Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: To review value-returning functions and void functions, reference par

ID: 3757410 • Letter: O

Question

Objective: To review value-returning functions and void functions, reference parameters and value parameters. Tasks: Part 1: In this lab, we will use functions to input and validate the user input for the hours worked and pay rate (as type double) of an employee, calculate the gross pay, and output the hours worked, pay rate, and gross pay. We will define and invoke the following 3 functions to complete the above tasks. 1. A function named setHoursRate that prompts the user for the hours worked and pay rate of an employee. Both values must be non-negative. The function must keep reading user input until a valid input is entered. 2. A function named calcPay that accepts the hours worked and pay rate, calculates and returns the gross pay. (Assume gross pay hours worked pay rate.) 3. A function named printCheck that prints the hours worked, pay rate, and gross pay Part 2: Write loop statements in the main function to print out all the 95 printable characters in the ASCIl character set starting from the blank character

Explanation / Answer

I am prepared Single program above two parts using C++

PROGRAM

#include<iostream>

using namespace std;

// implement setHoursRate() function for set values

void setHoursRate(double rate,int hrs)

{

// initially set 0

rate=0.0;

hrs=0;

}

// implement calcPay() function for calculate

double calcPay(int &hrs,double &prate)

{

return hrs*prate; // calculate value and return

}

// implement printCheck() function for display

void printCheck(int &hrs,double &prate,double &gpay)

{

// display values

cout<<"Total Hours: "<<hrs<<endl;

cout<<"Pay Rate: "<<prate<<endl;

cout<<"Gross Pay Rate: "<<gpay<<endl;

}

int main()

{

// declare variables

int i=1,hrs;

double rate;

cout<<"Enter How many Hours: ";

cin>>hrs; // read hours

cout<<"Enter Pay Rate: ";

cin>>rate; // read rate

if(hrs>=0&&rate>=0.0) // check negative values

{

// Part-2 program display lines

cout<<char(255); // set fist value space using ascii character 255

while(i<=50) // create while loop until 50 characters

{

cout<<char(95); // display - using ascii value 95

i++; // increment i value

}

cout<<endl;

setHoursRate(rate,hrs); // calling setHoursRate() and set values

double r=calcPay(hrs,rate); // calling calcPay() function and receive total value

printCheck(hrs,rate,r); // calling printCheck() to display values

// display line using ascii values 255 and 95

int j=1;

cout<<char(255);

while(j<=50)

{

cout<<char(95);

j++;

}

cout<<endl;

}

// negative inputs display this message

else

cout<<"Invalid Inputs...."<<endl;

return 0;

}

OUTPUT-1

Enter How many Hours: 12
Enter Pay Rate: 265
__________________________________________________
Total Hours: 12
Pay Rate: 265
Gross Pay Rate: 3180
__________________________________________________

OUTPUT-2

Enter How many Hours: -18
Enter Pay Rate: 256
Invalid Inputs....