Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// This program demonstrates overloaded functions to calculate // the gross weekly pay of hourly paid, salarized or contracted // employees. #include #include using namespace

// This program demonstrates overloaded functions to calculate

// the gross weekly pay of hourly paid, salarized or contracted

// employees.

#include

#include

using namespace std;

// Function prototypes

void getChoice(char &);

double calcWeeklyPay(int, double);

double calcWeeklyPay(double);

int main()

{

char selection; // Employee selection

int worked; // Hours worked

double rate; // Hourly pay rate

doyble yearly; // Yearly salary

// Set numeric output formatting.

cout << fixed << showpoint << setprecision(2);

// Display the selection.

cout << "Do you want to calculate the weekly pay of ";

cout << "(H) an hourly paid employee, or ";

cout << "(S) a salarized employee? ";

cout << "(C) an contracted employee? ";

getChoice(selection);

// Process the selection.

switch (selection)

{

// Hourly paid employee

case 'H' :

case 'h' : cout << "How many hours were worked? ";

cin >> worked;

cout << "What is the hourly pay rate? ";

cin >> rate;

cout << "The gross weekly pay is $";

cout << calcWeeklyPay(worked, rate) << endl;

break;

// Salarized employee

case 'S' :

case 's' :

cout << "What is the annual salary? ";

cin >> yearly;

cout << "The gross weekly pay is $";

cout << calcWeeklyPay(yearly) << endl;

break;

}

return 0;

}

//***************************************************************************

//Defination of function getChoice. *

// The arameter letter is a refernce to a char. *

// This function asks the user for an H, S or C and returns *

// the validated input. *

//***************************************************************************

void getChoice(char & letter)

{

// Get the user's selection.

cout << "Enter your choice (H, S or C): ";

cin >> letter;

// Validate the selection.

while (letter != 'H' && letter != 'h' &&

letter != 'S' && letter != 's' &&

letter != 'C' && letter != 'c')

{

cout << "Please enter H, S or C: ";

cin >> letter;

}

}

//***************************************************************************

//Defination of function getChoice. * *

// This function calculates the gross weekly pay of *

//an hourly paid employee.The parameter hours holds the *

// number of hours worked. The parameter payRate holds the *

// hourly pay rate. The function returns the weekly salary. * *

//***************************************************************************

double calcWeeklyPay(int hours,double payRate)

{

return hours * payRate;

}

//***************************************************************************

//Defination of function getChoice. * *

// This function calculates the gross weekly pay of *

//an hourly paid employee.The parameter hours holds the *

// number of hours worked. The parameter payRate holds the *

// hourly pay rate. The function returns the weekly salary. * *

//***************************************************************************

double calcWeeklyPay(double annSalary)

{

return annSalary / 52;

}

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