Answer to Question #265399 in C++ for btw

Question #265399

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. 

- 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. 


Input Validation: Do not accept a number less than 1 for number of employees. Do not accept a negative  number for the days any employee missed. 




1
Expert's answer
2021-11-13T05:43:46-0500
#include<iostream>
using namespace std;

int AskNumEmp();
int AskMissDay(int EmplCount);
double AverageAbs(int EmplCount, int MissDays);

int main()
{
	int EmplCount = AskNumEmp();
	int MissDays = AskMissDay(EmplCount);
	cout << "\nThe average  number of days absent is "
		<< AverageAbs(EmplCount, MissDays);
}

int AskNumEmp()
{
	int num;
	do
	{
		cout << "Please, enter the number of employees in company: ";
		cin >> num;
		if (num < 1)cout << "Incorrect number. Retry enter!\n";
	} while (num < 1);
	return num;
}

int AskMissDay(int EmplCount)
{
	int totalMiss = 0;
	for (int i = 1; i <= EmplCount; i++)
	{
		int days;
		do
		{
			cout << "Enter the number of missed days during the past year for\n"
				<< "Employee " << i << ": ";
			cin >> days;
			if (days < 0)
			{
				cout << "Incorrect missed days. Retry enter!\n";
			}
			else
			{
				totalMiss += days;
			}		
		} while (days < 0);	
	}
	return totalMiss;
}

double AverageAbs(int EmplCount, int MissDays)
{
	double AvDays =(double) MissDays / EmplCount;
	return AvDays;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS