Guest User

Untitled

a guest
Jan 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.47 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct Employee{
  6.     char firstName[256];
  7.     char lastName[256];
  8.     int age;
  9.     int sinNumber;
  10.     char status;
  11. };
  12.  
  13. struct Node{
  14.     struct Employee employee;
  15.     struct Node *next;
  16. };
  17.  
  18. void initilizeList(struct Node* _head){
  19.     _head = (struct Node*) malloc(sizeof(struct Node));
  20.     //_head->employee = initEmployee
  21.  
  22. }
  23.  
  24. void addEmployee(struct Node* _head, char _firstName[256], char _lastName[256], int _age, int _sinNum, char _status){
  25.     struct Node *newNode;
  26.     newNode = (struct Node*)malloc (sizeof(struct Node));
  27.     newNode->next =NULL;
  28.  
  29.     //initilizes the new node with the employee data
  30.     strcpy(newNode->employee.firstName, _firstName);
  31.     strcpy(newNode->employee.lastName, _lastName);
  32.     newNode->employee.age = _age;
  33.     newNode->employee.sinNumber = _sinNum;
  34.     newNode->employee.status = _status;
  35.  
  36.     //tranverse to the end of the list
  37.     struct Node* current;
  38.     current = (struct Node*)malloc (sizeof(struct Node));
  39.     //current = _head;
  40.    
  41.     for (current = _head; current!=NULL;current = current->next);
  42.     /*while(current!=NULL){
  43.         current = current->next;
  44.     }*/
  45.     current = newNode;
  46.    
  47.  
  48. }
  49. /*
  50. int getnode(){
  51.  
  52.  
  53. }
  54.  
  55. int removeEmployee(){
  56.  
  57.  
  58.  
  59. }
  60.  
  61. int Reapeated(){
  62.  
  63.  
  64. }
  65. */
  66. void DeleteExpt(struct Node* _head, char _lastName[256]){
  67.     struct Node *newHead;
  68.     newHead = (struct Node*) malloc (sizeof(struct Node));
  69.    
  70.     struct Node *current;
  71.     current = (struct Node*) malloc (sizeof(struct Node));
  72.  
  73.     int count = 0;
  74.  
  75.     while(_head->next!=NULL){
  76.         if (strcmp(_head->employee.lastName, _lastName)==0 && count ==0){
  77.             newHead = _head;
  78.             newHead->next = current;
  79.             count++;
  80.         }
  81.         else if (strcmp(_head->employee.lastName, _lastName)==0){
  82.             //struct Node *temp;
  83.             //temp = (struct Node*) malloc (sizeof(struct Node));
  84.             current->next = _head;
  85.             current = current ->next;
  86.         }
  87.     }
  88.  
  89.     _head = newHead;
  90. }
  91.  
  92.  
  93. void displayList1(struct Node* _head, int _age){
  94.     struct Node* current = _head;
  95.     while(current->next !=NULL){
  96.         if (current->employee.age > _age)
  97.             //displayEmployee
  98.             printf("%s, %s\n%d\n%d\n%c\n", current->employee.lastName, current->employee.firstName, current->employee.age, current->employee.sinNumber, current->employee.status);
  99.         current = current->next;
  100.     }
  101. }
  102.  
  103. void displayList2(struct Node* _head, char _status){
  104.     struct Node* current = _head;
  105.     while(current->next !=NULL){
  106.         if (current->employee.status == _status)
  107.             //displayEmployee
  108.             printf("%s, %s\n%d\n%d\n%c\n", current->employee.lastName, current->employee.firstName, current->employee.age, current->employee.sinNumber, current->employee.status);
  109.         current = current->next;
  110.     }
  111. }
  112.  
  113.  
  114. int main (){
  115.     struct Node *head;
  116.    
  117.     head = (struct Node*) malloc (sizeof(struct Node));
  118.     //initilizeList(head);
  119.  
  120.     int age;
  121.     int sinNum;
  122.     char firstName [256];
  123.     char lastName [256];
  124.     char status;
  125.  
  126.     for (int i =1;;i++){
  127.         printf("Enter the first name of Employee #%d. Enter 'q' to stop entering employees.\n", i);
  128.         scanf("%s", firstName);
  129.         if (firstName == "q")
  130.             break;
  131.         printf("Enter his/her last name.\n");
  132.         scanf("%s", lastName);
  133.  
  134.         printf("Enter his/her age\n");
  135.         scanf("%d", &age);
  136.  
  137.         printf("Enter his/her SIN number\n");
  138.         scanf("%d", &sinNum);
  139.  
  140.         printf("Enter the status of the employee 'a' active, 's' suspended, 't' terminated.\n");
  141.         //status = getchar();
  142.         scanf("%c", &status);
  143.         addEmployee(head, firstName, lastName, age, sinNum, status);       
  144.     }
  145.  
  146.     displayList1(head, 50);
  147.     displayList2(head, 'a');
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.     return 0;
  155. }
Add Comment
Please, Sign In to add comment