1: //test_menu2.cpp 2: //A test driver for the Scobey::Menu class. 3: //Illustrates some Menu class error messages. 5: #include <iostream> 6: #include <string> 7: using namespace std; 9: #include "utilities.h" 10: using Scobey::Menu; 11: using Scobey::Pause; 13: int main() 14: { 15: Pause(0, "\nTesting the Scobey::Menu class ..." 16: "\n\nIn this program we show what happens when we try to do " 17: "some things we\nshouldn't do with Menu objects." 18: "\n\nFirst we create and display a blank menu."); 19: Menu menu1; 20: menu1.display(); 21: Pause(); 23: Pause(0, "Now watch what happens if we try to add to this " 24: "existing menu\na title that's too long."); 25: string longTitle("A Title That is Way, Way, Way, Way "); 26: longTitle += "Too ..... Long for any Reasonable Menu"; 27: menu1.setTitle(longTitle); 29: Pause(0, "Now we show the menu again, unchanged."); 30: menu1.display(); 31: Pause(); 33: Pause(0, "Next we see the error we get if we try to add " 34: "an option that's too long."); 35: string longOption("This option is going to be way too long "); 36: longOption += "to be added to any menu, for sure!"; 37: menu1.addOption(longOption); 39: Pause(0, "Once again, here's the same menu, unchanged."); 40: menu1.display(); 41: Pause(); 43: Pause(0, "And here's what happens if we attempt to get a " 44: "menu choice from\na \"title-only\" menu, i.e., " 45: "a menu with no options."); 46: int menuChoice = menu1.getChoice(); 47: cout << "The menu choice returned in this case was " 48: << menuChoice << ".\n"; 49: Pause(); 52: Pause(0, "An error also occurs if we try to create a new " 53: "menu and initialize it\nin the constructor with " 54: "a title that's too long, as we see next."); 55: Menu menu2(longTitle); 57: Pause(0, "We show next the menu we actually created."); 58: menu2.display(); 59: Pause(); 62: Pause(0, "Finally, we show what happens if we try to add an " 63: "\noption to a menu that already has 20 options." 64: "\nSo, first we show the menu ..."); 65: Menu menu3("Test Menu"); 66: menu3.addOption("Option 1 permits you to quit"); 67: menu3.addOption("Option 2 allows you to do this"); 68: menu3.addOption("Option 3 lets you do something just a bit longer"); 69: menu3.addOption("Option 4 just lets you do it"); 70: menu3.addOption("Option 5 lets you do that"); 71: menu3.addOption("Option 6 lets you do it now, not later"); 72: menu3.addOption("Option 7 lets you do whatever"); 73: menu3.addOption("Option 8 requires you to do it quickly if you can"); 74: menu3.addOption("Option 9 lets you do it and take your time"); 75: menu3.addOption("Option 10 lets you do it over and over again"); 76: menu3.addOption("Option 11 lets you do it with style"); 77: menu3.addOption("Option 12 requires it to be done by Monday"); 78: menu3.addOption("Option 13 asks that you do it next week"); 79: menu3.addOption("Option 14 demands that it be done yesterday"); 80: menu3.addOption("Option 15 doesn't care if it's done at all"); 81: menu3.addOption("Option 16 lets you do it whenever you like"); 82: menu3.addOption("Option 17 requires it to happen every Friday"); 83: menu3.addOption("Option 18 suggests you do it Sundays and Mondays"); 84: menu3.addOption("Option 19 asks for a full report in the morning"); 85: menu3.addOption("Option 20 asks you to undo it"); 86: menu3.display(); 87: Pause(); 89: Pause(0, "Now note what happens when we attempt to add another " 90: "option,\nthus exceeding the maximum of 20."); 91: menu3.addOption("And yet another option ... "); 93: Pause(0, "And finally we show the 20-option menu, unchanged."); 94: menu3.display(); 95: Pause(); 97: Pause(0, "No more tests to perform." 98: "\nProgram will now terminate."); 99: }