Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make sure to make a copy of the Google Doc for this lab into your Google Account. Answer all the highlighted questions in there. Here

Make sure to make a copy of the Google Doc for this lab into your Google Account. Answer all the highlighted questions in there.

Here is a program that uses two user-defined methods: one with call by value formal parameters and one with call by address formal parameters. The program computes the Gross Pay and Net Pay for an employee after entering the employees last name, hours worked, hourly rate, and percentage of tax.

Make a new Project in C# (called Lab6). Delete the skeleton code, and rename Program.cs, to Lab6.cs. Then enter the following program into C# (ignore the line numbers).

// Name: xxxxxxxxxxxxx // Student Number: xxxxxxx // Lab 6 // Program Description: This program uses two user defined methods to compute // the gross pay and net pay for an employee after entering the employees // last name, hours worked, hourly rate, and percentage of tax. using System; public static class Lab6 { public static void Main() { // declare variables int hrsWrked; double ratePay, taxRate, grossPay, netPay=0; string lastName; // enter the employee's last name Console.Write("Enter the last name of the employee => "); lastName = Console.ReadLine(); // enter (and validate) the number of hours worked (positive number) do { Console.Write("Enter the number of hours worked (> 0) => "); hrsWrked = Convert.ToInt32(Console.ReadLine()); } while (hrsWrked < 0); // enter (and validate) the hourly rate of pay (positive number) // *** Insert the code to enter and validate the ratePay // enter (and validate) the percentage of tax (between 0 and 1) // *** Insert the code to enter and validate taxRate // Call a method to calculate the gross pay (call by value) grossPay = CalculateGross(hrsWrked, ratePay); // Invoke a method to calculate the net pay (call by reference) CalculateNet(grossPay, taxRate , ref netPay); // print out the results Console.WriteLine("{0} worked {1} hours at {2:C} per hour", lastName, hrsWrked, ratePay); // *** Insert the code to print out the Gross Pay and Net Pay Console.ReadLine(); } // Method: CalculateGross // Parameters // hours: integer storing the number of hours of work // rate: double storing the hourly rate // Returns: double storing the computed gross pay public static double CalculateGross(int hours, double rate) { // *** Insert the contents of the CalculateGross Method } // Method: CalculateNet // Parameters // grossP: double storing the grossPay // tax: double storing tax percentage to be removed from gross pay // netP: call by reference double storing the computed net pay // Returns: void public static void CalculateNet(double grossP, double tax, ref double netP) { // *** Insert the details of the CalculateNet Method } }

Copy

Replace the lines marked with // *** with the appropriate C# code (may require more than one line of code to complete the missing parts).

Build the solution. Resolve any syntax mistakes (if you make any) until the program compiles. Run the program using the input data: Smith, 40, 12.5, 0.2. You should find that the gross pay is $500.00 and net pay is $400.00

What is the output?

Run the program using input Smith, -8,40, 12.5, 0.2.

What is the output?

Run the program using input Smith, 40,-3, 12.5, 0.2.

What is the output?

Run the program using input Smith, 40,12.5, 9, 0.2.

What is the output?

Run the program using input Smith, 44,12.5, 0.2.

What is the output?

Now lets add another user-defined method to our program ... this method will compute any overtime pay.

Assume the employees receive time and a half (1.5) for any hours worked over 40).

Your method should be invoked after you compute gross pay with CalculateGross but before you compute net pay with CalculateNet (i.e., between Lines 36 and 39).

The new method is to be called CalculateOT, and it is to have to following method header:

public static double CalculateOT(int hours, double rate)

Copy

In this method, both formal parameters are call by value with hours representing the number of hours work and rate representing the hourly wage.

CalculateOT is to return only the amount of overtime pay (in excess of regular pay) which is computed from the number of hours greater than 40 multiplied by the hourly wage and then multiplied by 0.5.

CalculateOT is only returning the overtime amount which must be added to the gross pay variable in Main() before netPay is calculated

Run the program using the input data: Smith, 40, 12.5, 0.2.

What is the output?

Run the program using input Smith, 44,12.5, 0.2.

The grossPay for this data should be $575 and the netPay should be $460. If you get a different answer, you've made a mistake and should revisit your code.

What is the output?

How does the result differ from Part (f)?

Run the program using input Smith, 20,12.5, 0.2.

The grossPay for this data should be $250 and the netPay should be $200. If you get a different answer, you've made a mistake and should revisit your code.

What is the output?

You're now finished the lab. Save your Google Doc, and export it as a PDF.

Upload your completed PDF, plus your Lab6.cs to Blackboard.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

a valuing of personal and psychological privacy;

Answered: 1 week ago