Guest User

Untitled

a guest
Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.02 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 = _head;
  42.    
  43.     //for (; current->next!=NULL;current = current->next);
  44.     /*while(current!=NULL){
  45.         current = current->next;
  46.     }*/
  47.     //current->next = newNode;
  48.     newNode->next = *_head;
  49.     *_head = 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. void displayList(struct Node *head){
  97.     for(struct Node* current = head;current!=NULL;current=current->next)
  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.     printf("\n");
  100. }
  101.  
  102. void displayList1(struct Node* _head, int _age){
  103.     for (struct Node* current = _head;current !=NULL; current= current->next){
  104.         if (current->employee.age > _age)
  105.             //displayEmployee
  106.             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);
  107.     }
  108.     printf("\n");
  109. }
  110.  
  111. void displayList2(struct Node* _head, char _status){
  112.     struct Node* current = _head;
  113.     while(current !=NULL){
  114.         if (current->employee.status == _status)
  115.             //displayEmployee
  116.             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);
  117.         current = current->next;
  118.     }
  119.     printf("\n");
  120. }
  121.  
  122.  
  123. int main (){
  124.     struct Node *head;
  125.    
  126.     head = (struct Node*) malloc (sizeof(struct Node));
  127.     head = NULL;
  128.     //initilizeList(head);
  129.  
  130.     int age;
  131.     int sinNum;
  132.     char firstName [256];
  133.     char lastName [256];
  134.     char status;
  135.  
  136.     char temp;
  137.  
  138.     for (int i =1;;i++){
  139.         printf("Enter the first name of Employee #%d. Enter 'q' to stop entering employees.\n", i);
  140.         scanf("%s%c", firstName, &temp);
  141.         //printf("\n%s\n", firstName);
  142.         if (strcmp(firstName,"q")==0)
  143.             break;
  144.         printf("Enter his/her last name.\n");
  145.         scanf("%s%c", lastName, &temp);
  146.  
  147.         printf("Enter his/her age\n");
  148.         scanf("%d%c", &age, &temp);
  149.  
  150.         printf("Enter his/her SIN number\n");
  151.         scanf("%d%c", &sinNum, &temp);
  152.  
  153.         printf("Enter the status of the employee 'a' active, 's' suspended, 't' terminated.\n");
  154.         //status = getchar();
  155.         scanf("%c%c", &status, &temp);
  156.         addEmployee(&head, firstName, lastName, age, sinNum, status);
  157.         displayList(head);
  158.     }
  159.  
  160.     displayList1(head, 50);
  161.     displayList2(head, 'a');
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.     return 0;
  169. }
Add Comment
Please, Sign In to add comment