Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. /*1- Create a structure named Employee. Include data fields to hold the Employee's ID number, first name, last name, and hourly pay rate.
  2. Create an array of five Employee structures. Prompt the user to enter data for each Employee. Do not allow duplicate ID numbers to be entered.
  3. Then prompt the user to choose whether to search for an Employee by (1) ID number, (2) last name, or (3) hourly pay. After the user chooses the field on
  4. which to search, prompt the user for the search value. Display an error message if there is no Employee with matching criteria, otherwise display all the
  5. data for every matching Employee (more than one Employee might have the same last name or pay rate).*/
  6.  
  7. #include<stdio.h>
  8. #include <string.h>
  9. //const or macro for EMPLOYEES = 5
  10.  
  11. struct Employee {
  12. int ID;
  13. char firstName[100];
  14. char lastName[100];
  15. float hourlyRate;
  16. };
  17.  
  18. bool isInIDS (int _IDS [5], int _id) {
  19. for (int i = 0; i < 5;i++)
  20. if (_IDS[i] == _id)
  21. return true;
  22. return false;
  23. }
  24.  
  25. void getInfo(struct Employee _employee[5], int _IDS [5]){
  26. for(int i = 0;i<5;i++){
  27. printf("Enter the employees first name:");
  28. scanf("%s", _employee[i].firstName);
  29. printf("Enter %s's last name: ", _employee[i].firstName);
  30. scanf("%s", _employee[i].lastName);
  31.  
  32. do {
  33. printf("Enter %s, %s's ID number:", _employee[i].firstName, _employee[i].lastName);
  34. scanf("%d", &_employee[i].ID);
  35. if (isInIDS(_IDS, _employee[i].ID))
  36. printf("*Id is already in use*\n");
  37. }while (isInIDS(_IDS, _employee[i].ID));
  38. _IDS[i] = _employee[i].ID;
  39.  
  40. printf("Enter %s, %s's hourly pay:$", _employee[i].firstName, _employee[i].lastName);
  41. scanf("%f", &_employee[i].hourlyRate);
  42. printf("------------------------------\n");
  43. }
  44. }
  45.  
  46. void printEmployee (struct Employee employee){
  47. printf("First Name\tLast Name\tID\tHourly Pay\n");
  48. printf("%10s\t%9s\t%d\t%.2f\n", employee.firstName, employee.lastName, employee.ID, employee.hourlyRate);
  49. }
  50.  
  51. void searchEmployees (struct Employee employee[5], int option){
  52. int hourlyRate;
  53. char lastName[100];
  54. int ID;
  55. printf("Enter keyword to search for\n");
  56. if (option == 1){
  57. scanf("%d", &ID);
  58. for (int i = 0; i < 5;i++){
  59. if (employee[i].ID == ID)
  60. printEmployee(employee[i]);
  61. }
  62. }
  63. else if (option ==2){
  64. scanf("%s", lastName);
  65. for (int i = 0; i < 5;i++){
  66. if (strcmp(employee[i].lastName, lastName)==0)
  67. printEmployee(employee[i]);
  68. }
  69.  
  70. }
  71. else if (option ==3){
  72. scanf("%d", &hourlyRate);
  73. for (int i = 0; i < 5;i++){
  74. if (employee[i].hourlyRate == hourlyRate)
  75. printEmployee(employee[i]);
  76. }
  77. }
  78.  
  79.  
  80.  
  81. }
  82.  
  83. int main(){
  84. int IDList [5];
  85. int option;
  86. struct Employee employees[5];
  87. //getInfo(employees, IDList);
  88.  
  89. strcpy(employees[0].firstName, "John");
  90. strcpy(employees[0].lastName, "Smith");
  91. employees[0].ID = 0001;
  92. employees[0].hourlyRate = 12.00;
  93.  
  94. strcpy(employees[1].firstName, "Jimmy");
  95. strcpy(employees[1].lastName, "Crackcorn");
  96. employees[1].ID = 0002;
  97. employees[1].hourlyRate = 12.00;
  98.  
  99. strcpy(employees[2].firstName, "John");
  100. strcpy(employees[2].lastName, "Scott");
  101. employees[2].ID = 0003;
  102. employees[2].hourlyRate = 22.00;
  103.  
  104. strcpy(employees[3].firstName, "Jimmy");
  105. strcpy(employees[3].lastName, "Smith");
  106. employees[3].ID = 0004;
  107. employees[3].hourlyRate = 22.00;
  108.  
  109. strcpy(employees[4].firstName, "Cody");
  110. strcpy(employees[4].lastName, "Scott");
  111. employees[4].ID = 0005;
  112. employees[4].hourlyRate = 32.00;
  113.  
  114. printf("Select an option to search for an employee\n");
  115. printf("1\t-\tID number\n2\t-\tLast name\n3\t-\tHourly Pay\n");
  116. scanf("%d", &option);
  117. searchEmployees(employees, option);
  118.  
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement