Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* "(1)Days Out
- Write a program that calculates the average number of days a company s employees
- are absent. The program should have the following functions:
- * A function called by main that asks the user for the number of employees in the
- company. This value should be returned as an int. (The function accepts no
- arguments.)
- * A function called by main that accepts one argument: the number of employees in
- the company. The function should ask the user to enter the number of days each
- employee missed during the past year. The total of these days should be returned
- as an int.
- * A function called by main that takes two arguments: the number of employees in
- the company and the total number of days absent for all employees during the
- year. The function should return, as a double, the average number of days
- absent. (This function does not perform screen output and does not ask the user
- for input.)
- Input Validation: Do not accept a number less than 1 for the number of employees.
- Do not accept a negative number for the days any employee missed." */
- #include <iostream>
- using namespace std;
- int inputNumberEmployees();
- int inputMissedDayNumber(int employees_number);
- double calculateAverageMissedDaysNumber(int emplotees_number, int total_missed_day);
- int main()
- {
- int number_of_employees = inputNumberEmployees();
- int number_missed_day = inputMissedDayNumber(number_of_employees);
- double average_number_day_absent = calculateAverageMissedDaysNumber(number_of_employees, number_missed_day);
- cout << "\nThe average number of days a company's employees are absent: " << average_number_day_absent << endl;
- return 0;
- }
- int inputNumberEmployees()
- {
- int employees_number;
- bool valid_input = true;
- do {
- cout << "Enter the number of employees in the company: ";
- cin >> employees_number;
- if (employees_number <= 1)
- {
- cout << "\nError: number of employees in the company must be > 1!\n";
- valid_input = false;
- }
- else valid_input = true;
- } while (!valid_input);
- return employees_number;
- }
- int inputMissedDayNumber(int employees_number)
- {
- bool valid_input = true;
- int missed_day_number = 0, total_missed_day = 0;
- cout << "\nEnter the number of days each employee missed during the past year\n";
- for (int i = 1; i <= employees_number; i++)
- {
- do {
- cout << "\n\t"<< i << " employee missed day(s): ";
- cin >> missed_day_number;
- if (missed_day_number < 0)
- {
- cout << "\nError: number for the days any employee missed must be positive\n";
- valid_input = false;
- }
- else valid_input = true;
- } while (!valid_input);
- total_missed_day += missed_day_number;
- }
- return total_missed_day;
- }
- double calculateAverageMissedDaysNumber(int emplotees_number, int total_missed_day)
- {
- double average_missed_day_number;
- average_missed_day_number = (double)total_missed_day / emplotees_number;
- return average_missed_day_number;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement