Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

What I have tried:

C++
double getHoursWorked(double Hours);
double getPayRate(double Rate);
double calcGross(double Gross);
//defining functions
int getHoursWorked()
{
	int Hours;
	cout << "please 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 << "\nPlease 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 << "\nThe gross pay is  :" << Pay << endl;//output the gross pay
	return 0;
}
Posted
Updated 19-Nov-20 18:21pm
v2

Your code looks correct to me, albeit not fully compliant with the requirements (e.g. you didn't write the function prototypes in a separate header).
 
Share this answer
 
First, you don't need the function prototypes. As long as a function or its prototype appears before it is used you are OK.

Second, you can lose the function OverTime entirely and for two reasons : it is not called and it does not do what its name implies.

Third, I would rewrite your calcGross function to make it simpler.
C++
double calcGross( int hours, double rate )
{
    int straight = hours;
    if( straight > 40 )
        straight = 40;
    double stamount = straight * rate;

    int over = hours - 40;
    if( over < 0 )
        over = 0;
    double otamount = rate * 1.5 * over;

    return otamount + stamount;
}
There is a little more code there but it is all very simple and it is much easier to see what's going on the debugger which is the highest priority for me.

-edit-

The prototypes are supposed to be in a separate header file to satisfy the requirement. The compiler does not require that as I noted.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900