#include #include #include "playpen.h" #include "colournames.h" #include int main() { try { fgw::playpen paper; fgw::hue mycolor; int x(0); int y(0); int height(0); int width(0); int draw(0); std::string acolor; bool reject = false; std::cout << "Input a value for height "; std::cin >> height; if (not std::cin) throw std::exception(); std::cout << "Input a value for width "; std::cin >> width; if (not std::cin) throw std::exception(); std::cout << "Please choose a color (blue, green or red) :\n"; std::cin >> acolor; for (int index(0); index < acolor.length() && not reject; index++) { if (isalpha(acolor[index])) continue; else reject = true; } if (reject) { std::cout << "You must enter a non-numeric word!\n"; throw std::exception(); } int anum(0); if (acolor == "blue") anum = 1; if (acolor == "green") anum = 2; if (acolor == "red") anum = 3; switch (anum) { case 1: mycolor = fgw::blue7; break; case 2: mycolor = fgw::green7; break; case 3: mycolor = fgw::red7; break; default: mycolor = fgw::black; std::cout << "No valid color selected, using default black\n"; } x = width / 2; draw = x; while (draw != 0) { paper.scale(5); paper.plot(-draw, 0, mycolor); paper.display(); --draw; } paper.scale(5); paper.plot(0,0,mycolor); paper.display(); draw = x; while (draw != 0) { paper.scale(5); paper.plot(draw, 0, mycolor); paper.display(); --draw; } y = height / 2; draw = y; while (draw != 0) { paper.scale(5); paper.plot(0, -draw, mycolor); paper.display(); --draw; } draw = y; while (draw != 0) { paper.scale(5); paper.plot(0, draw, mycolor); paper.display(); --draw; } std::cin.ignore(); std::cin.get(); } catch (...) { std::cerr << "***An Exception was thrown***\n"; } }