Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program. Program Note: For this assignment the normal C++ string and cstring functions cant be used (except >> and < < with cstrings). You

C++ Program.

Program Note: For this assignment the normal C++ string and cstring functions cant be used (except >> and << with cstrings). You may not #include them. You must write all the functions that will be used.

Gang of Four and other friends

Program Description: This assignment is continuing to make your MYString class so that it is more complete and usable. The data within your MYString class will be the same as before, but now we are adding the Gang of Four functions and some operators. I have highlighted the new/modified functions in red below.

Your Gang of four and overloaded operator functions should have normal behavior. As you write each function, you should make a little test to verify that the function is working correctly.

The MYString class will need to have the following member functions:

Programming Note: Write and test one or two functions at a time. Remember to mark member functions that do not change member data with const, I will be looking for this in the grading

Member Functions : return type

Description

MYString( )

Default Constructor: creates an empty string

MYString(const MYString & mstr)

Copy Constructor: creates a string that is a duplicate of the argument

MYString (const char*)

creates a string that contains the information from the argument example: MYString greeting( "hello there wise one");

~MYString()

Destructor: release the dynamic memory

= operator : lvalue&

Replaces

setEqualTo(const MYString& argStr): void

Assignment Operator: this does the assignment operation objStr.setEqualTo( argStr ) would change objStr so that it would contain the same information as argStr

Non-const

[ ] operator : char

Like:

at( int index) : char

returns the character at a certain location. No Error checking. Fast but dangerous

>> operator: istream&

Replaces

read( istream& istrm) : istr

read a string from the istream argument (could be from cin or an ifstream variable) {when reading in, you can assume that you will not read in a string longer than 99 characters} This function will now return the istream which is the normal behavior.

<< operator : ostream&

Replaces write( ostream& ostrm) : ostr

write the string out to the ostream argument, but do not add any end of line (could be cout or an ofstream variable) This function will now return the ostream which is the normal behavior.

< operator > operator

== operator : all return a bool

Replaces/Uses compareTo( const MYString& argStr) : int

You could either replace the compareTo function with the 3 comparison operators or you could make the compareTo function private and then have the operators call compareTo. If you have the operators use compareTo, then you should make compareTo private.

Compares the object string (objStr) to the argument string (argStr) by subtracting each element of argStr from objStr until a difference is found or until all elements have been compared objStr < argStr returns a negative number objStr > argStr returns a positive number objStr == argStr returns zero

+ operator : MYString

this function creates and returns a new MYString variable that is the combination of both the rvalue and the lvalue. For example if you had the following values inside two of your strings and added them bat + man, then you would return a MYString that contains batman

length( ) : int

the length of the string ( "cat" would return 3)

capacity() : int

The amount of spaces that is currently reserved for possible use before growing

c_str( ) : const char *

return a pointer to a constant cstring version of the MYString object

Static things
These are the static variables and functions that you will need to implement in your program.
Static Variables What information it holds Static Funtion for access
currentCount this is the count of how many MYString instances are currently "alive" int getCurrentCount( )
createdCount this is the count of how many MYString instance have been created in the program ( don't decrease in destructor) int getCreatedCount( )

Main Program Requirements:

Read the words from the input file into MYString variables (Note: The input file is out in Files/Program Resource/P3 MYString v2 and is called infile3.txt). As the words are being read in append them with the + operator to each other until you have combined 5 words together into one jumbo MYString. Then take this jumbo MYString and add it into the vector with pushback (so it will be using your copy constructor). The input file probably wont have an even multiple of 5, so you will need to allow the loop to end due to reaching end of file (not due to knowing the word count).

Once you have read, combined, and pushed your MYStrings into the vector, then once again sort the strings into ascending order based on their ASCII value. Then output them to the screen with one combination string per line. When outputting the strings also include the length and capacity of the string on the same line. Here is an example of one line of output:

Theyseemedamazinglybusy.I 25:40 // use setw to make it look good // don't worry about making the one crazy long word look nice

After outputting all the combo strings, then on a new line each output the count of the current objects, and the total count of the objects create throughout your program. These static outputs are required. You should strive for accuracy, but are more for our curiousity sake.

You much create your own sort routine (cant call a library, bubble sort is fine) and you cant use the swap function (I want you to be using your assignment operator).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions