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: 3641940 • 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: 1) A function that asks the user for the number of employees in the company. (no parameters, returns an int). 2) A function that asks the user to enter the number of days each employee missed during the past year. (1 parameter for number of employees, returns total of days missed for all employees) 3) A function to calculate the average number of days absent (2 int parameters: number of employees and number of days, returns float storing average number of days missed.) Your program should not accept negative numbers as input: use loops to ensure this.

To get full credit you must follow the instructions on how each function should be organized.

Program output:

Test Case 1:

How many employess does the company have?
Days missed by Employee #1?
Days missed by Employee #2?
Days missed by Employee #3?
The average number of days missed per employee is 1.

Test Case 2:

How many employess does the company have?
Number of employees must be one or greater.
How many employess does the company have?
Number of employees must be one or greater.
How many employess does the company have?
Days missed by Employee #1?
Days missed by Employee #2?
Days missed by Employee #3?
Days missed by Employee #4?
The average number of days missed per employee is 11.5.

Test Case 3:

How many employess does the company have?
Number of employees must be one or greater.
How many employess does the company have?
Days missed by Employee #1?
Days missed by Employee #2?
Days missed by Employee #3?
Days missed by Employee #4?
Days missed by Employee #5?
The average number of days missed per employee is 3.

Test Case 4:

How many employess does the company have?
Days missed by Employee #1?
Days missed by Employee #2?
Days missed must be zero or greater.
Days missed by Employee #2?
Days missed by Employee #3?
Days missed must be zero or greater.
Days missed by Employee #3?
The average number of days missed per employee is 1.

Test Case 5:

How many employess does the company have?
Days missed by Employee #1?
Days missed by Employee #2?
Days missed by Employee #3?
Days missed by Employee #4?
Days missed by Employee #5?
Days missed by Employee #6?
Days missed by Employee #7?
Days missed by Employee #8?
Days missed by Employee #9?
Days missed by Employee #10?
The average number of days missed per employee is 0.

Test Case 6:

How many employess does the company have?
Number of employees must be one or greater.
How many employess does the company have?
Days missed by Employee #1?
Days missed must be zero or greater.
Days missed by Employee #1?
Days missed by Employee #2?
Days missed must be zero or greater.
Days missed by Employee #2?
Days missed by Employee #3?
Days missed must be zero or greater.
Days missed by Employee #3?
The average number of days missed per employee is 5.66667.

I have:


#include <iostream>
#include <iomanip>
using namespace std;
int numOfWorkers()
{
// to store user input
int num;
cout << "How many employess does the company have?" << endl;
cin >> num;
if(num<1)
{
cout << "you have to enter at least one "<< endl;
cout << "Try again" << endl;
//if user enters a value we cannot accept we call our function again, the 0 + is just to make sure no garbage follows
return 0 + numOfWorkers();
}
//return number of workers
return num;
}
int missedDayes(int num)
{
// total is the number of total days missed
int total=0;
//temp is to hold user input
int temp;
//i is the iterator in the do while loop
int i = 0;
do
{
cout << "Days missed by Employee #" << i+1 << endl;
cin >> temp;
if(temp<0)
{
//if user enters a value we cannot accept we alert the user that values are not allowed and ask again
cout << "you can not enter negative values" << endl;
cout << "Try again" << endl;
}
else
{
//if values are ok we store them in our total integer and increment our iterator
total +=temp;
i++;
}
}while(i!=num);
//return our total
return total;
}

double averageNumberOfDaysAbsent(int num,int total)
{
//self explanatory, except we cast to double to make sure we get the float out
return (double) total/num;
}

int main()
{
//function returns an integer
int num = numOfWorkers();
//functions takes in an integer and returns another integer
int miss = missedDayes(num);
//function takes in two integers and returns a double number
double av = averageNumberOfDaysAbsent(num,miss);
//format the output with setprecision, thats wy we need the iomanip
cout << "The average number of days missed per employee is " <<setprecision(4) <<av << endl;
//if you are using visual studio this pause the screen and waits for you to enter a button
//remove if you are using another ide or linux/mac
system("pause");
return 0;
}

-- I am given the error "E: empBACF.tmpemployee.cpp:5:1: error: expected initializer before 'int'"

Explanation / Answer

I hate how cramster will removed my hard work by removing the indentation in my code, but anyway, here goes the code. #include #include // -----------------> necessary for using the system("pause"); function #include using namespace std; int NumOfEmployees() { int numWorkers; cout > numWorkers; while (numWorkers
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