-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstud.cpp
259 lines (241 loc) · 9.77 KB
/
stud.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<windows.h>
#include<unistd.h>
using namespace std;
class employee{
private:
// Variables for employee details
char name[30];
char id[5];
char designation[10];
int age;
int ctc;
int experience;
// Utility functions
void waitForEnter(void){
cout<<"\n\n\n Press enter to go back \n\n";
cin.get();
cin.get();
}
// Functions to perform desired actions
void listEmployees(void){ //To list total employees with Name, Id and Designation
system("cls");
FILE *file;
file= fopen("data.txt", "r");
cout<<"\n\t List of Employees\n";
cout<<"\n----------------------------------------------";
cout<<"\n NAME | ID | DESIGNATION\n";
cout<<"----------------------------------------------";
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc, &experience)!= EOF)
cout<<"\n"<<name<<"\t\t"<<id<<"\t\t"<<designation;
fclose(file);
waitForEnter();
}
void showDetails(void){ //Displays all details according to Employee's id
system("cls");
FILE *file;
char checkId[5];
cout<<"\n\nEnter Employee ID: ";
cin>>checkId;
file= fopen("data.txt", "r");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc, &experience)!=EOF)
if(strcmp(checkId,id)==0){
cout<<"\n---------------------";
cout<<"\nName: "<<name;
cout<<"\n---------------------";
cout<<"\nId: "<<id;
cout<<"\n---------------------";
cout<<"\nDesignation: "<<designation;
cout<<"\n---------------------";
cout<<"\nAge: "<<age;
cout<<"\n---------------------";
cout<<"\nCTC: "<<ctc;
cout<<"\n---------------------";
cout<<"\nExperience: "<<experience;
cout<<"\n---------------------";
}
fclose(file);
waitForEnter();
}
void editExisting(void){ //edits Designation and CTC of an employee
system("cls");
char checkId[5];
cout<<"\nEnter employee id: ";
cin>>checkId;
char newDesignation[10];
cout<<"\n-----------------------------";
cout<<"\nEnter new designation: ";
cin>>newDesignation;
int newCtc;
cout<<"------------------------------";
cout<<"\nEnter new CTC: ";
cin>>newCtc;
FILE *file, *tempfile;
file= fopen("data.txt", "r");
tempfile= fopen("temp.txt", "w");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc, &experience)!=EOF){
if(strcmp(checkId, id)==0)
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, newDesignation, age, newCtc, experience );
else
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
}
fclose(file);
fclose(tempfile);
int isRemoved= remove("data.txt");
int isRenamed= rename("temp.txt", "data.txt");
waitForEnter();
}
void addNewEmployee(void){ //adding records
system("cls");
cout<<"\n----------------------------------------";
cout<<"\n Enter First Name of Employee: ";
cin>>name;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee ID [max 4 digits]: ";
cin>>id;
cout<<"\n----------------------------------------";
cout<<"\n Enter Designation: ";
cin>>designation;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee Age: ";
cin>>age;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee CTC: ";
cin>>ctc;
cout<<"\n----------------------------------------";
cout<<"\n Enter Employee Experience: ";
cin>>experience;
cout<<"\n----------------------------------------";
char ch;
cout<<"\nEnter 'y' to save above information\n";
cin>>ch;
if(ch=='y'){
FILE *file;
file= fopen("data.txt","a");
fprintf(file, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
fclose(file);
cout<<"\nNew Employee has been added to database\n";
}
else
addNewEmployee();
waitForEnter();
}
void deleteEmployeeDetails(void){ //removing records
system("cls");
char checkId[5];
cout<<"\n----------------------------------";
cout<<"\nEnter Employee Id To Remove: ";
cin>>checkId;
char ch;
cout<<"----------------------------------";
cout<<"\n\n\n\n\nCONFIRMATION\nEnter 'y' To Confirm Deletion \n";
cin>>ch;
if(ch=='y'){
FILE *file, *tempfile;
file= fopen("data.txt", "r");
tempfile= fopen("temp.txt", "w");
while(fscanf(file, "%s %s %s %d %d %d", &name[0], &id[0] , &designation[0], &age, &ctc, &experience)!=EOF)
if(strcmp(checkId, id)!=0)
fprintf(tempfile, "%s %s %s %d %d %d \n", name, id, designation, age, ctc, experience );
fclose(file);
fclose(tempfile);
int isRemoved= remove("data.txt");
int isRenamed= rename("temp.txt", "data.txt");
cout<<"\nRemoved Successfully\n";
waitForEnter();
}
else
deleteEmployeeDetails();
}
public:
// Function to serve as end point
void options(void){ //menu
int login(); //login declaration
login();//login screen
while(true){
system("cls");
// Options to choose an action
cout<<"\n\t\t\t>>>>>>>>> EMPLOYEE MANAGEMENT SYSTEM <<<<<<<<<";
cout<<"\n";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 1: To View List of Employees";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 2: To View Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 3: To Modify Existing Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 4: To Add New Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 5: To Remove an Employee Details";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\t\t\tENTER 0: To Exit ";
cout<<"\n\t\t\t------------------------------------------------";
cout<<"\n\n\t\t\t Please Enter Your Choice: ";
// Taking the action input
int choice;
cin>>choice;
// Calling relevant function as per choice
switch (choice) {
case 0:
system("CLS");
cout<<"\n\nEMPLOYEE MANAGEMENT SYSTEM \n\n Brought To You By code-projects.org\n\n ";
Sleep(10);
return;
case 1:
listEmployees();
break;
case 2:
showDetails();
break;
case 3:
editExisting();
break;
case 4:
addNewEmployee();
break;
case 5:
deleteEmployeeDetails();
break;
default:
cout<<"\n Sorry! I don't understand that! \n";
break;
}
}
}
};
int main(){
// Call the options function
employee e;
e.options();
return 0;
}
int login(){ //login procedure
string pass ="";
char ch;
cout <<"\n\n\n\n\t\t\t\t\tEMPLOYEE MANAGEMENT SYSTEM";
cout <<"\n\n\n\n\n\t\t\t\t\tEnter Your Password :";
ch = _getch();
while(ch != 13){//character 13 is enter
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "pass"){
cout<<"\n\n\n\t\t\t\t\tLOADING \n\t\t\t\t\t";
for(int a=1;a<8;a++) // Change 'a<?' to how many * you want
{
Sleep(500);
cout << "...";
}
cout << "\n\n\n\t\t\t\t\tAccess Granted!! \n\n\n";
system("PAUSE");
system("CLS");
}else{
cout << "\nAccess Aborted...\n";
login();
}
}