How do I call calculate pay based on the following rules: (****** PLEASE COMMENT
ID: 3633825 • Letter: H
Question
How do I call calculate pay based on the following rules:
(****** PLEASE COMMENT CODE **********)
- For hours between 0 and 40, the pay is payrate times the number of hours worked.
- For all hours over 40 and less than or equal to 60, the payrate is one and a half times the normal payrate
- For all hours over 60, the payrate is twice the normal payrate
// Employee pay header file
class Pay
{
private:
double payRate;
int numHours;
public:
double getPayRate();
void setPayRate(double newPayRate);
int getNumHours();
void setNumHours(int newNumHours);
double calculatePay();
};
// Implementation file for Pay.h
#include <iostream>
using namespace std;
#include "Pay.h"
// Accessor function: Pay rate
double Pay::getPayRate()
{
return payRate;
}
// Mutator function: Pay rate
void Pay::setPayRate(double newPayRate)
{
payRate = newPayRate;
}
// Accessor function: Number of hours
int Pay::getNumHours()
{
return numHours;
}
// Mutator function: Number of hours
void Pay::setNumHours(int newNumHours)
{
numHours = newNumHours;
}
// Function: Calculate pay
double Pay::calculatePay()
{
}
// Main function
int main()
{
Pay p1;
p1.setNumHours(45);
p1.setPayRate(12);
cout << "The number of hours worked is: " << p1.getNumHours() << " ";
cout << "The pay rate is: " << p1.getPayRate() << " ";
cout << "The pay for the employee is: " << p1.calculatePay() << " ";
return 0;
}
Explanation / Answer
Dear,
Here is the code
#include<iostream>
using namespace std;
class Payroll
{
private://member variables
double hourrate;
double noh;
double totalpay;
public:
//default constructor
Payroll()
{
hourrate=0.0;
noh=0.0;
}
//Mutator function for pay rate
void setRate(double rate)
{
hourrate=rate;
}
//Mutator function for number of hours
void setHour(double h)
{
noh=h;
}
//calculating pay
void calculatePay()
{
if(noh<=40)
totalpay=noh*hourrate;
else
totalpay=((noh-40)*hourrate*0.01)+noh*hourrate;
}
//Accessor function for number of hours
double getHour()
{ return noh; }
// Accessor function for total pay
double gettotalpay()
{ return totalpay;
}
};
int main()
{
Payroll p[10];//An array of seven payroll objects
double hrs,rate;
//initializing memebers of class
for(int i=0;i< 10;i++)
{
cout<< "Enter the number of hours for employee " << i+1<< endl;
cin>>hrs;
cout<< "Enter rate:";
cin>>rate;
p[i].setHour(hrs);
p[i].setRate(rate);
p[i].calculatePay();
}
for(int j=0;j< 10;j++)
{
cout<< "The gross pay for employee "<< j+1 << "is:" << p[j].gettotalpay() << endl;
}
system("pause");
return 0;
}
Hope this will help you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.