/////////////////////////////////////////////////////////////////////////////// // // Module: cs321lab2.cpp // // Abstract: This is an skeleton test program for cs321 lab2. // Its purpose is to test the image class along with all derived shape classes. // The menu-driven interface gives you a way to control the tests you run. // // Author: // // Revisions: Original. You need to add additional tests and revision notes // as your classes undergo further development in future labs. // // Notes: // /////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include "image.h" using namespace std; int main() { // a collection of images to test with this program vector images; // you could use a list too, but a vector is probably better in this case // various menu selections... const int menuCreateImage = 1; const int menuListImages = 2; const int menuAddShape = 3; const int menuDrawImage = 4; const int menuEraseImage = 5; const int menuCopyImage = 6; const int menuCloneImage = 7; const int menuReadFile = 8; const int menuWriteFile = 9; const int menuExit = 10; // quit this test program bool repeatMenu = true; // this flag is set false when the user selects the "quit" option const int menuMinValue = 1; // minimum menu entry value const int menuMaxValue = 10; // maximum menu entry value while( repeatMenu ) // keep looping until the user presses 0 to quit { system("clear"); // clear the terminal screen // post the menu to the user cout << "_________________________Menu_________________________" << endl << "\t1. Create an new empty image." << endl << "\t2. List images in the image collection" << endl << "\t3. Create and add a shape to an image" << endl << "\t4. Draw shapes in an image" << endl << "\t5. Erase an image from the collection" << endl << "\t6. Copy one existing image to another existing image" << endl << "\t7. Make a new copy of an existing image" << endl << "\t8. Read an image from file" << endl << "\t9. Write an image to file" << endl << "\t10. Exit" << endl << "Enter a choice: "; int menuSelectionValue = 0; // user's menu choice as a numeric value bool isEntryValid = false; // indicates whether the user's menu choice was valid while( isEntryValid == false ) // keep prompting until a valid selecting is made { string menuSelectionString; //user's choice entered as a string getline (cin, menuSelectionString); // get the user's entry (could be any arbitrary text string at this point) istringstream userInputStream(menuSelectionString); // istringstream used for subsequent parsing of the input string userInputStream >> menuSelectionValue; // try to convert the string selection to a numeric value // Perform a sanity check on the user's input char extraneousInputChar; // used below to see if the user input too many characters for the menu selection if (!userInputStream // invalid stream || userInputStream >> extraneousInputChar // other junk in the input string || menuSelectionValue < menuMinValue // invalid numerical value || menuSelectionValue > menuMaxValue) // invalid numerical value cout << endl << "Invalid Input! Enter again: " << endl; else isEntryValid = true; // good input } // decide what the user selected and perform the associated command switch( menuSelectionValue ) { case menuCreateImage: // creates an image and adds it to the images collection; tests image default constructor cout << endl << "CreateImage test..." << endl; // your code here...ie call a createImage function that you must write break; case menuListImages: // iterates through the vector collection cout << endl << "ListImage test..." << endl; // your code here... break; case menuAddShape: // tests the image::Add() method cout << endl << "AddShape test..." << endl; // your code here... break; case menuDrawImage: // tests the image::ReDraw method; must iterate through the shape collection and invoke the correct virtual method cout << endl << "DrawImage test..." << endl; // your code here... break; case menuEraseImage: // tests the image::Erase and image destructor; must correctly delete all shapes too cout << endl << "EraseImage test..." << endl; // your code here... break; case menuCopyImage: // tests the image::operator=() method for correct deep copy cout << endl << "CopyImage test..." << endl; // your code here... break; case menuCloneImage: // tests the image copy constructor for correct deep copy cout << endl << "CloneImage test..." << endl; // your code here... break; case menuWriteFile: // writes an to a file; tests image::Write() cout << endl << "WriteFile test..." << endl; // your code here...ie call a writeFile function that you must write break; case menuReadFile: // load an image from a file and add to collection; tests image::Read() cout << endl << "ReadFile test..." << endl; // your code here...ie call a readFile() function that you must write break; case menuExit: // quit this test program repeatMenu = false; cout << endl << "Exiting..." << endl; break; default: cout << endl << "Invalid entry; try again" << endl; break; } cout << endl << "Press Enter to continue..." << endl; getchar(); } return EXIT_SUCCESS; }