3. Write a program that calculates the average number of days a company employee
ID: 3702584 • Letter: 3
Question
3. Write a program that calculates the average number of days a company employee is absent. The program should have the following three methods: .A method that asks the user for number of employees in the company This value should be returned as an int type value. The method accepts no arguments. A method that accepts one argument: the number of employees in the company. The method 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 int type. (you need to use a loop to find this total) A method that accepts two arguments: The number of employees in the company and the total number of days absent for all employees during the past year. The method should return, as double type, the average number of days absent. (This method does not perform screen output and does not ask the user for input). . Use appropriate description phrases with the outputExplanation / Answer
Here by i have added the code for three methods As well as the description is added as comment line in the source code.
#include <iostream>
using namespace std;
int numberofEmployees();
int numberofDays(int);
double averageDays(int, int);
int main()
{
int employees;
int total;
double average;
//Function call for function
employees = numberofEmployees();
total = numberofDays(employees);
average = averageDays(employees, total);
//Displaying output by main function
cout<< "The average number of days a company's employees are absent is: " <<average<<endl;
return 0;
}
int numberofEmployees()
{
int workers;
cout<<"Enter the number of employees in the company: ";
cin>>workers;
//validating the Input
if(workers<=1)
{
cout<<" Do not accept number less than 1. Please, enter again: ";
cin>>workers;
}
return workers;
}
//Function for number of days
int numberofDays(int w)
{
int workers = w;
int total = 0;
int abnt;
//loop for every employees' missed days
for (int count=0; count<workers; count++)
{
cout <<"Enter the number of days each employee missed during past year: "<<count+1<<endl;
cin >>abnt;
total+=abnt;
//validating the Input
if (abnt<0)
{
cout<<"Please, do not enter numbers in negative";
cin>>abnt;
}
}
return total;
}
//Function for average number of days absent
double averageDays (int work, int totl)
{
int w = work;
int t = totl;
double avg;
avg=(w*365)/t;
return avg;
}
output
*******
Enter the number of employees in the company: 5
Enter the number of days each employee missed during past year: 1
3
Enter the number of days each employee missed during past year: 2
5
Enter the number of days each employee missed during past year: 3
7
Enter the number of days each employee missed during past year: 4
7
Enter the number of days each employee missed during past year: 5
7
The average number of days a company's employees are absent is: 62
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.