Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. FILE *empinfo;
  4.  
  5. struct employeeData {
  6.     int EMP_ID;
  7.     char name[20];
  8.     int dept;
  9.     int rank;
  10.     double salary;
  11.     struct employeeData *next;
  12. };
  13.  
  14. struct employeeData *head = NULL;
  15.  
  16. void initializeList();
  17. void add();
  18. void deleteEmp(int ID);
  19. void modify(int ID, double NewSalary);
  20. void query(int rank);
  21. void print();
  22.  
  23. void main(){
  24.  
  25.     int choice=1, ID, rank;
  26.     double newSalary;
  27.  
  28.     initializeList();
  29.  
  30.     while (choice != 0) {
  31.         printf("1-Add 2-Delete 3-Modify 4-Query 5-Print 0-Exit\n");
  32.         scanf("%d", &choice);
  33.  
  34.         if (choice == 1) {
  35.             add();
  36.         }
  37.         else if (choice == 2){
  38.             printf("Enter employee ID to delete: ");
  39.             scanf("%d", &ID);
  40.             deleteEmp(ID);
  41.         }
  42.         else if (choice == 3){
  43.             printf("Enter employee ID to modify: ");
  44.             scanf("%d", &ID);
  45.             printf("Enter new salary amount: ");
  46.             scanf("%lf", &newSalary);
  47.             modify(ID,newSalary);
  48.         }
  49.         else if (choice == 4){
  50.             printf("Enter the rank you wish to query: ");
  51.             scanf("%d", &rank);
  52.             query(rank);
  53.         }
  54.         else if (choice == 5){
  55.             print();
  56.         }
  57.     }
  58.     printf("Goodbye...\n");
  59.     return;
  60. }
  61.  
  62. void initializeList(){
  63.     head = NULL;
  64.     empinfo=fopen("empinfo.txt", "r");
  65.     head = (struct employeeData *)malloc(sizeof(struct employeeData));
  66.     head->next = NULL;
  67.  
  68.     struct employeeData *tempPtr = head;
  69.  
  70.     while (tempPtr->EMP_ID != 0){
  71.         fscanf(empinfo, "%d %s %d %d %lf", &tempPtr->EMP_ID, &tempPtr->name, &tempPtr->dept, &tempPtr->rank, &tempPtr->salary);
  72.         printf("%d %s %d %d %lf\n", tempPtr->EMP_ID, tempPtr->name, tempPtr->dept, tempPtr->rank, tempPtr->salary);
  73.         if (tempPtr->EMP_ID == 0){
  74.             free(tempPtr);
  75.             break;
  76.             }
  77.         tempPtr->next = (struct employeeData *)malloc(sizeof(struct employeeData));
  78.         tempPtr=tempPtr->next;    
  79.     }
  80. }
  81.  
  82. void add(){
  83. }
  84. void deleteEmp(int ID){
  85. }
  86. void modify(int ID, double NewSalary){
  87. }
  88. void query(int rank){
  89. }
  90. void print(){
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement