-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
141 lines (118 loc) · 3.62 KB
/
Copy pathmain.cpp
File metadata and controls
141 lines (118 loc) · 3.62 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
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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "employee_class.h"
#include "file_manipulation.h"
#include "navigation.h"
#include "array_manipulation.h"
#include "handle_user_input.h"
using namespace std;
int main() {
// initial welcome and prompt for file
cout << "-----------------------------------------------------" << endl;
cout << "\n\tEmployee Management System" << endl;
cout << "\nWould you like to:" << endl;
cout << "1. Load existing employee file." << endl;
cout << "2. Create new employee file." << endl;
int userFileChoice = 0;
while (userFileChoice != 1 && userFileChoice != 2) {
userFileChoice = getValueByInteger("file choice");
}
string employeeDataFilename;
string userPrompt;
vector <Employee> employeesArray;
// load existing file
if (userFileChoice == 1) {
cout << "\nWelcome back, Nord Etoile!" << endl;
employeeDataFilename = getFileName("name of employee data file");
ifstream fin;
bool isOpen = openIfstream(fin, employeeDataFilename);
while(!isOpen)
{
employeeDataFilename = getFileName("file name");
isOpen = openIfstream(fin, employeeDataFilename);
}
employeesArray = readEmployeeDataFile(fin);
fin.close();
} else {
// load new file
cout << "\nWelcome, New User!" << endl;
employeeDataFilename = getFileName("name of new employee data file");
}
cout << "-----------------------------------------------------" << endl;
// menu-based navigation
int userChoice;
while (true) {
cout << "-----------------------------------------------------" << endl;
cout << "What do you want to do?" << endl;
// menu
cout << "0: Exit the program, and record changes to your employee data in the file you loaded." << endl;
cout << "1: Create a new employee record." << endl;
// if employees array is empty, do not allow user to pick menu options 2 to 7
if (employeesArray.size() > 0) {
cout << "2: Search employees." << endl;
cout << "3: Display list of employees." << endl;
cout << "4: Sort employee records." << endl;
cout << "5: Modify record of an employee." << endl;
cout << "6: Fire employees." << endl;
cout << "7. Delete employee records." << endl;
}
cout << "-----------------------------------------------------" << endl;
// prompt for user input
userChoice = getValueByInteger("choice");
if (employeesArray.size() == 0 && (userChoice > 1 || userChoice < 0)) {
cout << "\nThere aren't any employee records. The function you have selected is not available." << endl;
continue;
}
switch (userChoice) {
// all cases will call a corresponding function from navigation.h
case 0:
{
exitProgram(employeeDataFilename, employeesArray);
break;
}
case 1:
{
createNewEmployee(employeesArray);
break;
}
case 2:
{
searchEmployees(employeesArray);
break;
}
case 3:
{
displayEmployees(employeesArray);
break;
}
case 4:
{
sortEmployeesArray(employeesArray);
break;
}
case 5:
{
modifyEmployeeRecords(employeesArray);
break;
}
case 6:
{
fireEmployees(employeesArray);
break;
}
case 7:
{
deleteEmployeeRecords(employeesArray);
break;
}
default:
{
cout << "\nPlease make a valid choice from the options given." << endl;
break;
}
}
}
return 0;
}