#ifndef __FORMAT_HPP__ #define __FORMAT_HPP__ #include #include #include // parent class class format { protected: int width; public: format(int w) { width = w; } void output() { std::string line, word; std::ifstream inFile("quote.txt"); inFile >> word; line = word; while (inFile >> word) { if (line.length() + word.length() + 1 > width) { justify(line); line = ""; } if (line == "") line = word; else line = line + " " + word; } justify(line); inFile.close(); } virtual void justify(const std::string& str) = 0; }; class LeftJustify : public format { public: LeftJustify(int w) :format(w) {} protected: virtual void justify(const std::string& str) { std::cout << str << std::endl; } }; class RightJustify : public format { public: RightJustify(int w) :format(w) {} protected: virtual void justify(const std::string& str) { int num = width - str.length(); int i; for (i = 0; i < num; i++) std::cout << " "; std::cout << str << std::endl; } }; class CenterJustify : public format { public: CenterJustify(int w) :format(w) {} protected: virtual void justify(const std::string& str) { int num = (width - str.length())/2; int i; for (i = 0; i < num; i++) std::cout << " "; std::cout << str << std::endl; } }; #endif