// Program: house.cpp // Author: ... #include #include #include ///////////////////////////////////////////////////////////////////////////// // CLASS DEFINITIONS ///////////////////////////////////////////////////////////////////////////// class Shape { public: Shape(bool p) : paintable(p) {} virtual ~Shape() {} // needed just for technical reasons // PRE:- // POST: Returns true if area is paintable. bool can_paint() const { return paintable; } // PRE: - // POST: Returns the area of the shape. virtual double get_area() const = 0; private: bool paintable; }; // TODO: IMPLEMENT TRIANGLE CLASS // TODO: IMPLEMENT RECTANGLE CLASS // TODO: IMPLEMENT CIRCLE CLASS ///////////////////////////////////////////////////////////////////////////// // TEST MAIN FUNCTION (MODIFY WHERE STATED) ///////////////////////////////////////////////////////////////////////////// // int main() { std::vector shapes; // parse test data in the following format until end marker is found: // // where is optional while(std::cin.good()) { std::string shape; std::cin >> shape; if (shape == "end") break; // parse + / - char sign; std::cin >> sign; bool is_paintable = sign == '+'; if (shape == "triangle") { double width; std::cin >> width; double height; std::cin >> height; // TODO: IMPLEMENT, ADD PARAMETERS AND UNCOMMENT //shapes.push_back(new Triangle(...)); } else if (shape == "rectangle") { double width; std::cin >> width; double height; std::cin >> height; // TODO: IMPLEMENT, ADD PARAMETERS AND UNCOMMENT //shapes.push_back(new Rectangle(...)); } else if (shape == "circle") { double radius; std::cin >> radius; // TODO: IMPLEMENT, ADD PARAMETERS AND UNCOMMENT //shapes.push_back(new Circle(...)); } else { std::cout << "unknown shape: " << shape << "\n"; break; } } // calculate area to be painted double area = 0; for(std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { const Shape* shape = *it; if (shape->can_paint()) { area += shape->get_area(); } else { area -= shape->get_area(); } } std::cout << "--- paintable area:\n" << area << "\n"; // clean up allocated shape objects for(std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) delete *it; return 0; }