// LikeAString.cpp #include ///////////////////////////////////////////////////////////// // required part of solution starts here class LikeAString : public std::string { public: LikeAString(const std::string& s) : std::string(s) {} void setIndent(unsigned int ind) { _indent = ind; } std::string indent() { std::string prefix(_indent,' '); return prefix.append(*this); } std::string MajorTitle() { LikeAString boarder(std::string(size(),'=')); boarder += '\n'; std::string temp = boarder.indent(); temp += this->indent(); temp += std::string("\n") += boarder.indent(); return temp; } std::string MinorTitle() { LikeAString boarder(std::string(size(),'-')); boarder += '\n'; std::string temp = this->indent(); temp += std::string("\n") += boarder.indent(); return temp; } private: static unsigned int _indent; }; unsigned int LikeAString::_indent = 3; std::ostream& operator<<(std::ostream& out, LikeAString& las) { out << las.indent().c_str(); return out; } // required part of solution ends here ///////////////////////////////////////////////////////////// std::ostream& operator<<(std::ostream& out, std::string& s) { out << s.c_str(); return out; } typedef LikeAString LAS; int main() { LAS("").setIndent(5); std::cout << std::endl; std::cout << LAS("Major Title").MajorTitle() << std::endl; std::cout << LAS("Minor Title").MinorTitle() << std::endl; std::cout << LAS("some longer and boring string\n\n") << "\n"; }