Advertisement
darkhelmet125

RomanType - menu driver

Sep 22nd, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. /*Matt Short
  2. Project 1
  3. CPSC 131
  4. Purpose: Write a program as a menu driver to select a particular opertation to take place.*/
  5. #include <iostream>
  6. #include "RomanType.h"
  7. using namespace std;
  8.  
  9. void DisplayMenu(); //A funtion that displays a menu of operations to choose from.
  10. int GetCommand(RomanType& Result);  //A function that gets the users choice.
  11. void RunChoice(int choice, RomanType& Result);  //A function that runs the choice of the user.
  12.  
  13. int main()
  14. {
  15.     RomanType Result=RomanType();
  16.     int choice=0;   //int to store operation chosen by the user.
  17.     while(choice!=7)
  18.     //displays menu, prompts user for choice, runs choice
  19.     //and continues doing so until user chooses 7=Quit
  20.     {
  21.         DisplayMenu();
  22.         choice=GetCommand(Result);
  23.         RunChoice(choice, Result);
  24.     }
  25.     return 0;
  26. }
  27.  
  28. void DisplayMenu()
  29. {
  30.     //pre:none
  31.     //post:menu is displayed for user
  32.     cout<<"Choose an operation to execute:"<<endl;
  33.     cout<<"1. Get Arabic number"<<endl;
  34.     cout<<"2. Get Roman numeral"<<endl;
  35.     cout<<"3. Convert from Arabic to Roman"<<endl;
  36.     cout<<"4. Convert from Roman to Arabic"<<endl;
  37.     cout<<"5. Print Arabic number"<<endl;
  38.     cout<<"6. Print Roman numeral"<<endl;
  39.     cout<<"7. Quit"<<endl;
  40. }
  41. int GetCommand(RomanType& Result)
  42. {
  43.     //pre:menu is displayed
  44.     //post:prompts user for a choice, and gets users choice
  45.     int choice;
  46.     cout<<"Please enter the number of the operation you would like executed: ";
  47.     cin>>choice;
  48.     return choice;
  49. }
  50. void RunChoice(int choice, RomanType& Result)
  51. {
  52.     //pre: user has chosen an option
  53.     //post:user choice is run
  54.     switch(choice)
  55.     {
  56.         case 1: cout<<endl;
  57.             Result.getArabicNumber();
  58.             cout<<endl;
  59.             break;
  60.         case 2: cout<<endl;
  61.             Result.getRomanNumber();
  62.             cout<<endl;
  63.             break;
  64.         case 3: cout<<endl;
  65.             Result.convertToRoman();
  66.             cout<<endl;
  67.             break;
  68.         case 4: cout<<endl;
  69.             Result.convertToArabic();
  70.             cout<<endl;
  71.             break;
  72.         case 5: cout<<endl;
  73.             Result.printArabic();
  74.             cout<<endl;
  75.             break;
  76.         case 6: cout<<endl;
  77.             Result.printRoman();
  78.             cout<<endl;
  79.             break;
  80.         case 7: cout<<"Quitting program."<<endl<<endl;
  81.             break;
  82.         default: cout<<"Not a valid input."<<endl<<endl;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement