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

Please write a c++ code for my pseudo code. I am take a class that is teaching m

ID: 3722950 • Letter: P

Question

Please write a c++ code for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would like to see the actual code so that I can start preparing myself for next semester’s classes. Here is the pseudo code:

// Main module

Module main()

// Local variables

Declare Real rate, hours

// Get the rate of pay.

Call getRate(rate)

// Get the hours worked.

Call getHours(hours)

// Show the gross pay.

Call showGrossPay(rate, hours)

End Module

// The getRate module gets the pay rate.

Module getRate(Real Ref amount)

// Get the pay rate.

     Display "Enter hourly pay rate."

Input amount

     // Validate the pay rate.

     While amount < 7.50 OR amount > 18.25

          Display "Pay rate must be between 7.50 and 18.25."

          Display "Enter a valid pay rate."

          Input amount

     End While

End Module

// The getHours module gets hours worked.

Module getHours(Real Ref hours)

     // Get the hours worked.

     Display "Enter hours worked:"

     Input hours

     // Validate the hours.

     While hours < 0 OR hours > 40

          Display "Hours must be between 0 and 40!"

          Display "Enter a valid number."

          Input hours

     End While

End Module

// The showGrossPay module shows gross pay.

Module showGrossPay(Real rate, Real hours)

Declare Real gross

     // Calculate the gross pay.

Set gross = rate * hours

// Display the gross pay,

Display "Employee gross pay: $", gross

End Module

This is what the output should show:

Enter the pay rate (between 7.5 AND 18.25):
7
Enter the pay rate (between 7.5 AND 18.25):
18.5
Enter the pay rate (between 7.5 AND 18.25):
18.25
Enter hours (between 0.0 AND 40.0):
41
Enter hours (between 0.0 AND 40.0):
40
Gross Pay is: $730.0

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//code.cpp

#include<iostream>

using namespace std;

/*method to prompt the user to enter the hourly payrate and update the variable passed as reference*/

void getRate(float &rate){

                cout<<"Enter hourly pay rate (between 7.5 AND 18.25): ";

                cin>>rate;

                /**loops until the user enters a valid input (only if he input an invalid value) */

                while(rate<7.50 || rate>18.25){

                                cout<<"Pay rate must be between 7.50 and 18.25!"<<endl;

                                cout<<"Enter a valid pay rate: ";

                                cin>>rate;

                }

}

/*method to prompt the user to enter the number of hours worked and update the variable passed as reference*/

void getHours(float &hours){

                cout<<"Enter hours worked (between 0.0 AND 40.0): ";

                cin>>hours;

                /**loops until the user enters a valid input (only if he input an invalid value) */

                while(hours<0 || hours>40){

                                cout<<"Hours must be between 0 and 40!"<<endl;

                                cout<<"Enter a valid number: ";

                                cin>>hours;

                }

}

/*method to find and display the gross pay, given the hourly rate and number of hours worked*/

void showGrossPay(float rate, float hours){

                float gross;

                gross=rate*hours;

                cout<<"Employee gross pay: $"<<gross<<endl;

}

int main(){

                //initializing variables

                float rate,hours;

                //getting rate

                getRate(rate);

                //getting hours

                getHours(hours);

                //finding and displaying the gross pay

                showGrossPay(rate,hours);

                return 0;

}

/*OUTPUT*/

Enter hourly pay rate (between 7.5 AND 18.25): 7

Pay rate must be between 7.50 and 18.25!

Enter a valid pay rate: 20

Pay rate must be between 7.50 and 18.25!

Enter a valid pay rate: 18.2

Enter hours worked (between 0.0 AND 40.0): -5

Hours must be between 0 and 40!

Enter a valid number: 45

Hours must be between 0 and 40!

Enter a valid number: 10

Employee gross pay: $182