IN C++ microsoft visual studios 2013 Create a simple programmer prototype Librar
ID: 3826884 • Letter: I
Question
IN C++ microsoft visual studios 2013 Create a simple programmer prototype Library using a .h header file for your GrossPay Function Prototypes. Write a .cpp file that includes your functions from your Gross Pay program but no prototypes. Create a program called OverTime that calls getHoursWorked(), and getPayRate() from your GrossPay .cpp file. Make sure that for 40 hours or below, call CalcGross() from your GrossPay program. For more than 40 hours, write a new method (outside of main) in your OverTime program that pays the first 40 hours at straight Pay Rate and anything above 40 hours at 1.5 times Pay Rate. Note - If there were any issues in your old Gross Pay program, make sure they are fixed before using the code for this program.
Here is my gross pay program
#include "stdafx.h"
#include <iostream>
using namespace std;
//functions prototype
double getHoursWorked(double hours);
double getPayRate(double rate);
double calcGross(double gross);
//defining functions
int getHoursWorked() {
int hours;
cout << "Enter the hours worked: ";//prompt user to enter number of hours worked
cin >> hours;
return hours;
}
double getPayRate() {
double rate;
cout << "Enter the pay rate: "; //promt user to enter pay rate
cin >> rate;
return rate;
}
double calcGross(int hours, double rate) {
return hours * rate;
}
int main()
//calling functions getHoursWorked, getPayRate, calcGrossPay
{
int hours = getHoursWorked();
double rate = getPayRate();
double pay = calcGross(hours, rate);
cout << "The gross pay is " << pay << endl;//output the gross pay
return 0;
}
Explanation / Answer
#include <iostream>
using namespace std;
//functions prototype
double getHoursWorked(double hours);
double getPayRate(double rate);
double calcGross(double gross);
//defining functions
int getHoursWorked() {
int hours;
cout << "Enter the hours worked: ";//prompt user to enter number of hours worked
cin >> hours;
return hours;
}
double OverTime (int hours, double rate) {
return hours * rate;
}
double getPayRate() {
double rate;
cout << "Enter the pay rate: "; //promt user to enter pay rate
cin >> rate;
return rate;
}
double calcGross(int hours, double rate) {
if(hours <= 40 ) {
return hours * rate;
}
else{
return 40 * rate + OverTime(hours-40, (rate*3)/2);
}
}
int main()
//calling functions getHoursWorked, getPayRate, calcGrossPay
{
int hours = getHoursWorked();
double rate = getPayRate();
double pay = calcGross(hours, rate);
cout << "The gross pay is " << pay << endl;//output the gross pay
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the hours worked: 45
Enter the pay rate: 10
The gross pay is 475
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the hours worked: 35
Enter the pay rate: 10
The gross pay is 350