Question: Classes, Objects, Pointers and Dynamic Memory Program Description: This assignment you will need to create your own string class. For the name of the class.

 Classes, Objects, Pointers and Dynamic Memory Program Description: This assignment youwill need to create your own string class. For the name ofthe class. use your initials from your name. For example: my stringclass would be called EEString. Since each of you will be using

Classes, Objects, Pointers and Dynamic Memory Program Description: This assignment you will need to create your own string class. For the name of the class. use your initials from your name. For example: my string class would be called EEString. Since each of you will be using a unique class name. I will use the name Mv5ting as the generic name of the class (but make sure for you program. that you use the correct name based on your na mel. The MYString objects will hold a cstring and allow it to be used and changed. We will he changing this class over the next couple programs. to be adding more features to it (and correcting some problems that the program has in this simple version). Below will be the details of the class. Since this is your first class that you will be writing. I would recommend that you write and test this class a few member functions at a time. For example you may want to start hy writing the two constructors and the iit function and then test them with some simple code in main like th mstring teststr("heno-); (nut ' (start With 20 chars and then double it whenever this is not enough) intend index of the end of the string [the '\\0' char) The class will store the string in dynamic memory that is pointed to with the pointer. When you first create an MVString object you should allocate 20 spaces of memory [using the new command). The string will be stored as a cstring in this memory. (NOTE: Here on Canvas in Files\\Review Lectures from 131\\ For this program, your MYString variables will never need to grow beyond length 20, in program 3 you will need to be allow your string that is held in the class to be able to be larger than 20 chars. So you may want to start allowing your strings to be able to grow.if you have extra time. If you are optionally building in the ability to grow, it should start with a capacity of 20, but when needed it would grow in increments of 20. The capacity should always be a multiple of 20. For example if we were storing the string "cat" in a MYString object, our data member would have the following values: str starting addr of dynamic array cap 20 lend 3 Dynamic array: a t ? ? 2 2 ? ? ? ? 2 ? The MYString class will need to have the following member functions: Programming Note: Write and test one or two functions at a time Member Functions : return type Description MYString() Default Constructor: creates an empty string MYString (const char*) creates a string that contains the information from the argument example: MYString greeting( "hello there wise one"); length( ) : int the length of the string ( "cat" would return 3) capacity( ) : int the total amount of memory available for use (always 20 in this version, but in the next version, this will change) at( int index) : char returns the character at a certain location ( at( 0 ) for a "cat" would return 'c' ). If the index is not inside the string (negative or too large) then return '\\0' read one string from the istream argument (could be from cin or an ifstream variable). This should work just like the > > operator. When reading in, you can assume that you will not read in a string read( istream& istrm) : bool longer than 99 characters. This function will return true if it was able to read (remember > > operator will return true if it is able to read from a file). For simplicity sake, you could create a local char array variable 100 that you first read into and then you could copy from this char array into your dynamic memory.write( ostream& ostrm) : void write the string out to the ostream argument, but do not add any end of line (could be cout or an ofstream variable) 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 compareTo( const MYString& argStr) : int objStr argStr returns a positive number objStr == argStr returns zero c_str( ) : const char * return a pointer to a constant cstring version of the MYString object. This can be nice for simple outputs: cout . (do not use vector's push_back function. See programming note below*). Example: while ( words[count].read(fin) ) {...} . as you are reading the words in, keep a count of how many words were read in. . After you have read in all the words from the file, resize your vector to the correct size based on your count of the number of words read in. . sort the MYStrings from smallest to largest (this will be based on the ASCII encoding..meaning capital letters will sort before lower case letters) using Bubble Sort . output the sorted words to outfile.txt file . 6 words per line ( use setw(13), which is part of library, to space them out...the setw command should not be in the write member function). Below is an example of what you output should look like ..but is missing the middle section. Martian Such They Were amazingly an an and animal. . . . .. .middle of the output.. . . . . . . . to using , was what within would *Programming Note: Do not use the push_back() member function of vector, because this won't work for this program (it calls the copy constructor of our MYString class, which we haven't written). Turn in: For turn in, you will have three files: your main program, the .h file and the .cpp file. For all programs which include class definitions, I want you to place them in that order (main, interface/header (.h), and implementation (.cpp) ) NOTE: In addition to the program header documentation (above main), you should also have class documentation (and author info: name, Sect #, and explanation of the class ) at the top of the .h file.NOTE: In addition to the program header documentation (above main), you should also have class documentation (and author info: name, Sect #, and explanation of the class ) at the top of the .h file. Ways to lose points: if your main file does not contain the program header with a program description and short function description to accompany the function prototypes. your interface (.h) file should have a class description about what the class does your code should also be consistently indented as talked about in class, and shown in the book you can not use global variables unless it is a const you should use good variable names (descriptive, and start with lower case letter ) proper placement of { and } ( a ] should not be placed at the end of a line) you need staple to keep your papers together (folding a corner or using a paper clip are not good enough) you need to have the three source files (mystring.h, mystring.cpp, and the main) as well as a print out of the output file if you did not split the MYString class into separate files

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!