forked from DSC-COEA-Ambajogai/Hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmployee ds
251 lines (238 loc) · 7.34 KB
/
Employee ds
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
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<iostream>
using namespace std;
struct EmpNo
{
char ocp;
int Year;
int Month;
int s_no;
};
struct Address
{
char h_no[20];
char street_name[20];
char town[30];
char city[30];
char state[30];
char country[30];
int pin;
};
struct Employee
{
struct EmpNo empN;
char name[40];
char F_name[50];
char M_name[50];
struct Address adr;
struct Employee * next;
};
typedef struct Employee list;
list* getnewNode()
{
list* newNod = (list*)malloc(sizeof(list));
newNod->next = NULL;
return (newNod);
}
void insert(list** head) { //at beginning
list* newNode = getnewNode(); char buff[100];
cout<<"\nEnter the occupation of the Employee(O/C/M)(O-Office,C-Clerk,M-Multitask)\t";
scanf(" %c",&newNode->empN.ocp);
cout<<"\nEnter the Year of the entry of the employee\t";
scanf(" %d", &newNode->empN.Year);
cout<<"\nEnter the month of the entry of the employee\t";
scanf(" %d", &newNode->empN.Month);
cout<<"\nEnter the social security number of the employee\t";
scanf(" %d", &newNode->empN.s_no);
gets(buff);
cout<<"\nEnter the Name of the Employee: \t";
gets(newNode->name);
cout<<"\nEnter the Father's Name of the Employee: \t";
gets(newNode->F_name);
cout<<"\nEnter the Mother's Name of the Employee: \t";
gets(newNode->M_name);
cout<<"\nEnter the house number of the Employee: \t";
gets(newNode->adr.h_no);
cout<<"\nEnter the street name of the Employee: \t";
gets(newNode->adr.street_name);
cout<<"\nEnter the Name of town/village of the Employee: \t";
gets(newNode->adr.town);
cout<<"\nEnter the Name of City of the Employee: \t";
gets(newNode->adr.city);
cout<<"\nEnter the Name of state of the Employee: \t";
gets(newNode->adr.state);
cout<<"\nEnter the Name of Country of the Employee: \t";
gets(newNode->adr.country);
cout<<"\nEnter the PIN code of the Employee: \t";
scanf(" %d", &newNode->adr.pin);
if ((*head) == NULL)
(*head) = newNode;
else if ((*head)->next == NULL)
{
(*head)->next = newNode;
}
else
{
newNode->next = (*head);
(*head) = newNode;
}
}
void create(list** head)
{
int n;
cout<<"\nEnter the number of records you want to enter \n";
scanf(" %d", &n);
for (int i = 0; i < n; i++) {
insert(&(*head));
}
}
void display(list* head)
{
if (head == NULL) {
cout<<"Record empty, exiting.";
return;
}
while (head != NULL) {
printf("\nEmployee Number in order (Occupation, Year, Month, No.)\n %c %d %d %d", head->empN.ocp, head->empN.Year, head->empN.Month, head->empN.s_no);
printf("\nName of the Employee \n %s", head->name);
printf("\nFather's Name of the Employee\n %s", head->F_name);
printf("\nMother's Name of the Employee\n %s", head->M_name);
printf("\nHouse number of the Employee\n %s",head->adr.h_no);
printf("\nStreet name of the Employee\n%s",head->adr.street_name);
printf("\nName of town/village of the Employee\n %s", head->adr.town);
printf("\nCity of the Employee\n %s", head->adr.city);
printf("\nState of the Employee\n %s", head->adr.state);
printf("\nCountry of the employee\n %s",head->adr.country);
printf("\nEnter the PIN code of the Employee\n %d",head->adr.pin);
head = head->next;
}
return;
}
void disp(list* head) {
printf("\nEmployee Number in order (O Y M N)\n %c %d %d %d", head->empN.ocp, head->empN.Year, head->empN.Month, head->empN.s_no);
printf("\nName of the Employee \n %s", head->name);
printf("\nFather's Name of the Employee\n %s", head->F_name);
printf("\nMother's Name of the Employee\n %s", head->M_name);
printf("\nHouse number of the Employee\n %s",head->adr.h_no);
printf("\nStreet name of the Employee\n%s",head->adr.street_name);
printf("\nName of town/village of the Employee\n %s", head->adr.town);
printf("\nCity of the Employee\n %s", head->adr.city);
printf("\nState of the Employee\n %s", head->adr.state);
printf("\nCountry of the employee\n %s",head->adr.country);
printf("\nEnter the PIN code of the Employee\n %d", head->adr.pin);
return;
}
void searchNo(list* head, int ssn)
{
int flag = 0;
while ((head != NULL)&& flag==0)
{
if (head->empN.s_no = ssn)
{
cout<<"\nRecord Found";
flag = 1;
}
}
if (flag == 0)
cout<<"\nRecord not found";
}
void delet(list** head, int ssn)
{
if ((*head)==NULL){
cout<<"Record empty, exiting.";
return ;
}
if ((*head)->empN.s_no == ssn)
(*head) = (*head)->next;
list* temp;
temp = getnewNode();
(*head) = temp;
(*head)=(*head)->next;
while ((*head)!=NULL)
{
if ((*head)->empN.s_no == ssn)
{
temp->next = (*head) ->next;
temp = (*head);
free(temp);
}
(*head)=(*head)->next;
}
cout<<"\n New Record list is as follows \n";
display(*head);
}
void count(list* head, int Yr) {
int count = 0;
while (head != NULL) {
if (head->empN.Year == Yr) {
disp(head);
count++;
}
head = head->next;
}
printf("No of employees in the year %d are %d", Yr,count);
}
int main()
{
list* head;
head = NULL;
int choice, ssn, sn, y;
char ans = 'y';
do{
cout<<"\t\t MAIN MENU\n";
cout<<"1.Create new record.\n";
cout<<"2.Insert new record into the database.\n";
cout<<"3.Display the records.\n";
cout<<"4.Search the record for a given Social Security Number.\n";
cout<<"5.Delete a record for a given SSN.\n";
cout<<"6.Count the number of employees from a particular year. \n";
scanf(" %d", &choice);
switch (choice)
{
case 1:
create(&head);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
case 2:
insert(&head);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
case 3:
display(head);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
case 4:
cout<<"\nEnter the SSN you want to search in the record\n";
scanf(" %d", &ssn);
searchNo(head, ssn);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
case 5:
cout<<"\nEnter the SSN of the record you want to delete \n";
scanf(" %d", &sn);
delet(&head, sn);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
case 6:
cout<<"\nEnter the year of which you want to count the employees.\n";
scanf(" %d", &y);
count(head, y);
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
default:
cout<<"\n Wrong choice selected.";
cout<<"\nDo you want to return to main menu(Y/N)";
scanf(" %c", &ans);
break;
}
} while (ans == 'y' || ans == 'Y');
return 0;
}