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

  Task your task is to write a simple program that converts

task your task is to write a simple program that converts between app and ppm values. the screenshots below

  Write in c++ another overloaded operator

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..

  Conversion of programming languages

How to convert java proram into C++ program.

  Write fibonacci function that calculates the nth number

The Fibonnacci numbers begin with the numbers 0 and 1 and have the property that each succeeding number is the sum of the two preceding numbers. For xample: 0,1,1,2,3,5,8,13,21,...etc. Write Fibonacci() function that calculates the n'th Fibonacci ..

  Program to compute diameter in centimeters of a steel rod

Write a program to compute the diameter in centimeters of a steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  Write a program which adjusted bill with a sales tax

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

  Print the matrix in a format and transpose of the matrix

Write a program which asks the user for 9 integers representing the elements of a 3 by 3 matrix by rows, stores the numbers in a 2-dimensional C++ vector, prints the matrix in a pretty format, prints the transpose of the matrix in a pretty format,..

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

  Write a driver program called testrationalnumber.cpp

Write a driver program called testRationalNumber.cpp to test each of the above functions and overloaded operators in the RationalNumber class.

  What is an abstract base class

What is a pure virtual function. Why would you define a pure virtual function. Give an example of a pure virtual function. What is an abstract base class. What does it do. Why would you make a class abstract

  Complete the 8 queens 2 dimensional array

Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better unde..

  Function that will merge the contents

Write a function that will merge the contents of two sorted(ascending order) arrays of type double values, storing the result in an array output parameter (still in ascending order).

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