// 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
}
1.Question is to insert the code to print out the Gross Pay and Net Pay.
2.Insert the contents of CalculateGross Method.
using System;
namespace Questions
{
class Program
{
static void Main()
{
// Call a method to calculate the gross pay (call by value)
Console.Write("Lastname: ");
string lastName = Console.ReadLine();
Console.Write("\nhours: ");
int hrsWrked = int.Parse(Console.ReadLine());
Console.Write("\nrate: ");
double ratePay = double.Parse(Console.ReadLine());
double grossPay = CalculateGross(hrsWrked, ratePay);
Console.Write("\ntax (from 0 to 1): ");
double taxRate = double.Parse(Console.ReadLine());
double netPay = 0;
// Invoke a method to calculate the net pay (call by reference)
CalculateNet(grossPay, taxRate, ref netPay);
Console.WriteLine();
// print out the results
Console.WriteLine(string.Format("{0} worked {1} hours at {2} per hour", lastName,
hrsWrked, ratePay.ToString("0.00")));
// *** Insert the code to print out the Gross Pay and Net Pay
Console.WriteLine(string.Format("Gross pay: {0}", grossPay.ToString("0.00")));
Console.WriteLine(string.Format("Net pay: {0}", netPay.ToString("0.00")));
Console.ReadLine();
Console.ReadKey();
}
// 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
return rate * hours;
}
public static void CalculateNet(double grossPay, double taxRate, ref double netPay)
{
netPay = grossPay * (1 - taxRate);
}
}
}
Comments
Leave a comment