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

C++ PROGRAMMING Days Out Write a program that calculates the average number of d

ID: 3811638 • Letter: C

Question

C++ PROGRAMMING

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 that asks the user for the number of employees in the company. This value should be passed by reference to the function.
Function prototype: void GetNumEmployees(int&);
• A function 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. Keep track of the total number of days missed. This value should be returned as an int.
(Hint: You will need a for loop)
Function prototype: int TotalDaysMissed(int);
• A function that takes two arguments: the number of employees in the company and the total number of days absent for all employees in the company during the year. The function should return, as a float, the average number of days absent. (No output or user input)
Function prototype: float AverageDaysMissed(int,int);
Input validation:
• Do not accept a number less than 1.
• Do not accept a negative number for the days missed.

Function Definitions:
a) GetNumEmployees
b) TotalDaysMissed
c) AverageDaysMissed

Explanation / Answer

// C++ code

#include <iostream>
using namespace std;

int GetNumEmployees(int*);
int TotalDaysMissed(int);
double AverageDaysMissed(int,int);

int main()
{
int totalEmployee = 0;
int totalMissedDays = 0;
double avgDayMissed = 0.0;
GetNumEmployees(&totalEmployee);
totalMissedDays=TotalDaysMissed(totalEmployee);
avgDayMissed=AverageDaysMissed(totalEmployee,totalMissedDays);
cout << "Average employee absent days last year: "<<endl<< avgDayMissed;
cout<<endl;
return 0;
}

int GetNumEmployees(int *totalEmployee)
{

   cout << "Enter # of Employees"<<endl;
   cin >> *totalEmployee;

   while(*totalEmployee < 1)
   {
   cout << "INVALID, # of employees must be > 1.";
   cout << "Enter # of Employees: ";
   cin >> *totalEmployee;
   }
}

int TotalDaysMissed(int totalEmployee)
{
   int totalMissed;
   int TotalDaysMissed=0;

   for(int i = 0; i < totalEmployee; i++)
   {
       while(true)
       {
           cout << "Enter no. of Days "<<i+1<<" employee missed last year: ";
           cin >> totalMissed;

           if(totalMissed >= 0 )
               break;
           else
               cout << "Invalid Input ";
       }
       TotalDaysMissed+=totalMissed;
   }

   return TotalDaysMissed;
}

double AverageDaysMissed(int totalEmployee, int totalMissedDays)
{
   double avgDayMissed;

   avgDayMissed = (totalMissedDays*1.0)/totalEmployee;
   return avgDayMissed;

}


/*
output:

Enter # of Employees
4
Enter no. of Days 1 employee missed last year: 56
Enter no. of Days 2 employee missed last year: 54
Enter no. of Days 3 employee missed last year: 33
Enter no. of Days 4 employee missed last year: 23
Average employee absent days last year:
41.5


*/

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