Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. /* "(1)Days Out
  2. Write a program that calculates the average number of days a company s employees
  3. are absent. The program should have the following functions:
  4. * A function called by main that asks the user for the number of employees in the
  5. company. This value should be returned as an int. (The function accepts no
  6. arguments.)
  7. * A function called by main that accepts one argument: the number of employees in
  8. the company. The function should ask the user to enter the number of days each
  9. employee missed during the past year. The total of these days should be returned
  10. as an int.
  11. * A function called by main that takes two arguments: the number of employees in
  12. the company and the total number of days absent for all employees during the
  13. year. The function should return, as a double, the average number of days
  14. absent. (This function does not perform screen output and does not ask the user
  15. for input.)
  16. Input Validation: Do not accept a number less than 1 for the number of employees.
  17. Do not accept a negative number for the days any employee missed." */
  18.  
  19. #include <iostream>
  20.  
  21. using namespace std;
  22.  
  23. int inputNumberEmployees();
  24. int inputMissedDayNumber(int employees_number);
  25. double calculateAverageMissedDaysNumber(int emplotees_number, int total_missed_day);
  26.  
  27. int main()
  28. {
  29. int number_of_employees = inputNumberEmployees();
  30. int number_missed_day = inputMissedDayNumber(number_of_employees);
  31. double average_number_day_absent = calculateAverageMissedDaysNumber(number_of_employees, number_missed_day);
  32. cout << "\nThe average number of days a company's employees are absent: " << average_number_day_absent << endl;
  33. return 0;
  34. }
  35.  
  36. int inputNumberEmployees()
  37. {
  38. int employees_number;
  39. bool valid_input = true;
  40. do {
  41. cout << "Enter the number of employees in the company: ";
  42. cin >> employees_number;
  43. if (employees_number <= 1)
  44. {
  45. cout << "\nError: number of employees in the company must be > 1!\n";
  46. valid_input = false;
  47. }
  48. else valid_input = true;
  49. } while (!valid_input);
  50. return employees_number;
  51. }
  52.  
  53. int inputMissedDayNumber(int employees_number)
  54. {
  55. bool valid_input = true;
  56. int missed_day_number = 0, total_missed_day = 0;
  57. cout << "\nEnter the number of days each employee missed during the past year\n";
  58. for (int i = 1; i <= employees_number; i++)
  59. {
  60. do {
  61. cout << "\n\t"<< i << " employee missed day(s): ";
  62. cin >> missed_day_number;
  63. if (missed_day_number < 0)
  64. {
  65. cout << "\nError: number for the days any employee missed must be positive\n";
  66. valid_input = false;
  67. }
  68. else valid_input = true;
  69. } while (!valid_input);
  70. total_missed_day += missed_day_number;
  71. }
  72. return total_missed_day;
  73. }
  74.  
  75. double calculateAverageMissedDaysNumber(int emplotees_number, int total_missed_day)
  76. {
  77. double average_missed_day_number;
  78. average_missed_day_number = (double)total_missed_day / emplotees_number;
  79. return average_missed_day_number;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement