Write a program to manipulate strings using pointers

Assignment Help C/C++ Programming
Reference no: EM13763039

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

Reference no: EM13763039

Questions Cloud

Various consequences of tax : What would be the various consequences of this tax on both consumption as well as production?
Primary psycho graphic population segments : 1. Identify and describe the three (3) primary psychographic population segments. 2. Discuss at least six (6) of the main social/cultural trends that have impacted online exchange. 3. For each psychographic population segment, select two (2) social/c..
Explain a relevant theory of human freedom and consciousness : explain a relevant theory of human freedom, consciousness, and/or reality; analyze how the chosen theory might approach the decision, including the relevant considerations and the ultimate conclusion reached.
Organizational of infrastructure and security : The last section of the project plan will present the infrastructure in accordance with the parameters set forth at the outset of the project. The network solution that is chosen should support the conceived information system and allow for scalab..
Write a program to manipulate strings using pointers : 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
Determine cash generated from operations : Which financial statement is used to determine cash generated from operations?
Identify the analogues of given passages : Identify the analogues, the basis of the comparison, and the feature of given passages. Also identify any inductive fallacies of your textbook.
Question differ in different cultures or contexts : Does the manager's failure to acknowledge the contributions of his staff constitute an ethical violation? Why or why not? Would the answer to this question differ in different cultures or contexts?
The existence of deltas on the human population : What Potential impact does the existence of deltas have on the human population in the U.S.?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  The use of decision logic

The use of decision logic is one of the major concepts of computer programming.

  Write a program to find the max value

Write a program to find the max value in an unsigned char array[100].

  Prepare a program to add the specific numbers

Write a program that will read in 5 numbers and add 10 to the first number, 20 to the second number, and 30 to the third number, 40 to the fourth and 50 to the 50th.

  Create your own while-end repetition structure

Create your own While-End repetition structure. You decide the theme. You should provide both the pseudocode and the flowchart of your example. Be sure to provide an overview of what your repetition structure is doing. Provide a walk-through of yo..

  Classes and objects are the basic concepts of

question 1. list three debugging techniques within the debugger that can be used to locate logical error in the java

  An evaluation of blogger

*An evaluation of Blogger*Identify and discuss the online blogs you examined and their usefulness Discuss the place blogging holds in today's availability of information,*and its advantages/disadvantages over more traditional formats such as newspape..

  Ansi-c program complete assignment as per written in the

complete assignment as per written in the attached

  Give a recursive definition of s.

Let S be the set of positive integers that can be written as a sum of one or more 4's and/or 7's. For example, 7 ? S and 18 ? S (because 18 = 4 + 7 + 7)

  To reverse the order of elements on a stack

Write a program in C++ to  reverse the order of elements on a stack S using two additional stacks using one additional stack

  Write a program that asks the user for non-negative integer

The factorial of n (written n!) is the product of the integers between 1 and n. Thus 4! = 1*2*3*4 = 24. By definition, 0! = 1.

  Write a program to find the average value

Write a program to find the average value, the largest value, and the smallest value of a set of numbers supplied as input from the keyboard. The number of values in the data set must be in the range 0 to 20, inclusive.

  Design a phonecall class that holds a phone number

Design a PhoneCall class that holds a phone number to which a call is placed, the length of the call in minutes, and the rate charged per minute. Overload extraction and insertion operators for the class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd