// // file: asgnmt3_s01.cpp // // driver to test simple graph algorithms // #include #include #include #include #include "graph.h" using namespace std; const int Quit = 4; void DisplayMenu (); int RecordChoice (); void main () { int size, choice, directed, connected, n, k; char label, direction; char filename [25]; // not ideal, but graph1 cannot be declared within a case statement // since Microsoft does not allow variable declarations or // constructor calls within a case statement do { cout << "\nPress d for directed graph, u for undirected: "; cin >> direction; } while (direction != 'd' && direction != 'D' && direction != 'u' && direction != 'U'); directed = (direction == 'd' || directed == 'D'); size = DetermineSize (); weightedGraph graph1 (size, directed); DisplayMenu (); choice = RecordChoice (); do { switch (choice) { case 1: cout << "This section computes the binomial coefficient " << "matrix\n\n"; cout << "Enter n and k: "; cin >> n >> k; break; case 2: cout << "This section builds a weighted graph and then calls " << " Floyd's shortest paths\nalgorithm\n\n"; cout << "Enter filename and extension: "; /* NOTE: the system expects the file to be in the project folder, so if the project folder for this is asgnmt3_s01, that's where the date file should be. An example, Floyd1.txt, is provided with the value for the graph example from class. */ cin >> filename; graph1.build (filename); /* NOTE: the system displays the fatal warning message box and debug error as the program exits. I haven't been able yet to identify the cause of this. I think it is a need for destructors to be called to de-allocate the dynamic memory used for the STL vector components of a graph. ...Working on it. Extra credit and much gratitude and admiration for anyone who can figure it out before I do! */ break; case Quit - 1: DisplayMenu (); break; } choice = RecordChoice (); } while (choice < Quit); } void DisplayMenu () { cout << " 1 -- compute binomial coefficient\n"; cout << " 2 -- Floyd's shortest paths algorithm\n"; cout << " " << Quit - 1 << " -- display menu\n"; cout << " " << Quit << " -- Quit\n"; } int RecordChoice () { int choice; char ch; cout << "Enter menu choice (" << Quit - 1 << " to quit, " << Quit << " to quit): "; do cin >> choice; while (choice < 1 || choice > Quit); // gobble up remaining newline character in input buffer cin.get (ch); return choice; }