Create the following program using C++ Problem 2: Modify Program 8-33, pages 582
ID: 3867954 • Letter: C
Question
Create the following program using C++
Problem 2: Modify Program 8-33, pages 582, 583 (30 points) Create a program proj4_2.cpp using as starting point the program 8-33 from pages 582, 583. You can modify directly the file from the textbook data files pr8-33.cpp (click to download) but save it under the required project file name. Your program should change the struct Payinfo into class Paylnfo. For this class, the data members hours and payRate should be private. The class should have a default constructor and following member functions: void setHours(int hr); void setpayRate(double pr); int getHours0 double getPayRate); double getGrossPay:/ this function computes and if necessary adds overtime as the required project file (regular_pay+1.5*pay_rate hours_over_40) Finally, in main0 you should not have the variable grossPay since this value is available by calling getGrossPay For the given input as an example in the textbook, your program should generate the same output values. Absolutely NO GLOBAL VARIABLES ALLOWEDExplanation / Answer
#include<iostream>
using namespace std;
class PayInfo {
private:
double payRate;
int hours;
public:
PayInfo() {
payRate = 0;
hours = 0;
}
void setHours(int hr) {
hours = hr;
}
void setPayRate(double pr) {
payRate = pr;
}
int getHours() {
return hours;
}
double getPayRate() {
return payRate;
}
double getGrossPay() {
double regular_pay = hours*payRate;
double grossPay = regular_pay + 1.5*payRate*(hours>40?(hours-40):0);
}
};
int main() {
PayInfo payInfo;
int hr;
double pr;
double gross;
cout << "Enter work hours: ";
cin >> hr;
cout << "Enter payRate: ";
cin >> pr;
payInfo.setHours(hr);
payInfo.setPayRate(pr);
gross = payInfo.getGrossPay();
cout << "Gross pay = " << gross << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.