-
Notifications
You must be signed in to change notification settings - Fork 0
/
employeemanagementsystem.c
129 lines (114 loc) · 4.2 KB
/
employeemanagementsystem.c
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
#include <stdio.h>
enum EmployeeType {
FullTime,
PartTime
};
union EmployeeDetails {
struct {
float monthlySalary;
float bonus;
} fullTime;
struct {
float hourlyRate;
int hoursWorked;
} partTime;
};
struct Employee {
char name[50];
int age;
enum EmployeeType type;
union EmployeeDetails details;
};
int main() {
int numEmployees;
printf("Enter the number of employees: ");
scanf("%d", &numEmployees);
struct Employee employees[numEmployees];
for (int i = 0; i < numEmployees; i++) {
printf("\nEnter details for Employee %d\n", i + 1);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Age: ");
scanf("%d", &employees[i].age);
//int employeeType;
enum EmployeeType employeeType;
printf("Employee Type (0 for Full-time, 1 for Part-time): ");
scanf("%d", &employeeType);
if (employeeType == FullTime) {
employees[i].type = FullTime;
printf("Monthly Salary: ");
scanf("%f", &employees[i].details.fullTime.monthlySalary);
printf("Bonus: ");
scanf("%f", &employees[i].details.fullTime.bonus);
} else if (employeeType == PartTime) {
employees[i].type = PartTime;
printf("Hourly Rate: ");
scanf("%f", &employees[i].details.partTime.hourlyRate);
printf("Hours Worked: ");
scanf("%d", &employees[i].details.partTime.hoursWorked);
} else {
printf("Invalid employee type! Setting as Full-time.\n");
employees[i].type = FullTime;
printf("Monthly Salary: ");
scanf("%f", &employees[i].details.fullTime.monthlySalary);
printf("Bonus: ");
scanf("%f", &employees[i].details.fullTime.bonus);
}
}
int choice;
printf("\nEmployee Management System\n");
printf("1. Calculate total monthly salary for all full-time employees\n");
printf("2. Calculate total earnings for all part-time employees\n");
printf("3. Display details of all employees\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: {
float totalMonthlySalary = 0.0;
for (int i = 0; i < numEmployees; i++) {
if (employees[i].type == FullTime) {
totalMonthlySalary += employees[i].details.fullTime.monthlySalary;
}
}
printf("Total monthly salary for all full-time employees: %.2f\n", totalMonthlySalary);
break;
}
case 2: {
float totalEarnings = 0.0;
for (int i = 0; i < numEmployees; i++) {
if (employees[i].type == PartTime) {
totalEarnings += employees[i].details.partTime.hourlyRate * employees[i].details.partTime.hoursWorked;
}
}
printf("Total earnings for all part-time employees: %.2f\n", totalEarnings);
break;
}
case 3: {
printf("\nDetails of all employees:\n");
for (int i = 0; i < numEmployees; i++) {
printf("Employee %d\n", i + 1);
printf("Name: %s\n", employees[i].name);
printf("Age: %d\n", employees[i].age);
if (employees[i].type == FullTime) {
printf("Employee Type: Full-time\n");
printf("Monthly Salary: %.2f\n", employees[i].details.fullTime.monthlySalary);
printf("Bonus: %.2f\n", employees[i].details.fullTime.bonus);
} else if (employees[i].type == PartTime) {
printf("Employee Type: Part-time\n");
printf("Hourly Rate: %.2f\n", employees[i].details.partTime.hourlyRate);
printf("Hours Worked: %d\n", employees[i].details.partTime.hoursWorked);
}
printf("--------------------\n");
}
break;
}
case 4:
printf("Exiting the program. Goodbye!\n");
break;
default:
printf("Invalid choice!\n");
break;
}
return 0;
}