Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that calculates and displays the average number of days a compan

ID: 3810865 • Letter: W

Question

Write a program that calculates and displays 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 receives no arguments.) A function called by main that takes one 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.

Explanation / Answer

C++ program (DaysOut.cpp) for above problem statement is given below. This program has 4 functions.

Sample Output:

Enter number of employees (> 1): 3
Enter number of absent days (>= 0) for employee #1: 5
Enter number of absent days (>= 0) for employee #2: 8
Enter number of absent days (>= 0) for employee #3: 0
Average number of absent days: 4.33333

File: DaysOut.cpp

#include <iostream>
using namespace std;

int getNumberOfEmployees() {
int numEmps;
  
do {
cout << "Enter number of employees (> 1): ";
cin >> numEmps;
} while (numEmps < 1);

return numEmps;
}

int getTotalNumberOfAbsentDays(int numEmps) {
int totalNumAbsentDays = 0;
int numAbsentDays;
  
for (int i = 0; i < numEmps; i++) {
do {
cout << "Enter number of absent days (>= 0) for employee #" << (i + 1) << ": ";
cin >> numAbsentDays;
} while (numAbsentDays < 0);
  
totalNumAbsentDays += numAbsentDays;
}
  
return totalNumAbsentDays;
}

double getAverageNumberOfAbsentDays(int numEmps, int totalNumAbsentDays) {
return totalNumAbsentDays * 1.0 / numEmps;
}

int main() {
int numEmps = getNumberOfEmployees();
int totalNumAbsentDays = getTotalNumberOfAbsentDays(numEmps);

cout << "Average number of absent days: " << getAverageNumberOfAbsentDays(numEmps, totalNumAbsentDays) << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote