Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- float avg;
- typedef struct Node
- {
- char name[100];
- int age, emp_num;
- char date[10];
- float salary;
- struct Node *next;
- } Node;
- Node *getNode()
- {
- Node *p;
- p = (Node *)malloc(sizeof(Node));
- return p;
- }
- typedef struct
- {
- int count;
- Node *first;
- } list;
- void Display_all(list *lp)
- {
- struct Node *temp;
- if (lp->first == NULL)
- {
- printf("There Are No Employee Details!!\n");
- return;
- }
- temp = lp->first;
- printf("-----------All Employee Details-----------\n");
- while (temp != NULL)
- {
- printf("Employee Name :: %s\n", temp->name);
- printf("Age :: %d\n", temp->age);
- printf("Emp Number :: %d\n", temp->emp_num);
- printf("Joining Date :: %s\n", temp->date);
- printf("Salary :: %f\n", temp->salary);
- printf("\n");
- temp = temp->next;
- }
- printf("Total Number of Employees :: %d", lp->count);
- }
- void Display_particular(list *lp)
- {
- struct Node *temp;
- int emp_num;
- if (lp->first == NULL)
- {
- printf("There Are No Employee Details!!\n");
- return;
- }
- printf("Enter the Employee number whose Deatils are to be displayed :: ");
- scanf("%d", &emp_num);
- temp = lp->first;
- while (temp != NULL)
- {
- if (temp->emp_num == emp_num)
- {
- printf("Employee Name :: %s\n", temp->name);
- printf("Age :: %d\n", temp->age);
- printf("Emp Number :: %d\n", temp->emp_num);
- printf("Joining Date :: %s\n", temp->date);
- printf("Salary :: %f\n", temp->salary);
- printf("\n");
- return;
- }
- temp = temp->next;
- }
- printf("Employee not found!!!\n");
- }
- void Delete_record(list *lp)
- {
- struct Node *temp, *prev;
- int emp_num;
- if (lp->first == NULL)
- {
- printf("There Are No Employees To be deleted!!\n");
- return;
- }
- temp = lp->first;
- printf("Enter the Employee number whose Record is to be Deleted :: ");
- scanf("%d\n", &emp_num);
- if (temp->emp_num == emp_num)
- {
- lp->first = temp->next;
- avg = ((avg*lp->count)-temp->salary)/(lp->count-1);
- free(temp);
- lp->count--;
- printf("Record Deleted Successfully!!\n");
- return;
- }
- while (temp != NULL)
- {
- if (temp->emp_num != emp_num)
- {
- prev = temp;
- temp = temp->next;
- }
- else
- {
- if (temp->next != NULL)
- {
- prev->next = temp->next;
- avg = ((avg*lp->count)-temp->salary)/(lp->count-1);
- free(temp);
- lp->count--;
- printf("Record Deleted Successfully!!\n");
- return;
- }
- else
- {
- prev->next = NULL;
- avg = ((avg*lp->count)-temp->salary)/(lp->count-1);
- free(temp);
- lp->count--;
- printf("Record Deleted Successfully!!\n");
- return;
- }
- }
- }
- printf("Employee Not Found!!!\n");
- }
- void Insert_record(list *lp)
- {
- char name[100];
- int age, emp_num;
- char date[10];
- float salary;
- printf("Enter Employee Name :: ");
- scanf("%s", name);
- printf("Enter Employee Age :: ");
- scanf("%d", &age);
- printf("Enter Employee Number :: ");
- scanf("%d", &emp_num);
- printf("Enter Date of Joining :: ");
- scanf("%s", date);
- printf("Enter Salary :: ");
- scanf("%f", &salary);
- Node *employee;
- employee = getNode();
- strcpy(employee->name, name);
- employee->age = age;
- employee->emp_num = emp_num;
- strcpy(employee->date, date);
- employee->salary = salary;
- employee->next = NULL;
- if (lp->first == NULL)
- {
- lp->first = employee;
- printf("Employee Records Inserted Successfully!!!\n");
- lp->count++;
- avg = ((avg*(lp->count-1))+employee->salary)/(lp->count);
- return;
- }
- struct Node *temp;
- temp = lp->first;
- while (temp->next != NULL)
- {
- temp = temp->next;
- }
- temp->next = employee;
- printf("Employee Records Inserted Successfully!!!\n");
- lp->count++;
- avg = ((avg*(lp->count-1))+employee->salary)/(lp->count);
- }
- void Display_salary_above_average(list *lp)
- {
- struct Node *temp;
- if (lp->first == NULL)
- {
- printf("There Are No Employee Details!!\n");
- return;
- }
- temp = lp->first;
- printf("-----------Employee Details whose Salaray is above Average-----------\n");
- while (temp != NULL)
- {
- if (temp->salary > avg)
- {
- printf("Employee Name :: %s\n", temp->name);
- printf("Age :: %d\n", temp->age);
- printf("Emp Number :: %d\n", temp->emp_num);
- printf("Joining Date :: %s\n", temp->date);
- printf("Salary :: %f\n", temp->salary);
- printf("\n");
- }
- temp = temp->next;
- }
- }
- int main()
- {
- printf("-------------EMPLOYEE MANAGEMENT SYSTEM-------------\n");
- int choice;
- list employee;
- employee.first = NULL;
- employee.count = 0;
- avg = 0.0;
- while (1)
- {
- printf("\n");
- printf("Press 1 to Display Records of all Employees\n");
- printf("Press 2 to Display Record of a particular Employee\n");
- printf("Press 3 to Delete Record of a particular\n");
- printf("Press 4 to Insert Record of a new Employee\n");
- printf("Press 5 to Display name of Employees having highest salary than average of all employees salaray\n");
- printf("Press 6 to Exit the program\n");
- printf("Enter your choice :: ");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- Display_all(&employee);
- break;
- case 2:
- Display_particular(&employee);
- break;
- case 3:
- Delete_record(&employee);
- break;
- case 4:
- Insert_record(&employee);
- break;
- case 5:
- Display_salary_above_average(&employee);
- break;
- case 6:
- exit(0);
- default:
- printf("Invaild Choice !!!\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement