This week you'll be making the following refinements to the class that you wrote in the last assignment. All the requirements from that class are still in force. For example, all MyStrings must always be stored in a dynamic array that is exactly the correct size to store the string. Your score on this assignment will take into consideration your work on both the previous assignment and this assignment.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This week you'll be making the following refinements to the class that you wrote in the last assignment. All the requirements from that class are still in force. For example, all MyStrings must always be stored in a dynamic array that is exactly the correct size to store the string. Your score on this assignment will take into consideration your work on both the previous assignment and this assignment.

1. Extraction Operator

Just like the >> operator that reads C-strings, your >> operator should skip any leading spaces and then read characters into the string up to the first whitespace character.

For reasons of convenience, we will impose a limit of 127 on the number of characters this function will read. This is so you can temporarily read into a non-dynamic array and then copy what you need into your data member, which will be a dynamic array. Note that this does not mean that all MyStrings will always have a maximum of 127 characters. For example, you might get a MyString with more than 127 characters by using the MyString constructor or by concatenating two MyStrings.

You should create a constant for the maximum input size. Declare it in the public area of the class. It should be static.

Hint: Don't try to read character by character in a loop. Use the extraction operator to read the input into a non-dynamic array, then use strcpy() to copy it into your data member. Make sure to allocate the correct amount of memory.

Hint: if you use the extraction operator as suggested above, you will not have to skip leading whitespace, because the extraction operator does that for you.

2. A read() function

The read() function will allow the client programmer to specify the delimiting character (the character at which reading will stop). It should work just like the getline() function works for c-strings; that is, it should place everything up to but not including the delimiting character into the calling object, and it should also consume (and discard) the delimiting character. This will be a void function that will take two arguments, a stream and the delimiting character. It should not skip leading spaces. The limit of 127 characters imposed on the >> function above also applies to this function.

Hint: Don't try to read character by character in a loop. Use the in.getline() function to read the input into a non-dynamic array, then use strcpy() to copy it into your data member.

3. Concatenation Operator

Overload the + operator to do MyString concatenation. The operator must be able to handle either MyString objects or C-strings on either side of the operator. Be careful with the memory management here. You'll have to allocate enough memory to hold the new MyString. I suggest using strcpy() to get the left operand into the result MyString, and then strcat() to append the right operand. Both strcpy() and strcat() should be used as if they are void, even though they do have return values.

4. Combined Concatenation/Assignment Operator

Overload the shorthand += to combine concatenation and assignment. Only MyStrings can be on the left-hand side of a += operation, but either MyStrings or C-strings may appear on the right side. If you pay close attention to the += operator from the feetInches class, these may be the easiest points of the semester.

tinclude "mystring.h"
tinclude <fstream>
tinclude <cctype>
tinclude <string>
tinclude <cassert>
#include <iostream>
using namespace std;
using namespace cs mystring;
// for toupper ()
void BasicTest ();
void RelationTest ();
void ConcatTest ();
void CopyTest ();
MyString AppendTest (const MyStrings ref, MyString val);
string boolString (bool convertMe);
int main ()
BasicTest ();
RelationTest ();
ConcatTest 0;
CopyTest ();
string boolstring (bool convertMe){
if (convertMe) {
return "true":
} else {
return "false";
void BasicTest ()
MyString s;
int stringlLength;
cout <« "----- Testing basic String creation & printing" << endl;
const MyString strs[] =
(MyString ("Wow"), MyString ("C++ is neat!"),
MyString (""), MyString ("a-z")};
for (int i = 0; i < 4; i++) {
cout « "string [" <« i «"] = " « strs[i] « endl;
cout « endl « "----- Now reading MyStrings from file" <« endl;
cout << endl <« "----- first, word by word" << endl;
ifstream in ("mystring.txt");
assert (in) ;
Transcribed Image Text:tinclude "mystring.h" tinclude <fstream> tinclude <cctype> tinclude <string> tinclude <cassert> #include <iostream> using namespace std; using namespace cs mystring; // for toupper () void BasicTest (); void RelationTest (); void ConcatTest (); void CopyTest (); MyString AppendTest (const MyStrings ref, MyString val); string boolString (bool convertMe); int main () BasicTest (); RelationTest (); ConcatTest 0; CopyTest (); string boolstring (bool convertMe){ if (convertMe) { return "true": } else { return "false"; void BasicTest () MyString s; int stringlLength; cout <« "----- Testing basic String creation & printing" << endl; const MyString strs[] = (MyString ("Wow"), MyString ("C++ is neat!"), MyString (""), MyString ("a-z")}; for (int i = 0; i < 4; i++) { cout « "string [" <« i «"] = " « strs[i] « endl; cout « endl « "----- Now reading MyStrings from file" <« endl; cout << endl <« "----- first, word by word" << endl; ifstream in ("mystring.txt"); assert (in) ;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 10 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY