-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInterface.cpp
115 lines (96 loc) · 2.12 KB
/
UserInterface.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// UserInterface.cpp
#include <iostream>
#include <stdexcept>
#include "Database.h"
using namespace std;
using namespace Records;
int displayMenu();
void addTicket(Database& db);
void displayByType(Database& db);
void displayByTrainNumber(Database& db);
int start()
{
Database ticketDB;
bool done = false;
while (!done) {
int selection = displayMenu();
switch (selection) {
case 1:
addTicket(ticketDB);
break;
case 2:
ticketDB.displayAll();
case 3:
displayByType(ticketDB);
break;
case 4:
displayByTrainNumber(ticketDB);
break;
case 0:
done = true;
break;
default:
cerr << "Unknown command." << endl;
}
}
return 0;
}
int displayMenu()
{
int selection;
cout << endl;
cout << "Tickets Database" << endl;
cout << "-----------------" << endl;
cout << "1) Add a new ticket" << endl;
cout << "2) Display all tickets" << endl;
cout << "3) Display all tickets with type" << endl;
cout << "4) Display all tickets with train number" << endl;
cout << "0) Quit" << endl;
cout << endl;
cout << "---> ";
cin >> selection;
return selection;
}
void addTicket(Database& inDB)
{
string passengerName;
string from;
string to;
string type;
int trainNumber;
int coachNumber;
int seatNumber;
cout << "Passenger name? ";
cin >> passengerName;
cout << "From location? ";
cin >> from;
cout << "To location? ";
cin >> to;
cout << "Ticket type? ";
cin >> type;
cout << "Train number? ";
cin >> trainNumber;
cout << "Coach number? ";
cin >> coachNumber;
cout << "Seat number? ";
cin >> seatNumber;
try {
inDB.addTicket(passengerName, from, to, type, trainNumber, coachNumber, seatNumber);
} catch (const std::exception&) {
cerr << "Unable to add new employee!" << endl;
}
}
void displayByType(Database &db)
{
string type;
cout << "Type of tickets to show? ";
cin >> type;
db.displayByType(type);
}
void displayByTrainNumber(Database &db)
{
int trainNumber;
cout << "Train number of tickets to show? ";
cin >> trainNumber;
db.displayByTrainNumber(trainNumber);
}