Assignment 8 - Your own String class with overloaded operators

due March 13th

The purpose of this assignment is to give you practice with constuctors, friend functions, static data members, static member functions and overloaded operators.


Program Overview

You are to write a String class with the necessary constructors and overloaded operator functions that makes use of the requisite main() function to produce the output below.

Requirements

  1. The program will be tested using the main() listed below.
  2. The String class must contain:
For this assignment you may NOT use the string class.

The Required main() function

int main()
{
    // Constructors
    String A("apple");
    String B("banana");
    String C("cantaloupe");
    String D(B);
    String E;

    // static member function
    cout << "Number of a's = " << String::a_count() << endl << endl;

    // Overloaded insertion operator
    cout << "A = " << A << endl;
    cout << "B = " << B << endl;
    cout << "C = " << C << endl;
    cout << "D = " << D << endl;
    cout << "E = " << E << endl << endl;

    // Relational operators
    cout << boolalpha;
    cout << "A < B " << (A < B) << endl;
    cout << "B < A " << (B < A) << endl;
    cout << "A == B " << (A == B) << endl << endl;

    // Assignment operator
    A = B;
    cout << "A = " << A << endl;
    cout << "A == B " << (A == B) << endl << endl;

    // Size (bang) operator
    cout << "A size = " << !A << endl;
    cout << "E size = " << !E << endl << endl;

    // Unary * operator
    cout << "C text = " << *C << endl << endl;

    // Plus operator
    cout << "A + B = " << A + B << endl << endl;

    // Plus equal operator
    A += C;
    cout << "A = " << A << endl << endl;

    // Index operator
    cout << "A[3] = " << A[3] << endl << endl;

    // static member function
    cout << "Number of a's = " << String::a_count() << endl;
}


Program Output

Your output should look like the following.


Number of a's = 9

A = apple
B = banana
C = cantaloupe
D = banana
E =

A < B true
B < A false
A == B false

A = banana
A == B true

A size = 6
E size = 0

C text = cantaloupe

A + B = bananabanana

A = bananacantaloupe

A[3] = a

Number of a's = 13



Program Hint

Write and test one function at a time.  Perform thorough testing, not just the the required main().