May 9, 2022 at 11:20pm UTC
Write C++ Console Application program that calculates a worker’s net earnings per week. The earnings are calculated based on the following factors:
1) Worker’s hourly wage is requested and entered.
2) Hours worked for each of the five working days per week are entered into an array using a loop procedure.
3) Total hours worked per week are calculated.
4) If the hours worked are less than or equal to 40, the net earning is calculated by simply multiplying the hourly wage by the number of hours worked per week [ total_hours worked X hourly_wage].
5) If the hours worked are more than 40, 40 hours are paid at regular rate, and the hours over 40 are paid at “hour and half” (overtime) rate. The total earning will then be the regular pay plus the overtime. [Regular_pay + (total_hours_worked – 40) x (1.5 X hourly_wage)]
The program should display the following:
1) Hourly wage
2) Hours worked per day.
3) Total hours per week worked.
4) Total pay (in monetary format)
Last edited on May 9, 2022 at 11:21pm UTC
May 9, 2022 at 11:40pm UTC
What issues are you having with your implementation? Show what you've tried.
May 10, 2022 at 12:07am UTC
#include <iostream>
#include <iomanip>
using namespace std;
class Payroll
{
private:
double hoursWorked;
double payRate;
public:
Payroll();
Payroll(double, double);
void setHours(double);
void setPayRate(double);
double getHours();
double getPayRate();
double getGross();
};
// Define member functions
Payroll::Payroll()
{
hoursWorked = 0;
payRate = 0.0;
}
Payroll::Payroll(double h, double r)
{
payRate = r;
hoursWorked = h;
}
void Payroll::setHours(double h)
{
hoursWorked = h;
}
void Payroll::setPayRate(double p)
{
payRate = p;
}
double Payroll::getHours()
{
return hoursWorked;
}
double Payroll::getPayRate()
{
return payRate;
}
double Payroll::getGross()
{
double gross = (hoursWorked)*payRate;
return gross;
}
int main()
{
const int NUM_EMPLOYEES = 1;
Payroll employee[NUM_EMPLOYEES];
double pay;
double hours;
int x;
double grossPay;
for (x = 0; x < NUM_EMPLOYEES; x++)
{
cout << "Enter Employee # " << (x) << " rate of pay per hour: ";
cin >> pay;
cout << "Enter Employee # " << (x) << " hours worked for the week: ";
cin >> hours;
employee[x].setPayRate(pay);
employee[x].setHours(hours);
}
cout << "\n\nHere is the gross pay for each employee:" << endl;
cout << fixed << showpoint << setprecision(2);
for (int x = 0; x < NUM_EMPLOYEES; x++)
{
grossPay = employee[x].getGross();
cout << "The gross pay for employee # " << (x) << " is: " << grossPay << endl;
}
system("pause");
return 0;
}
Last edited on May 10, 2022 at 12:09am UTC
May 10, 2022 at 12:26am UTC
To help us to better help you:
So you've written some code, what is the problem with the code?
Last edited on May 10, 2022 at 4:42am UTC
May 10, 2022 at 8:05am UTC
Slightly simplified version of the posted code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <iostream>
#include <iomanip>
class Payroll {
private :
double hoursWorked {};
double payRate {};
public :
Payroll();
Payroll(double , double );
void setHours(double );
void setPayRate(double );
double getHours() const ;
double getPayRate() const ;
double getGross() const ;
};
// Define member functions
Payroll::Payroll() {}
Payroll::Payroll(double h, double r) : payRate(r), hoursWorked(h) {}
void Payroll::setHours(double h) { hoursWorked = h; }
void Payroll::setPayRate(double p) {payRate = p; }
double Payroll::getHours() const {return hoursWorked; }
double Payroll::getPayRate() const { return payRate; }
double Payroll::getGross() const { return hoursWorked * payRate; }
int main() {
constexpr size_t NUM_EMPLOYEES {1};
Payroll employee[NUM_EMPLOYEES] {};
for (size_t x {}; x < NUM_EMPLOYEES; ++x) {
double pay {};
double hours {};
std::cout << "Enter Employee # " << x + 1 << " rate of pay per hour: " ;
std::cin >> pay;
std::cout << "Enter Employee # " << x + 1 << " hours worked for the week: " ;
std::cin >> hours;
employee[x].setPayRate(pay);
employee[x].setHours(hours);
}
std::cout << "\n\nHere is the gross pay for each employee:\n" ;
std::cout << std::fixed << std::showpoint << std::setprecision(2);
for (size_t x {}; x < NUM_EMPLOYEES; ++x)
std::cout << "The gross pay for employee # " << x + 1 << " is: " << employee[x].getGross() << '\n' ;
}
What are the issues with coding the rest of the program?
Last edited on May 10, 2022 at 8:06am UTC