Ask C/C++ Expert


Home >> C/C++

Write a program to manipulate strings using pointers. The program will start out by displaying a menu to ask user what to do as shown below:

Simple String Manipulation Program

Load string

Show string

Character count

Trim string

Convert to upper case

Quit

Based on user selection the original string will be manipulated (modified if applicable) and the program will show the resulted string after manipulation (or character count in case option 3 is chosen). This menu will then be re-displayed for another user selection until user selects option 6 to quit.

Note: when display a string you must use this format: [string content] so that if there is any leading white-space characters in the string we can recognize them. Example: if input string is

" Welcome to C++ programming world!!!"

then output per different options will be:

Option 2: [ Welcome to C++ programming world!!!]

Option 3: Total character count: 40

Option 4: [Welcome to C++ programming world!!!]

Option 5: [ WELCOME TO C++ PROGRAMMING WORLD!!!]

Class Design

You need at least two classes.

class SmartString

Private:

Data members: a pointer to a char , namely str

Public:

Constructors:

Default constructor: initialize the pointer str to NULL

Non-default constructor: take a pointer to a character as its only parameter and dynamically allocate memory for str and copy the character array to str. Do not use strlen or strcpy. Use a loop to get the length and to copy instead.

Destructor: if str is not NULL delete the string str

Member functions:

LoadString: ask user to enter a string (may include white space characters). Store it in a character array of maximum 1024 characters (use cin.getline). Dynamically allocate memory for str based on input string's length then copy input string to str.

Note: 1> Must use a loop to get the string's length and copying. strlen and strcpy are not allowed

2> You must check if str is not NULL. If true you must de-allocate it. Otherwise it will be a memory leak.

3> If you select Load string option then select Load string option again the program won't wait for you to enter an input string. of the class.

ShowString: display the string in format []

Size: return the number of characters in str. If str is NULL return 0.

Trim: remove all leading white-space characters in the original string str

ToUpper: Converting all letters in the str string to upper case letters

GetString: return str. This is dangerous and should not be done. It simply illustrates how to return a pointer from a function.

Important note: since SmartString class contains a pointer member we should provide a copy

constructor and overload the assignment operator. However you're not required to do it now.

We will discuss about this later on when learning how to overload C++ operators.

class SmartStringApp

Private

Data member: a pointer to a SmartString object, namely ss

Public

Constructors:

Default constructor: initialize ss to NULL

Non-default constructor: take a pointer to character as its only parameter. The constructor will dynamically create the SmartString object ss using SmartString class's non-default constructor.

Destructor: if ss is not NULL then de-allocate ss.

Pointer knowledge: what memory/object may be deallocated when ss is deleted?

Member functions:

Init: invoke function LoadString from SmartString object ss to load a string from user input

Start: display the menu shown above and execute SmartString's member functions based on user input

Implementation Requirements

Must use pointers notation and while loop when processing the string. No array notation is allowed except for array declarations if needed. No index is needed when processing an array of characters. Must increment pointer and check for '\0' as the end of the array. If you're not sure of this requirement show me your code before submitting your lab to avoid point deduction.

No string C/C++ library is allowed (except for isspace and toupper)

Must use the this pointer in at least 4 different places

Must use member initialization syntax in constructors

Main program will simply:

declare a pointer to SmartStringApp and dynamically create a SmartStringApp's default object

Invoke Init to get initial string

Invoke Start function for the newly created SmartStringApp object

free memory for the SmartStringApp object

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91332811
  • Price:- $45

Guranteed 36 Hours Delivery, In Price:- $45

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As