Question & Answer: Employee’s Weekly Gross Pay…..

Employee’s Weekly Gross Pay

Create a C++ program to calculate and display an employee’s weekly gross pay. The program should ask for the number of work hours in a week and the hourly pay rate, and use these items to calculate gross pay (gross pay = number of work hours * hourly rate). In addition to main(), use the following two functions in your program:

getRateAndHrs(): a void function that asks for hourly rate and number of work hours. Use pass-by-reference to send these two items to main().

calcPay(): a value returning function that calculates and returns gross pay to main().

The main() function should display the gross pay on the computer screen.

Expert Answer

 

// C++ code

#include <iostream>

#include <stdio.h>

#include <algorithm>

#include <math.h>

using namespace std;

// void function that asks for hourly rate and number of work hours.

void getRateAndHrs (double &hourlyRate, double &hoursWorked)

{

 

cout <<“Enter in Hourly Rate: “;

cin >> hourlyRate;

cout <<“Enter how many hours worked: “;

cin >> hoursWorked;

}

// a value returning function that calculates and returns gross pay to main().

double calcPay(double hourlyRate, double hoursWorked)

{

double grossPay = hourlyRate * hoursWorked;

return grossPay;

 

}

int main( )

{

double hourlyRate;

double hoursWorked;

getRateAndHrs(hourlyRate, hoursWorked);

double grossPay = calcPay(hourlyRate, hoursWorked);

cout << “Gross pay: $” << grossPay << endl;

 

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!