//-------------------------------------------------------------------- // // Laboratory A stradt.h // // Class declaration for the array implementation of the String ADT // //-------------------------------------------------------------------- #include #include using namespace std; class String { public: // Constructors String ( int numChars = 0 ) throw ( bad_alloc ); // Create an empty string String ( const char *charSeq ) throw ( bad_alloc ); // Initialize using char* // Destructor ~String (); // String operations int getLength () const; // # characters char operator [] ( int n ) const; // Subscript void operator = ( const String &rightString ) throw ( bad_alloc); // Assignment void clear (); // Clear string // Output the string structure -- used in testing/debugging void showStructure () const; // In-lab operation String ( const String &valueString ) throw ( bad_alloc ); // Copy constructor private: // Data members int bufferSize; // Size of the string buffer char *buffer; // String buffer containing a null-terminated // sequence of characters // Friends // String input/output operations (In-lab Exercise 1) friend istream & operator >> ( istream &input, String &inputString ); friend ostream & operator << ( ostream &output, const String &outputString ); // Relational operations (In-lab Exercise 3) friend bool operator == ( const String &leftString, const String &rightString ); friend bool operator < ( const String &leftString, const String &rightString ); friend bool operator > ( const String &leftString, const String &rightString ); };