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

Write a program that calculates the average number of days a company\'s employee

ID: 643555 • Letter: W

Question

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.

Explanation / Answer

#include <iostream>
using namespace std;

int numEmployees();
int GetdaysMissed(int x[], int n);
float averageMissingDays(int x[], int n);

void main()
{
int employees;
employees = numEmployees();
int *days=new int[employees]; // You need an array to store all the employees missing days as
// as you want to use in the next function that calculates average

GetdaysMissed(int x, employees);

cout<<averageMissingDays(days, employees)<<endl;
}

This function you written correctly.

int numEmployees()
{
int x;
do {
cout << "Please enter the number of people the company employs: ";
cin >> x;
}while (x < 0);

return (x);
}

This is partially correct

void GetdaysMissed(int x, int n)
{
for(int i = 0; i< n; i++)
{
int days;
do {
cout << "Please enter the days employee number " << i << " has missed: ";
cin >> days; }
while (days < 0);
x[i]=days;
}
}

float averageMissingDays(int x[], int n)
{
float s=0;
for(int i=0;i<n;i++) s+=x[i];
return s/n;
}

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