#include #include class Shape { public: virtual void draw() = 0; virtual ~Shape() = 0; protected: Shape(){} Shape(const Shape&){} Shape& operator=(const Shape&) { return *this; } }; Shape::~Shape(){} class Circle : public Shape { public: virtual void draw() { std::cout << " **** \n" << " * * \n" << " * * \n" << " * * \n" << " * * \n" << " * * \n" << " * * \n" << " * * \n" << " * * \n" << " **** \n" << std:: endl; } virtual ~Circle(){} }; class Triangle : public Shape { public: virtual void draw() { std::cout << " |\\ \n" << " |+\\ \n" << " |= \\ \n" << " |= =\\ \n" << " |== =\\ \n" << " |== ==\\ \n" << " |== ===\\ \n" << " |== =\\ \n" << " |= +++==\\ \n" << " |=+ +====\\ \n" << " |== + =\\ \n" << " |=+ ==\\ \n" << " L____________\\ \n" << std:: endl; } virtual ~Triangle(){} }; class Square: public Shape { public: virtual void draw() { std::cout << " ______________ \n" << " |/ | \n" << " |// ==== | \n" << " |/// ====| \n" << " |///// | \n" << " |//=== | \n" << " |////======== | \n" << " |/========// | \n" << " |//==/-- | \n" << " L______________J \n" << std:: endl; } virtual ~Square(){} }; int main() { int choice = 0; Shape* s; std::list shapes; do { std::cout << "Pick a shape by entering a number from 1 to 3: \n" << "(1) Square\n" << "(2) Triangle\n" << "(3) Circle\n" << "(4) Quit" << std::endl; switch ( choice ) { case 1: s = new Square; break; case 2: s = new Triangle; break; case 3: s = new Circle; break; default: s = 0; } // switch if (s) shapes.push_back(s); } while ( std::cin >> choice && choice != 4 ); std::list::const_iterator it; if ( ! shapes.empty() ) for ( it = shapes.begin(); it != shapes.end(); ++it ) { (*it)->draw(); delete (*it); } return 0; }