1: // Filename: MENUDEMO.CPP 2: // Purpose: A test driver for the Menu class. 4: #include <iostream> 5: #include <iomanip> 6: using namespace std; 8: #include "MENU.H" 9: #include "PAUSE.H" 12: int main() 13: { 14: // Declare a first Menu object. The default constructor will 15: // be invoked to create a "blank" menu. 16: Menu m1; 18: // Show what a menu with no title and no options 19: // (i.e. a "default menu) looks like when it is displayed: 20: m1.Display(); 21: Pause(0); 23: // Add a title to the blank menu and then re-display the menu: 24: m1.AddTitle("New Menu"); 25: m1.Display(); 26: Pause(0); 28: // Notice what happens when we attempt to get a menu choice from 29: // a blank or "title-only" (which is what we have here) menu. 30: m1.Display(); 31: int menuChoice = m1.Choice(); 32: cout << "The menu choice obtained was " << menuChoice << "." << endl; 33: Pause(0); 37: // Declare a second menu object and initialize it with a title, then 38: // add a number of options, and display the menu after each step. 39: // Notice how the menu remains "centered". 40: Menu m2("Main Menu"); 41: m2.Display(); 42: Pause(0); 43: m2.AddOption("Quit"); 44: m2.Display(); 45: Pause(0); 46: m2.AddOption("Get information"); 47: m2.Display(); 48: Pause(0); 49: m2.AddOption("Do something"); 50: m2.Display(); 51: Pause(0); 52: m2.AddOption("Do something really, really long and involved"); 53: m2.Display(); 56: // Loop while the user does not choose the Quit option, i.e. 57: // while the user does not choose option 1 from the menu. 58: bool finished = false; 59: while (!finished) 60: { 61: m2.Display(); 62: menuChoice = m2.Choice(); 63: finished = (menuChoice == 1 || menuChoice == -1); 64: cout << endl 65: << "The menu choice returned was " << menuChoice << "." 66: << endl; 67: Pause(0); 68: } 72: // Create a third menu with nine options (the maximum number) 73: Menu m3("Test Menu"); 74: m3.AddOption("Option 1"); 75: m3.AddOption("Option 2"); 76: m3.AddOption("Option 3"); 77: m3.AddOption("Option 4"); 78: m3.AddOption("Option 5"); 79: m3.AddOption("Option 6"); 80: m3.AddOption("Option 7"); 81: m3.AddOption("Option 8"); 82: m3.AddOption("Option 9"); 83: m3.Display(); 84: Pause(0); 86: // Now note what happens when you attempt to add another option. 87: m3.AddOption("And yet another option ... "); 89: cout << endl; 91: return 0; 92: }