Lab 3 - operator<< operator>>

2020_S19/wk3/lab3.cpp

The purpose of this lab is to practice operator overloading for the input (>>) and output (<<) operators with respect to a dynamic member variable within a 'SimpleString' class definition. In this lab, you will be given a SimpleString class which will contain three private member variables and a private resize member function. The class definition will also contain a default constructor, a destructor, and two overloaded operators, << and >>.

For this lab, you will write the definitions to the private 'resize' helper function, the default constructor, destructor, and overloaded input and output operators. Use the given descritions below.

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cctype>
using namespace std;

/*-------------------------------------------*/
#define DEFAULT 15
class SimpleString {
    private:
        char* str;
        int capacity;
        int length;
        void resize(const int);
    public:
        SimpleString();
        ~SimpleString();
        friend istream& operator>>(istream&, SimpleString&);
        friend ostream& operator<<(ostream&, const SimpleString&);
};
/*-------------------------------------------*/
int main () {
    SimpleString string; // invoke default constructor

    cout << "Enter a word: ";
    cin >> string;  // overloaded operator>>
    cout << "\nYou Entered: ";
    cout << string; // overloaded operator<<

    cout << "\nEnter another word: ";
    cin >> string;  // overloaded operator>>
    cout << "\nYou Entered: ";
    cout << string; // overloaded operator<<

    cout << endl;
    return(0);
}
/*-------------------------------------------*/