Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ This exercise will provide practice in working with structs and arrays. Alth

ID: 3664576 • Letter: C

Question

C++

This exercise will provide practice in working with structs and arrays. Although there might be many ways of doing the assignment, it must be done exactly as specified here (for pur- poses of practice). Write a program that will record information about employees and com- pute their paychecks. Each employee must be represented by a struct containing the last name of the employee, the hours worked each day of the week, the hourly rate, and the pay for that week. The “hours worked each day of the week” must be an array storing five values for the hours from Monday to Friday. (The company is not open on Saturday or Sunday.) Therefore, this array will be inside the struct. There will also be an array of all the employees (an array of structs). There must be at least four employees. The array of structs must be declared in the main function of the program. Then the en- tire array must be passed to a function called “initialize”, which will ask the user to enter val- ues for every part of every struct, except for the pay for that week (which will be computed in a different function). A loop for processing the array of employees must be set up in the main function. In- side the loop, a single employee will be passed into a function called “compute”, which will calculate the paycheck for that employee. If the employee worked longer than 40 hours, overtime pay of 1.5 times the hourly rate is to be used for each hour worked over the 40 hours. For example, an employee who works a total of 50 hours for $10.00 an hour would make $550. Do not pass the entire array of employees into the “compute” function; the em- ployees will be passed, one at a time, into the “compute” function until all of their pay- checks have been calculated, at which time the loop will terminate. The employee will need to be passed by reference. A single employee must be passed into the “result” function, which will output the last name of the employee and the amount of the paycheck for that employee. Do not pass the entire array of employees into the “result” function. Each employee must be passed through call by value, one at a time, until all the paycheck amounts have been output, at which time the loop (in the main function) will terminate. Then the program will end.

Explanation / Answer

#include <iostream>
using namespace std;
struct emp
{
char lname[20];
int hours[5],rate,pay;
};
void initilize(emp *ei)
{
cout<<" Enter last name : ";
cin>>ei->lname;
cout<<" Enter Hourly rate : ";
cin>>ei->rate;
for(int j=1;j<=5;j++)
{
cout<<" Enter hours for day"<<j<<" : ";
cin>>ei->hours[j];
}
}
void compute(struct emp *ec)
{
int time=0;
for(int j=1;j<=5;j++)
{
time=time+ec->hours[j];
}
if(time>40)
{
ec->pay=(ec->rate*40)+((time-40)*ec->rate*1.5);
}
else
{
ec->pay=time*(ec->rate);
}
}
void result(emp er)
{
cout<<" Last Name : "<<er.lname;
cout<<" Pay check : "<<er.pay;
}
int main()
{
int i,no;
cout<<"Enter No. of employee to enter data: ";
cin>>no;
emp e[no];
for(i=0;i<no;i++)
{
initilize(&e[i]);
}
for(i=0;i<no;i++)
{
compute(&e[i]);
}
for(i=0;i<no;i++)
{
result(e[i]);
}
   return 0;
}

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