Question

are less there to add Write a program that all the working hours of ple employees during a weekday The program will take the
a Find and print the average of working hours for all the employees peer one day (Average employees day) Find and print the a



in d digital t o add eployees w Theron will .10) be diyowe then A her owployees of the way of your lfred Write a C++ program


Write a C++ program that calculates the working hours of multiple employees during a weekday. The program will take the last digits of your student id as the number of row employees of the array (if your last digits are less than or equal to 7 add 3 to it) and the weekdays are the column then fill the array with using random integer inputs (between 0 - 10 ) (stores the random numbers in a 2D array using both stand() and rand) functions).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to create a 2D array of working hours for employee for all week day SUN-SAT with random numbers
// between 0 and 10(exclusive) and calculate the statistics using this array

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

// function prototype
void displayEmployee(int workingHours[][7], int numEmployee, int numDays);
double average_all_employee_all_days(int workingHours[][7], int numEmployee, int numDays);
double* average_all_employee_per_day(int workingHours[][7], int numEmployee, int numDays);
double* average_all_day_per_employee(int workingHours[][7], int numEmployee, int numDays);

int main()
{
srand(time(0));
// Assuming num of employees = 8
// data for the working hours
int workingHours[8][7] ; // 8 employees and 7 weekdays SUN-SAT
// number of employee and number of days
int numEmployee = 8, numDays = 7;
// array to store the days
string days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
// loop to fill the array with random working hours between 0 and 10(exclusive)
for(int i=0;i<numEmployee;i++)
{
for(int j=0;j<numDays;j++)
{
workingHours[i][j] = rand()%10; // generates random integer between 0 and 10 (exclusive)
}
}

// display the array
displayEmployee(workingHours, numEmployee, numDays);

// get the average of all employees for all days
double avg = average_all_employee_all_days(workingHours, numEmployee, numDays);
// get the average for all days per employee
double* avg_per_emp = average_all_day_per_employee(workingHours, numEmployee, numDays);
// get the average for all employees per day
double* avg_per_day = average_all_employee_per_day(workingHours, numEmployee, numDays);

cout<<fixed<<setprecision(2);
// display the result
cout<<endl<<"Average of working hours for all employees for all weekday: "<<avg<<endl;
cout<<endl<<"Average of working hours for all employees per one day: "<<endl;
for(int i=0;i<numDays;i++)
{
cout<<days[i]<<" : "<<avg_per_day[i]<<endl;
}

cout<<endl<<"Average of working hours for all weekday per one employee: "<<endl;
for(int i=0;i<numEmployee;i++)
{
cout<<"Employee "<<(i+1)<<" : "<<avg_per_emp[i]<<endl;
}

return 0;
}

// function to display the data of the input array for given number of rows and columns
void displayEmployee(int workingHours[][7], int numEmployee, int numDays)
{
cout<<left<<setw(20)<<""<<right<<setw(5)<<"SUN"<<right<<setw(5)<<"MON"<<right<<setw(5)<<"TUE"<<right<<setw(5)<<"WED"
<<right<<setw(5)<<"THU"<<right<<setw(5)<<"FRI"<<right<<setw(5)<<"SAT"<<endl;

for(int i=0;i<numEmployee;i++)
{
cout<<right<<setw(15)<<"Employee "<<left<<setw(5)<<(i+1);

for(int j=0;j<numDays;j++)
cout<<right<<setw(5)<<workingHours[i][j];
cout<<endl;
}
}

// function to calculate the overall average of the array
double average_all_employee_all_days(int workingHours[][7], int numEmployee, int numDays)
{
double total_hours = 0; // set total hours to 0
// loop over the rows
for(int i=0;i<numEmployee;i++)
{
// loop over the columns
for(int j=0;j<numDays;j++)
{
total_hours += workingHours[i][j]; // add the entry to total_hours
}
}

return ((double)total_hours)/(numEmployee*numDays); // return the average
}

// function to calculate the average for each column
double* average_all_employee_per_day(int workingHours[][7], int numEmployee, int numDays)
{
double *avg = new double[numDays]; // create the array of size equal to numDays
// loop over the columns
for(int i=0;i<numDays;i++)
{
avg[i] = 0; // set the ith entry in avg to 0
// loop over the rows
for(int j=0;j<numEmployee;j++)
avg[i] += workingHours[j][i]; // add the (j,i) entry to avg(i)
avg[i] = avg[i]/numEmployee; // calculate the average per day
}

return avg;
}

// function to calculate the average for each row
double* average_all_day_per_employee(int workingHours[][7], int numEmployee, int numDays)
{
double *avg = new double[numEmployee]; // create the array of size equal to numEmployee
// loop over the rows
for(int i=0;i<numEmployee;i++)
{
avg[i] = 0; // set the ith entry of avg to 0
// loop over the columns
for(int j=0;j<numDays;j++)
avg[i] += workingHours[i][j]; // add the (i,j) entry to avg(i)
avg[i] = avg[i]/numDays; // calculate the average for ith employee
}

return avg;
}

//end of program

Output:

Employee 1 Employee 2 Employee 3 Employee 4 Employee 5 Employee 6 Employee 7 Employee 8 SUN MON TUE WED THU FRI SAT 1 2 2 8 6

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that calculates the working hours of multiple employees during a weekday. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".

    Project DescriptionWrite a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".Project SpecificationsInput for this project:the user must enter the number of employees in the company.the user must enter as integers for each employee:the employee number (ID)the number of days that employee missed during the past year.Input Validation:Do not accept a number less than 1 for the number of employees.Do not accept a negative...

  • Write a C program that will calculate the gross pay of a set of employees. The...

    Write a C program that will calculate the gross pay of a set of employees. The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and then outputs a table in the following format. Column alignment, leading zeros in Clock#, and zero suppression in float fields is important. Use 1.5 as the overtime pay...

  • in C language we need to find the following : EXERCISE 3: 1. Write the definition...

    in C language we need to find the following : EXERCISE 3: 1. Write the definition of a structure named employee that contains character array members for an employee's first and last names, an int member for the employee's age, a char member that contains 'M' or 'F' for the employee's gender, and a double member for the employee's hourly salary. 2. Using the above mentioned definition, write a C program that asks a user to enter the values of...

  • Please include function in this program Write a C program that will calculate the gross pay...

    Please include function in this program Write a C program that will calculate the gross pay of a set of employees utilizing pointers instead of array references. You program should continue to use all the features from past homeworks (functions, structures, constants, strings). The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and...

  • in C++ Write a program which uses the following arrays: empID: An array of 7 integers...

    in C++ Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary. The program...

  • Write a C program that deal with employees’ salaries in a company, as follows: Define an...

    Write a C program that deal with employees’ salaries in a company, as follows: Define an integer array named salaries of size 100 Initialize all array elements with zeros Fill all array elements with random numbers within a range of 350 until 3000 (all inclusive) by using built-in-function rand() and srand() Develop the following functions and call them from the main program: avgSalary(), a function that receives the array and its size as parameters and returns the average salary in...

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in...

    In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in a 9-by-9 two-dimensional array. Generate the multiplication table with two loops. (So you will have a nested loop that will iterate 9 times and fill the 9x9 array with the values.) Step 2: Display the table for the user to see it. a 9x9 table Step 3: Create a function that returns the product of two numbers between 1 and 9by looking up the...

  • C++ Linked Lists You have been hired by Employees. Inc to write an employee management system....

    C++ Linked Lists You have been hired by Employees. Inc to write an employee management system. The following are your specifications: Write a program that uses the following linked lists: bullet empId: a linked list of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 bullet hours: a linked list of seven integers to hold the number of hours worked by each employee bullet payRate:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT