//-------------------------------------------------------------------- // // Laboratory 2 test2.C // // Test program for the operations in the Point List ADT // //-------------------------------------------------------------------- #include #include "ptlist.h" void main() { PointList testList(8), // Test list assignList(4); // List assigned to Point testPoint; // List element char cmd; // Input command cout << endl << "Commands:" << endl; cout << " + x y : Append point (x,y) to the end of the list" << endl; cout << " @ : Display the point marked by the cursor" << endl; cout << " < : Go to the beginning of the list" << endl; cout << " > : Go to the end of the list" << endl; cout << " N : Go to the next point" << endl; cout << " P : Go to the prior point" << endl; cout << " C : Clear the list" << endl; cout << " E : Empty list?" << endl; cout << " F : Full list?" << endl; cout << " = : Assignment " << "(Inactive : In-lab Ex. 2)" << endl; cout << " ! : Double check assignment " << "(Inactive : In-lab Ex. 2)" << endl; cout << " # x y : Insert point (x,y) at beginning " << "(Inactive : In-lab Ex. 3)" << endl; cout << " Q : Quit the test program" << endl; cout << endl; do { testList.showStructure(); // Output list cout << endl << "Command: "; // Read command cin >> cmd; if ( cmd == '+' || cmd == '#' ) cin >> testPoint.x >> testPoint.y; switch ( cmd ) { case '+' : // append cout << "Append (" << testPoint.x << "," << testPoint.y << ")" << endl; testList.append(testPoint); break; case '@' : // getCursor testPoint = testList.getCursor(); cout << "Point marked by the cursor is (" << testPoint.x << "," << testPoint.y << ")" << endl; break; case '<' : // gotoBeginning if ( testList.gotoBeginning() ) cout << "Go to the beginning of the list" << endl; else cout << "Failed -- list is empty" << endl; break; case '>' : // gotoEnd if ( testList.gotoEnd() ) cout << "Go to the end of the list" << endl; else cout << "Failed -- list is empty" << endl; break; case 'N' : case 'n' : // gotoNext if ( testList.gotoNext() ) cout << "Go to the next element" << endl; else cout << "Failed -- either at the end of the list " << "or the list is empty" << endl; break; case 'P' : case 'p' : // gotoPrior if ( testList.gotoPrior() ) cout << "Go to the prior element" << endl; else cout << "Failed -- either at the beginning of the " << "list or the list is empty" << endl; break; case 'C' : case 'c' : // clear cout << "Clear the list" << endl; testList.clear(); break; case 'E' : case 'e' : // empty if ( testList.empty() ) cout << "List is empty" << endl; else cout << "List is NOT empty" << endl; break; case 'F' : case 'f' : // full if ( testList.full() ) cout << "List is full" << endl; else cout << "List is NOT full" << endl; break; //= case '=' : // In-lab Exercise 2 //= assignList = testList; //= cout << "assignList:" << endl; //= assignList.showStructure(); //= cout << endl; //= break; //! case '!' : // In-lab Exercise 2 //! testPoint.x = 0; // Double check //! testPoint.y = 0; //! assignList.append(testPoint); //! cout << "Point (0,0) appended to assignList" << endl; //! testPoint.x = 1; //! testPoint.y = 1; //! testList.append(testPoint); //! cout << "Point (1,1) appended to testList" << endl; //! cout << "List assigned to:" << endl; //! assignList.showStructure(); //! cout << endl; //! break; //# case '#' : // In-lab Exercise 3 //# cout << "Insert (" << testPoint.x //# << "," << testPoint.y << ") at beginning" << endl; //# testList.insertBeginning(testPoint); //# break; case 'Q' : case 'q' : // Quit test program break; default : // Invalid command cout << "Inactive or invalid command" << endl; } } while ( cmd != 'Q' && cmd != 'q' ); }