use simple programming techniques learned in programming 1! use a loop to ensure
ID: 3715973 • Letter: U
Question
use simple programming techniques learned in programming 1! use a loop to ensure the user enters the correct number of digits
Programming Assignment: Payroll Write a C++ program that calculates the weekly payroll for five employees. Your program should ask the user to enter the following data for each employee: Employee ID Hours worked . Hourly pay rate Your program should then calculate the gross pay for each employee and display the following output to the screen: .Employee ID . Hours worked Hourly pay rate Gross pay Arrays and Global Constants Your program should contain four arrays and two global constants which are described in the following Name NUMBER OF EMPLOYEES EMPLOYEE ID LENGTH Description Global constant. Value e Global constant value equals a tring array. Size equals NUMBER OF EMPLOYEES Double array. Size Double array Size equa s NUMBER OF EMPLOYEES Double array. Size equals NUMBER OF EMPLOYEES hoursWorked S NUMBER OF EMPLOYEES 5 6 Y U CV B NExplanation / Answer
#include<iostream>
#include<string>
#include <iomanip>
#define NUMBER_OF_EMPLOYEES 5
#define EMPLOYEE_ID_LENGTH 4
using namespace std;
class Employee
{
public:string employeeID[NUMBER_OF_EMPLOYEES];
public:double hoursWorked[NUMBER_OF_EMPLOYEES];
public:double payRate[NUMBER_OF_EMPLOYEES];
public:double grossPay[NUMBER_OF_EMPLOYEES];
public:void getData()
{
int i;
for(i=0;i<NUMBER_OF_EMPLOYEES;i++)
{
cout<<"Enter the following data for employee "<<(i+1)<<endl;
cout<<"Employee ID: ";
getline(cin,employeeID[i]);
len=employeeID[i].length();
while(1)
{
int len;
if(len==EMPLOYEE_ID_LENGTH)
{
break;
}
else
{
cout<<"Please enter Employee ID of length 4: "<<" ";
getline(cin,employeeID[i]);
len=employeeID[i].length();
}
}
cout<<"Hours worked: ";
cin>>hoursWorked[i];
while(1)
{
if(hoursWorked[i]>0)
{
break;
}
else
{
cout<<"Please enter hours worked greater than 0";
cin>>hoursWorked[i];
}
}
cout<<"Pay rate (per hour): ";
cin>>payRate[i];
while(1)
{
if(payRate[i]>0)
{
break;
}
else
{
cout<<"Please enter pay rate greater than 0";
cin>>payRate[i];
}
}
}
}
public:void calculateGrossPay()
{
int i;
for(i=0;i<NUMBER_OF_EMPLOYEES;i++)
{
grossPay[i]=hoursWorked[i]*payRate[i];
}
}
public:void displayOutput()
{
int i;
cout<<"Weekly Payroll: "<<endl;
cout<<"--------------------"<<endl<<endl;
cout<<"Employee ID Hours Worked Pay Rate Gross Pay"<<endl<<endl;
for(i=0;i<NUMBER_OF_EMPLOYEES;i++)
{
std::cout << std::setprecision(2) << std::fixed;
cout<<employeeID[i]<<" "<<hoursWorked[i]<<" "<<payRate[i]<<" ";
std::cout<<grossPay[i];
cout<<endl;
}
}
};
int main()
{
Employee e1;
e1.getData();
e1.calculateGrossPay();
e1.displayOutput();
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.