-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
227 lines (217 loc) · 7.51 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include <iostream>
#include <fstream>
#include<limits>
#include<stdio.h>
#include<iomanip>
#include<string.h>
#include<conio.h>
#include<stdexcept>
#include"FullTimeEmployee.h"
#include"PartTimeEmployee.h"
#include"PayrollSystem.h"
using namespace std;
void displayMenu();
void handleMenu();
void login();
int main()
{
int enter;
cout << "PAYROLL - MANAGEMENT - SYSTEM" << endl;
cout << "Welcomes You...!" << endl;
do {
cout << "1.Login\n2.Exit\nEnter your choice: ";
string input;
cin >> input;
cin.ignore();
try {
enter = stoi(input); // Convert input to integer
}
catch (const invalid_argument& e) {
cout << "Invalid input. Please enter an integer." << endl;
enter = -1; // Set choice to an invalid value
}
if (enter >= 1 && enter <= 2) {
switch (enter) {
case 1:
login();
break;
case 2:
cout << "Exiting program...\n";
exit(0);
default:
cout << "Invalid choice. Please try again.\n";
}
}
} while (enter != 2);
return 0;
}
void displayMenu() {
cout << "\nPayroll System Menu\n";
cout << "1. Add Employee\n";
cout << "2. List Employees\n";
cout << "3. Delete Employee\n";
cout << "4. Update Employee\n";
cout << "5. Save Records\n";
cout << "6. Load Records\n";
cout << "7. Search Employee\n";
cout << "8. Print Employee PaySlip\n";
cout << "9. Exit\n";
cout << "Enter your choice: ";
}
void login() {
string username;
char Password[20], ch;
int i = 0;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
while (1)
{
ch = getch();
if (ch == 13)
break;
if (ch == 32 || ch == 9)
continue;
else if (ch == 8) {
if (i > 0) {
i--;
cout<<"\b \b";
}
}
else
{
cout << "*";
Password[i] = ch;
i++;
}
}
Password[i] = '\0';
cout << endl;
if (username == "admin" && strcmp(Password, "payroll") == 0) {
cout<<"Login success...!\n";
handleMenu();
}
else {
cout << "Invalid username or password!\n";
return;
}
}
void handleMenu() {
PayrollSystem payrollSystem;
int choice;
do {
displayMenu();
string input;
cin >> input;
cin.ignore();
try {
choice = stoi(input); // Convert input to integer
}
catch (const invalid_argument& e) {
cout << "Invalid input. Please enter an integer." << endl;
choice = -1; // Set choice to an invalid value
}
if (choice >= 1 && choice <= 9) { // Check if choice is within valid range
switch (choice) {
case 1: {
char name[100];
char designation[100];
int code, exp, age, workingHours;
char anyLoan;
cout << "Enter name: ";
cin.getline(name, sizeof(name));
cout << "Enter code: ";
cin >> code;
cin.ignore();
cout << "Enter designation: ";
cin.getline(designation, sizeof(designation));
cout << "Enter experience: ";
cin >> exp;
cout << "Enter age: ";
cin >> age;
cout << "Enter working hours: ";
cin >> workingHours;
cout << "Any loan? (Y/N): ";
cin >> anyLoan;
cin.ignore();
cout << "Enter Employee Type (1 for Full-Time, 2 for Part-Time): ";
int type;
cin >> type;
cin.ignore();
if (type == 1) {
// Assuming the function to add a full-time employee is correctly implemented
payrollSystem.addFullTimeEmployee(FullTimeEmployee(name, code, designation, exp, age, workingHours, anyLoan));
} else if (type == 2) {
int hourlyRate;
cout << "Enter Employee Hourly Rate: ";
cin >> hourlyRate;
cin.ignore();
payrollSystem.addPartTimeEmployee(PartTimeEmployee(name, code, designation, exp, age, workingHours, hourlyRate, anyLoan));
} else {
cout << "Invalid Employee Type!";
continue;
}
cout << "Employee added successfully!" << endl;
break;
}
case 2: {
int option;
cout << "1. Full-Time Employee\n"
<< "2. Part-Time Employee\n"
<< "Enter your choice: ";
cin >> option;
cin.ignore(); // Clear buffer after reading an integer
if (option == 1) {
payrollSystem.listFullTimeEmployees();
} else if (option == 2) {
payrollSystem.listPartTimeEmployees();
} else {
cout << "Invalid option!" << endl;
}
break;
}
case 3: {
int codeToDelete;
cout << "Enter Employee Code to delete: ";
cin >> codeToDelete;
cin.ignore();
payrollSystem.deleteEmployee(codeToDelete);
break;
}
case 4: {
int codeToUpdate;
cout << "Enter Employee Code to update: ";
cin >> codeToUpdate;
cin.ignore();
payrollSystem.updateEmployee(codeToUpdate);
break;
}
case 5:
payrollSystem.saveEmployees("FullTimeEmployees.dat", "PartTimeEmployees.dat");
cout << "Records saved successfully!" << endl;
break;
case 6:
payrollSystem.loadEmployees("FullTimeEmployees.dat", "PartTimeEmployees.dat");
cout << "Records loaded successfully!" << endl;
break;
case 7:
int code;
cout<<"Enter the code to search the Employee: ";
cin>>code;
payrollSystem.searchEmployee(code);
break;
case 8:
int codeToPrint;
cout<<"Enter the code to display the Pay Slip of Employee: ";
cin>>codeToPrint;
payrollSystem.displayPayslip(codeToPrint);
break;
case 9:
cout << "Exiting program...\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
}
} while (choice != 9);
}