#include #include "bstring.h" using namespace std; /* private: char* str; // pointer to the dynamic array of chars int size; // tracks size of string (i.e. how many chars) // allocation will always be size+1 (for '\0') */ BString operator+(const BString& s1, const BString& s2) { } bool operator== (const BString& s1, const BString& s2) { } bool operator!= (const BString& s1, const BString& s2) { } bool operator< (const BString& s1, const BString& s2) { } bool operator> (const BString& s1, const BString& s2) { } bool operator<= (const BString& s1, const BString& s2) { } bool operator>= (const BString& s1, const BString& s2) { } ostream& operator<< (ostream& os, const BString& bs) { os << bs.str; // OR you could write the for-loop return os; /* Alternate defn for (int i = 0; i < bs.size; i++) os << bs.str[i]; return os; */ } istream& operator>> (istream& is, BString& bs) { } BString::BString() // default constructor -- init to empty string { size = 0; str = new char[1]; // alternately, you could use null pointer str[0] = '\0'; } BString::BString(const char* c) { size = strlen(c); str = new char[size + 1]; // leave room for '\0' strcpy(str, c); // copy cstring into internal string } BString::BString(const BString& s) { size = s.size; str = new char[size+1]; // leave room for '\0' strcpy(str, s.str); // can use since we're STORING // internally as c-strings } BString& BString::operator= (const BString& s) { if (this != &s) { delete[] str; // delete what's already there size = s.size; str = new char[size+1]; // leave room for '\0' strcpy(str, s.str); // can use since we're STORING // internally as c-strings } return *this; } BString::~BString() { if (str != 0) delete[] str; } BString& BString::operator+= (const BString& bs) { } int BString::GetLength() const { return size; } void BString::Resize(int newsize) { }