Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming using function overloading, classes, and string concepts. class String { friend String operator+ (________________________); // concatenation operator friend bool operator= = (_______________________); //

C++ Programming using function overloading, classes, and string concepts.

class String { friend String operator+ (________________________); // concatenation operator friend bool operator= = (_______________________); // comparison operator friend ostream & operator<< (_______________________________); // insertion public: String (const char * = \0); // String default Constructor. It initializes the // string object to null or to the characters of a c-string String (_____________________________); // copy constructor ~String ( ); // Class destructor String & Operator= (_____________) // overloading the assignment operator String operator ( ) (int i , int n); // returns a string object which contains the // c-string that begins at i and of length n. private: int length; // number of characters in the string (without the NULL). char * pchars; // pointer to the array that stores the string // characters. The array of characters is terminated // by the NULL character. }; 1. Complete the declaration of the String class 2. Implement the default constructor 3. Implement the copy constructor of the class 4. Overload the assignment operator = as a member function of the String class 5. Overload the operator ( ) which takes, as shown below, an index i and a length n and returns a string object that stores c-string that starts at i and of length n. 6. Overload the insertion operator << as a friend function for the String class 7. Overload the string comparison operator = = as a friend function. That is, the comparison of two String objects should return the Boolean true, if the two objects are the same, false otherwise. 8. Overload the string concatenation operator + as a friend function. That is, the concatenation of two String objects should result in appending the right-hand-side string object to the left-hand-side String object and storing the result in a new string object that is returned by the operator function. 9. Implement an appropriate driver program that test the developed String class. Your program should test all of the implemented functions. In your testing, you may use the following string objects. S: the empty string S1 = {ABC} S3 = {DEFG}

As an example of testing, the following sample code can be used. Of course, more test cases are needed and should be used. void main ( ) { String S; cout << S; // prints out the following statement: This string is empty. String S1 (ABC); cout << S1; // prints out ABC String S2 (S1); cout << S2; // prints out ABC String S3 = DEFG; cout << (S1 + S3) << endl; }

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions