Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Matt Short
- Project 1
- CPSC 131
- Purpose: Write a program as a menu driver to select a particular opertation to take place.*/
- #include <iostream>
- #include "RomanType.h"
- using namespace std;
- void DisplayMenu(); //A funtion that displays a menu of operations to choose from.
- int GetCommand(RomanType& Result); //A function that gets the users choice.
- void RunChoice(int choice, RomanType& Result); //A function that runs the choice of the user.
- int main()
- {
- RomanType Result=RomanType();
- int choice=0; //int to store operation chosen by the user.
- while(choice!=7)
- //displays menu, prompts user for choice, runs choice
- //and continues doing so until user chooses 7=Quit
- {
- DisplayMenu();
- choice=GetCommand(Result);
- RunChoice(choice, Result);
- }
- return 0;
- }
- void DisplayMenu()
- {
- //pre:none
- //post:menu is displayed for user
- cout<<"Choose an operation to execute:"<<endl;
- cout<<"1. Get Arabic number"<<endl;
- cout<<"2. Get Roman numeral"<<endl;
- cout<<"3. Convert from Arabic to Roman"<<endl;
- cout<<"4. Convert from Roman to Arabic"<<endl;
- cout<<"5. Print Arabic number"<<endl;
- cout<<"6. Print Roman numeral"<<endl;
- cout<<"7. Quit"<<endl;
- }
- int GetCommand(RomanType& Result)
- {
- //pre:menu is displayed
- //post:prompts user for a choice, and gets users choice
- int choice;
- cout<<"Please enter the number of the operation you would like executed: ";
- cin>>choice;
- return choice;
- }
- void RunChoice(int choice, RomanType& Result)
- {
- //pre: user has chosen an option
- //post:user choice is run
- switch(choice)
- {
- case 1: cout<<endl;
- Result.getArabicNumber();
- cout<<endl;
- break;
- case 2: cout<<endl;
- Result.getRomanNumber();
- cout<<endl;
- break;
- case 3: cout<<endl;
- Result.convertToRoman();
- cout<<endl;
- break;
- case 4: cout<<endl;
- Result.convertToArabic();
- cout<<endl;
- break;
- case 5: cout<<endl;
- Result.printArabic();
- cout<<endl;
- break;
- case 6: cout<<endl;
- Result.printRoman();
- cout<<endl;
- break;
- case 7: cout<<"Quitting program."<<endl<<endl;
- break;
- default: cout<<"Not a valid input."<<endl<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement