Source of shell.cpp


  1: // Filename: SHELL.CPP
  2: // Purpose:  Provides a shell starter program utilizing both
  3: //           a "menu" and on-line help or other "text items".

  5: #include <iostream>
  6: using namespace std;

  8: #include "MENU.H"     // Header file for the Menu class
  9: #include "TXITEMS.H"  // Header file for the TextItems class

 11: int main()
 12: {
 13:     Menu m("Main Menu"); // Declare a Menu object "m" with title "Main Menu"
 14:     m.AddOption("Quit"); // Then add four options to the menu "m" ...
 15:     m.AddOption("Get information");
 16:     m.AddOption("Do something");
 17:     m.AddOption("Do something else");

 19:     TextItems itemList("SHELL.DAT"); // Load text items into memory
 20:     int menuChoice;

 22:     do
 23:     {
 24:         m.Display();  // Display the menu
 25:         menuChoice = m.Choice();  // Get the user's choice

 27:         if (menuChoice == -1) // If user choice not OK ...
 28:         {
 29:             cout << "\nUser failed to make valid menu choice."
 30:                  << "\nProgram now terminating.";
 31:             return 1;  // Exit program, indicating unsuccessful termination.
 32:         }

 34:         switch (menuChoice) // Display text item depending on user's choice
 35:         {
 36:             case 1: /* Do nothing */;                             break;
 37:             case 2: itemList.DisplayItem("Program Info");         break;
 38:             case 3: itemList.DisplayItem("Doing Something");      break;
 39:             case 4: itemList.DisplayItem("Doing Something Else"); break;
 40:         }

 42:     } while (menuChoice != 1); // Quit when user chooses first menu option

 44:     return 0;
 45: }