Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Venix Cador
- //String ADT
- //CS23001
- #ifndef STRING_HEADER
- #define STRING_HEADER
- #include <iostream>
- #include <cstdlib>
- #define MaxString 100
- class String {
- public:
- String(int cap = MaxString);
- String(const char, int cap = MaxString);
- String (const char[], int cap = MaxString);
- ~String();
- //copy constructor
- //Ex: str1 = str2;
- String(const String&, int cap = MaxString);
- int getlength()const {return length;};
- int getsize()const {return size;};
- /*
- *returns the character from a given index
- * Ex: char d = str[1];
- */
- char operator [] (int) const;
- char& operator [] (int);
- /*
- *Finds the first occurence of a char in a string with zero offset
- *Ex: str.findchar('d');
- */
- int findchar(char)const;
- int findstr(const String&)const;
- String substr(int, int right = 0) const;
- /*
- *compares a string to a character array
- *Ex:str =='abc';
- *Ex:str != 'abc';
- */
- bool operator==(const String&)const;
- bool operator !=(const String& rhs) const { return !(*this == rhs);};
- bool operator==(const char rhs[]) const { return *this == String(rhs); };
- bool operator!=(const char rhs[]) const { return !(*this == String(rhs)); };
- /*
- *compares if two Strings are less or grater than the others
- *Ex: str1 > str2;
- *Ex: str1 >= str2;
- *Ex: str1 < str2;
- *Ex: str1 <= str2;
- */
- bool operator <(const String&)const;
- bool operator >(const String& rhs )const {return rhs < *this; } ;
- bool operator >=(const String& rhs) const {return (*this < rhs ) || (*this == rhs);};
- bool operator <=(const String& rhs) const {return (*this > rhs) ||(*this == rhs);};
- bool isclosed() const {return s[length] == '\0';};
- void reallocate(const int);
- void swap(String&);
- /*
- * add two strings together
- *Ex: String result = left + right;
- *Ex: String str1 += str2;
- *Ex: String result = left + " ! !";
- *Ex: String result = left + ' ! '
- */
- String operator + (const String&) const;
- String operator + (const char rhs[]) const {return *this + String(rhs);};
- String operator + (const char rhs) const {return *this + String(rhs);};
- String& operator += (const String& rhs) {return *this = *this + rhs;};
- String& operator += (const char rhs[]) {return *this = *this + String (rhs);};
- String& operator += (const char rhs){return *this = *this + String (rhs);}
- String& operator = (String);
- //the function for the nextblank
- int nextBlank(int d = 0) const;
- //function prototype for find the nesxnonblank
- int nextNonBlank(int x = 0) const;
- String justify(const in) const;
- String justifyFile(std::ifstream in, std::ofstream& out, left, right);
- int getLength() const { return length; };
- private:
- char *s;
- int size;
- int length;
- };
- std::istream& operator >>(std::istream&, String&);
- std::ostream& operator <<(std::ostream&, const String&);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment