Guest User

Untitled

a guest
Jan 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.73 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 = NULL;
  21.     //_head->employee = initEmployee
  22. }
  23.  
  24. int 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.     if (_head == NULL){
  38.         _head = newNode;
  39.         return 1;
  40.     }
  41.     struct Node* current;
  42.     current = (struct Node*)malloc (sizeof(struct Node));
  43.     //current = _head;
  44.    
  45.     for (current = _head; current->next!=NULL;current = current->next);
  46.     /*while(current!=NULL){
  47.         current = current->next;
  48.     }*/
  49.     current->next = newNode;
  50.    
  51.     return 1;
  52. }
  53. /*
  54. int getnode(){
  55.  
  56.  
  57. }
  58.  
  59. int removeEmployee(){
  60.  
  61.  
  62.  
  63. }*/
  64.  
  65. /*int Reapeated(struct Node* _head, int _times){
  66.    
  67.  
  68. }*/
  69.  
  70. void DeleteExpt(struct Node* _head, char _lastName[256]){
  71.     struct Node *newHead;
  72.     newHead = (struct Node*) malloc (sizeof(struct Node));
  73.    
  74.     struct Node *current;
  75.     current = (struct Node*) malloc (sizeof(struct Node));
  76.  
  77.     int count = 0;
  78.  
  79.     while(_head->next!=NULL){
  80.         if (strcmp(_head->employee.lastName, _lastName)==0 && count ==0){
  81.             newHead = _head;
  82.             newHead->next = current;
  83.             count++;
  84.         }
  85.         else if (strcmp(_head->employee.lastName, _lastName)==0){
  86.             //struct Node *temp;
  87.             //temp = (struct Node*) malloc (sizeof(struct Node));
  88.             current->next = _head;
  89.             current = current ->next;
  90.         }
  91.     }
  92.  
  93.     _head = newHead;
  94. }
  95.  
  96.  
  97. void displayList1(struct Node* _head, int _age){
  98.     struct Node* current = _head;
  99.     while(current->next !=NULL){
  100.         if (current->employee.age > _age)
  101.             //displayEmployee
  102.             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);
  103.         current = current->next;
  104.     }
  105. }
  106.  
  107. void displayList2(struct Node* _head, char _status){
  108.     struct Node* current = _head;
  109.     while(current->next !=NULL){
  110.         if (current->employee.status == _status)
  111.             //displayEmployee
  112.             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);
  113.         current = current->next;
  114.     }
  115. }
  116.  
  117.  
  118. int main (){
  119.     struct Node *head;
  120.    
  121.     head = (struct Node*) malloc (sizeof(struct Node));
  122.     head = NULL;
  123.     //initilizeList(head);
  124.  
  125.     int age;
  126.     int sinNum;
  127.     char firstName [256];
  128.     char lastName [256];
  129.     char status;
  130.  
  131.     char temp;
  132.  
  133.     for (int i =1;;i++){
  134.         printf("Enter the first name of Employee #%d. Enter 'q' to stop entering employees.\n", i);
  135.         scanf("%s%c", firstName, &temp);
  136.         printf("\n%s\n", firstName);
  137.         if (firstName == "q")
  138.             break;
  139.         printf("Enter his/her last name.\n");
  140.         scanf("%s%c", lastName, &temp);
  141.  
  142.         printf("Enter his/her age\n");
  143.         scanf("%d%c", &age, &temp);
  144.  
  145.         printf("Enter his/her SIN number\n");
  146.         scanf("%d%c", &sinNum, &temp);
  147.  
  148.         printf("Enter the status of the employee 'a' active, 's' suspended, 't' terminated.\n");
  149.         //status = getchar();
  150.         scanf("%c%c", &status, &temp);
  151.         addEmployee(head, firstName, lastName, age, sinNum, status);
  152.         displayList1(head, 0);
  153.     }
  154.  
  155.     displayList1(head, 50);
  156.     displayList2(head, 'a');
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.     return 0;
  164. }
Add Comment
Please, Sign In to add comment