-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
170 lines (150 loc) · 3.38 KB
/
main.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <stdexcept>
#include "Database.h"
using namespace Records;
int displayMenu();
void doHire(Database& db);
void doFire(Database& db);
void doPromote(Database& db);
void doDemote(Database& db);
int main()
{
Database employeeDB;
bool isDone{};
while (!isDone)
{
int selection = displayMenu();
switch (selection)
{
case 0:
isDone = true;
break;
case 1:
doHire(employeeDB);
break;
case 2:
doFire(employeeDB);
break;
case 3:
doPromote(employeeDB);
break;
case 4:
doDemote(employeeDB);
break;
case 5:
employeeDB.displayAll();
break;
case 6:
employeeDB.displayCurrent();
break;
case 7:
employeeDB.displayFormer();
break;
default:
std::cerr << "Unknown Command, please provide a valid number." << std::endl;
break;
}
}
return 0;
}
/**
* Displays the menu where the user can select from.
* @return int The users selection.
*/
int displayMenu()
{
int selection;
std::cout << std::endl;
std::cout << "Employee Database" << std::endl;
std::cout << "-----------------" << std::endl;
std::cout << "1) Hire a new employee" << std::endl;
std::cout << "2) Fire an employee" << std::endl;
std::cout << "3) Promote an employee" << std::endl;
std::cout << "4) Demote an employee" << std::endl;
std::cout << "5) List all employees" << std::endl;
std::cout << "6) List all current employees" << std::endl;
std::cout << "7) List all former employees" << std::endl;
std::cout << "0) Quit" << std::endl;
std::cout << std::endl;
std::cout << "---> ";
std::cin >> selection;
return selection;
}
/**
* Hires the Employee based on the provided first and last name.
* @param db Database object.
*/
void doHire(Database& db)
{
std::string firstName{};
std::string lastName{};
std::cout << "First name? ";
std::cin >> firstName;
std::cout << "Last name? ";
std::cin >> lastName;
db.addEmployee(firstName, lastName);
}
/**
* Fires the employee based on the provided employee number.
* @param db Database object.
*/
void doFire(Database& db)
{
int employeeNumber{};
std::cout << "Employee number? ";
std::cin >> employeeNumber;
try
{
Employee& employee = db.getEmployee(employeeNumber);
employee.fire();
std::cout << "Employee " << employeeNumber << " has been fired." << std::endl;
}
catch (const std::logic_error& exception)
{
std::cerr << "Unable to fire the employee: " << exception.what() << std::endl;
}
}
/**
* Promotes the given Employee.
* @param db Database object.
*/
void doPromote(Database& db)
{
int employeeNumber{};
int raiseAmount{};
std::cout << "Employee number? ";
std::cin >> employeeNumber;
std::cout << "How much of a raise? ";
std::cin >> raiseAmount;
try
{
Employee& employee = db.getEmployee(employeeNumber);
employee.promote(raiseAmount);
}
catch (const std::logic_error& exception)
{
std::cerr << "Unable to promote employee: " << exception.what() << std::endl;
}
}
/**
* Demotes the given Employee.
* @param db Database object.
*/
void doDemote(Database& db)
{
int employeeNumber{};
int demoteAmount{};
std::cout << "Employee number? ";
std::cin >> employeeNumber;
std::cout << "How much of a demote? ";
std::cin >> demoteAmount;
try
{
Employee& employee = db.getEmployee(employeeNumber);
employee.demote(demoteAmount);
}
catch (const std::logic_error& exception)
{
std::cerr << "Unable to demote employee: " << exception.what() << std::endl;
}
}