1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// File: Gross pay calculator using functions.cpp
// Programmer: Sadia Rajput CPSC 1103 S10
// Purpose: Computes a worker's gross pay
#include<iostream>
#include<iomanip>
using namespace std;
//*****************************************************
// Function Prototypes
//*****************************************************
void intro(); // Displays welcome message
void getInput(int&, double&, double&); // Gets user input
double computeGrossWage(double, double); // Calculates gross pay based on hours worked & hourly wage
void displayEmptyData(int, double, double, double); // Displays, employee ID #, hours worked, hourly pay, gross pay
//*****************************************************
// Main Program
//*****************************************************
int main()
{
// Variables
int employeeIDnumber;
double hoursWorked;
double hourlyWage;
double grossPay;
//Function calls
intro(); // Calls function to display welcome message
do
{
getInput(employeeIDnumber, hoursWorked, hourlyWage);// Calls function to get user input
grossPay = computeGrossWage(hourlyWage, hoursWorked);
computeGrossWage(hourlyWage, hoursWorked); // Calls function to calculate gross pay
displayEmptyData(employeeIDnumber, hoursWorked, hourlyWage, grossPay);
} while (employeeIDnumber != -1);
// Exit
system("pause");
return 0;
}
//*****************************************************
// Function Definitons
//*****************************************************
void intro()
// Purpose: Displays welcome message
// Parameters: None
// Returns: None
{
cout << "Welcome to the gross pay calculator" << endl;
}
void getInput(int& employeeIDnumber, double& hoursWorked, double& hourlyWage)
// Purpose: Gets user input
// Parameters: Employee ID number, hours worked, hourly wage
// Returns: None
{
do
{
cout << "Enter employee ID number: ";
cin >> employeeIDnumber;
cout << "Enter number of hours worked: ";
cin >> hoursWorked;
cout << "Enter hourly wage: ";
cin >> hourlyWage;
}while (employeeIDnumber != -1);
cout << endl;
}
double computeGrossWage(double hourlyWage, double hoursWorked)
// Purpose: Calculates gross pay based on hours worked & hourly wage
// Parameters: Hourly wage, hours worked
// Returns: Gross pay
{
double grossPay;
if (hoursWorked <= 40)
grossPay = (hoursWorked * hourlyWage);
else
grossPay = (hourlyWage * (hoursWorked - 40) * 1.5) + (40 * hourlyWage);
return grossPay;
}
void displayEmptyData(int employeeIDnumber, double hoursWorked, double hourlyWage, double grossPay)
// Purpose: Displays results of gross pay calculation
// Parameters: employee ID #, hours worked, hourly wage, gross pay
// Returns: None
{
cout << "Employee ID number: " << employeeIDnumber << endl;
cout << "Gross Pay: $" <<fixed << setprecision(2) << grossPay << endl;
}
|