// An elementary implementation of type string. #include #include const int max_len = 255; class string { public: // universal access void assign(const char* st) { strcpy(s, st); len = strlen(st); } int length() { return len; } void print() { cout << s << "\nLength: " << len << "\n"; } private: // restricted access to member functions char s[max_len]; // implementation by character array int len; }; // Test of the class string. int main() { string one, two; char three[40] = {"My name is Charles Babbage."}; one.assign("My name is Alan Turing."); two.assign(three); cout << three; cout << "\nLength: " << strlen(three) << endl; // Print shorter of one and two. if (one.length() <= two.length()) one.print(); else two.print(); return 0; }