Question
I have posted the whole version of it previosly and have good progress by the help of ur experts. I still have some some issues
I have posted the whole version of it previosly and have good progress by the help of ur experts. I still have some some issues on some of the functions. Below is some part of the whole assignment and my update where I am up to
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( istream& istr) : bool | 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 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& ostr) : void | write the string out to the ostream argument, but do not add any end of line (could be cout or an ofstream variable) |
compareTo( const MYString& argStr) : int | compares the object string (Ostr) to the argument string (Astr) by subtracting each element of Astr from Ostr until a difference is found or until all elements have been compared Ostr < argStr returns a negative number Ostr > argStr returns a positive number Ostr ==argStr returns zero |
c_str( ) : const char * | return a pointer to a constant cstring version of the MYString object |
setEqualTo(const MYString& argStr): void | this does the assignment operation aStr.setEqualTo( bStr ) would change aStr so that it would contain the same information as bStr |
Main Program Requirements:
create a vector of MYStrings that is size 100
read each of the words from the file called "infile2.txt" (the file is out in Files section under Program Resources). You can call the read function directly on the indexed vector
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) using Bubble Sort
output the sorted words to outfile.txt file
6 words per line ( use setw(13) to space them out....the setw command should notbe in the write member function)
Below are part of my .cpp files and the functions work fine:
int NDString2::length()
{
return strlen(str);
}
//return capacity
int NDString2::capacity()
{
return cap;
}
//return character at index
char NDString2::at(int index)
{
return *(str)+index;
}
I have also a working compareTo function
I NEED HELP ON THE FOLLOWING:
I couldn't make the read & write function ( I have a saved file2.txt file in the project directory ) . And also help is very appreciated on test codes in the main per the Main Program Requirements:
Thanks you in advance
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started