From 7d66e92f48b84101d8e2278f4301fe7d8130b67f Mon Sep 17 00:00:00 2001 From: Tisha Malkani Date: Wed, 30 Oct 2024 22:54:55 +0530 Subject: [PATCH] Update employee_data.c Added updating, deleting and adding employees (function) --- C/employee_data.c | 196 ++++++++++++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 75 deletions(-) diff --git a/C/employee_data.c b/C/employee_data.c index aab8e44..99284a8 100644 --- a/C/employee_data.c +++ b/C/employee_data.c @@ -1,91 +1,137 @@ - #include #include -struct details -{ -char name[30]; -int eid; -int salary; + +struct details { + char name[30]; + int eid; + int salary; }; + struct details emp[30]; + void disp(int r); void emp_search(int r); void greater(int r); -int main() -{ -int n,i,ch; -printf("How many employees do you want to add?:"); -scanf("%d",&n); -for (i=0;i 10000\n3 for searching by employee ID\n4 to update employee details\n5 to delete employee\n6 to add more employees\n7 to exit\nEnter choice: "); + scanf("%d", &ch); + + switch (ch) { + case 1: disp(n); break; + case 2: greater(n); break; + case 3: emp_search(n); break; + case 4: updateEmployee(n); break; + case 5: deleteEmployee(&n); break; + case 6: addEmployees(&n); break; + case 7: exit(0); break; + default: printf("Invalid choice! Please try again.\n"); + } + } +} + +void addEmployees(int *r) { + int num, i; + printf("How many employees do you want to add?: "); + scanf("%d", &num); + + for (i = *r; i < *r + num; i++) { + printf("\n-------------------------"); + printf("\nEnter details of employee %d", i + 1); + printf("\n-------------------------"); + printf("\nEnter name: "); + scanf("%s", emp[i].name); + printf("\nEnter employee ID: "); + scanf("%d", &emp[i].eid); + printf("\nEnter employee salary: "); + scanf("%d", &emp[i].salary); + } + *r += num; } -while(1){ -printf("\nMENU"); -printf("\n-------------------------"); -printf("\nEnter\n1 for display\n2 for searching salary>10000\n3 for searching employee number\n4 to exit\nEnter choice:"); -scanf("%d",&ch); -switch (ch) -{ -case 1: -disp(n); -break; -case 2: -greater(n); -break; -case 3: -emp_search(n); -break; -case 4: -exit(0); -break; -}//switch closed -}//while closed -}//main closed -void disp(int r) -{ -//int n; -printf("\nEmployee details are as follows:"); -printf("\n-------------------------------------"); -printf("\n"); -printf("\nNAME\tEID\tSALARY\t"); +void disp(int r) { + printf("\nEmployee details are as follows:"); + printf("\n-------------------------------------"); + printf("\nNAME\tEID\tSALARY\t"); -for (int i=0;i= 10000) { + printf("\nNAME\tEID\tSALARY\t\n%s\t%d\t%d", emp[i].name, emp[i].eid, emp[i].salary); + } + } } -void greater(int r){ -printf("Employee(s) having salary more than 10000:"); -for (int i=0;i=10000) -{ -printf("\nNAME\tEID\tSALARY\t\n%s\t%d\t%d",emp[i].name,emp[i].eid,emp[i].salary); + +void emp_search(int r) { + int k, i; + printf("\nEnter the E ID you want to search: "); + scanf("%d", &k); + printf("\n-------------------------------------"); + for (i = 0; i < r; i++) { + if (emp[i].eid == k) { + printf("\nNAME\tEID\tSALARY\t\n%s\t%d\t%d", emp[i].name, emp[i].eid, emp[i].salary); + } + } } -}//for closed -}//greater closed -void emp_search(int r){ -int k,i; -printf("\nEnter the E ID you want to search:"); -scanf("%d",&k); -printf("\n-------------------------------------"); -for (int i=0;i