Can anyone please help me with this code? The question isn't that clear

The following code declares a skeleton for a String class. An object of that class, would store, as a data member, the characters, including the NULL one, of a C++ character string (c-string) as well as the length of that string. An empty string object must be represented as follows:




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;

}
To give you an idea.

2. Implement the default constructor.
Look at: http://www.cplusplus.com/doc/tutorial/classes2/


3. Implement the copy constructor of the class.
Look at http://www.cplusplus.com/doc/tutorial/classes2/

4. Overload the assignment operator “=” as a member function of the String class.
Look at https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

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.
Look at https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

6. Overload the insertion operator “<<” as a friend function for the String class.
Look at https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

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.
Look at https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

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.
Look at https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm
Topic archived. No new replies allowed.