Table Chart Text Shape Media Comment Project 5/Number of Days Absent Design, imp
ID: 3915707 • Letter: T
Question
Table Chart Text Shape Media Comment Project 5/Number of Days Absent Design, implement and test a C++ program which will- Calculate the average number of missing (absent) days for a company's employees during a year Requirements/Approach C++ functions MUST BE implemented. DO NOT implement everything (all of the logies) in main(). In addition to main(), implement three other functions - A function which will ask user for the total number of employee. This value must be returned as an integer. The function does not need to accept any (input) argument . o Here is a sample prototype: int total employeeso: " Another function which will: o accept one argument: the total number of employees o ask the user to enter the following info for each employee: the respective employee number (ID) employee number (ID) should be in the range of 1 and 9999 the number of days that the employee missed during the past year " Days should be between 0 and 365. No need to worry about a leap year " repeat this step for all employees o return the total missed days of all employees as an integer value o A 3rd function which will calculate average number of days absent of all employees o o accept two input arguments: o total number of employees o total number of days absent for all employees during the year o retum, as a double, the average number of days absent. o If additional functions are required, students may include them (if nceded) o See sample screenshots from last semester to understand output expectations 669Explanation / Answer
Program plan:
As mentioned above the program contains three functions apart from main.
int total_employee():which returns the no of employee in the company.
collectdata(totalemployeesno):function takes the totla no of employee and collects the data of employee id and absent days.
calcavg():this function calculates the average of employee absent days.
Program:
#include<iostream.h>
#include<conio.h>
//declaration of all the functions
int total_employee();
int collectdata(int tot_emp);
double calcavg(int tot_emp,int tot_absentdays);
//main method definition
void main()
{
int total_emp,absentdays;
double AVG;
clrscr();
//calling total_employee funtion
total_emp=total_employee();
absentdays=collectdata(total_emp);//store the value of total absent days
AVG=calcavg(total_emp,absentdays);
//AVG is the variable stores the average value.print the value
cout<<" The average absent days of all Employees: "<<AVG;
getch();
}
//main ends
//other function definitions
//total_employee() definition
int total_employee()
{
int n;
cout<<"Enter total no of employees: ";
cin>>n;
return n;
}
//collecting the employee data
int collectdata(int tot_emp)
{
int i,eid,ab_days;
int total_absent_days=0; //stores the total absent days info
for(i=1;i<=tot_emp;++i)
{
cout<<"enter employee Id(ranges 1 to 9999):";
cin>>eid;
cout<<"enter employee no of absent days:(0 to 365)";
cin>>ab_days;
//adding the absent days to total absent days.
total_absent_days=total_absent_days+ab_days;
}
return total_absent_days;
}
//function definition to calculate the average
double calcavg(int tot_emp,int tot_absentdays)
{
//to calculate avgabsent info divide total absentdays by total emp
return (double(tot_absentdays/tot_emp));
}
Sample output:
enter no of employee : 5
enter employee id(1 to 9999):25
enter employee absent days(0 to 365):21
enter employee id(1 to 9999):5
enter employee absent days(0 to 365):14
enter employee id(1 to 9999):65
enter employee absent days(0 to 365):60
enter employee id(1 to 9999):734
enter employee absent days(0 to 365):10
enter employee id(1 to 9999):87
enter employee absent days(0 to 365):17
the average absent days:24.5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.