-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUserInterface.cpp
More file actions
76 lines (71 loc) · 1.75 KB
/
Copy pathUserInterface.cpp
File metadata and controls
76 lines (71 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* UserInterface.cpp
*
* Created on: Jul 3, 2010
* Author: gina
*/
#include "UserInterface.h"
#include "Framer.h"
#include "NaturalLanguageMenuItem.h"
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
void UserInterface::run(){
runInteractively();
}
void UserInterface::printMainMenu(){
stringstream menu;
for(int i=0; i<menuList.size(); i++){
menu<<i<<" "<<menuList.at(i)->toString()<<"\n";
}
Framer framedMenu(menu.str(),"Main Menu"," ");
cout<<framedMenu.toString();
}
void UserInterface::runInteractively(){
bool stop=false;
while(!stop){
printMainMenu();
int menuNumber = getInt("Please enter a number corresponding to the menu item: ");
switch (menuNumber){
case 1:
cout<<"You choose 1";
stop=true;
default:
cout<<"Your menu choice was invalid."<<endl;
}//end switch
}//end while
}
void parseInput(){
}
void addMenuItem(){
}
void UserInterface::printLanguageMenu(){
}
UserInterface::UserInterface() {
menuList.push_back(new NaturalLanguageMenuItem("Quit","UserInterface"));
menuList.push_back(new NaturalLanguageMenuItem("Print","menu","UserInterface"));
}
UserInterface::~UserInterface() {
// TODO Auto-generated destructor stub
}
int UserInterface::getInt(string prompt) // definition of getInt(string) from FAQ
{
cout << prompt;
int x;
cin >> x;
while ( ! cin )
{
cin.clear();
string badinput;
getline(cin, badinput);
cerr << "Expected an integer but found " << badinput << endl << prompt;
cin >> x;
}
// Optionally clear the remaining characters in the input stream;
// for example, for a user input '123xyz', 123 is extracted to x and,
// here we choose to discard 'xyz' which is still in the input stream
string leftover;
getline(cin, leftover);
return x; // ignore leftover
}