CS 150 Introduction to C++ Programming - Spring 1998 |
|---|
[ Home | Lecture Notes| WebTutor | WebTutor Site Map]
The purpose of this exercise is to understand key parts of the
payroll case study on page 35 of your textbook.
Key Concepts are:
NOTE: at this point in the semester, you are not expected to
fully understand everything about this program!
You will be learning the concepts shown here later on. However,
see how many of the key concepts you can identify already.
Remember you are not being graded for this.
Line Number |
Program |
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 |
//******************************************************************
// Payroll program
// This program computes each employee's wages and
// the total company payroll
//******************************************************************
#include <iostream.h>
#include <fstream.h> // For file I/O
void CalcPay( float, float, float& );
const float MAX_HOURS = 40.0; // Maximum normal work hours
const float OVERTIME = 1.5; // Overtime pay rate factor
int main()
{
float payRate; // Employee's pay rate
float hours; // Hours worked
float wages; // Wages earned
float total; // Total company payroll
int empNum; // Employee ID number
ofstream payFile; // Company payroll file
payFile.open("payfile.dat"); // Open the output file
total = 0.0; // Initialize total
cout << "Enter employee number: "; // Prompt
cin >> empNum; // Read employee ID no.
while (empNum != 0) // While employee number
{ // isn't zero
cout << "Enter pay rate: "; // Prompt
cin >> payRate; // Read hourly pay rate
cout << "Enter hours worked: "; // Prompt
cin >> hours; // Read hours worked
CalcPay(payRate, hours, wages); // Compute wages
total = total + wages; // Add wages to total
payFile << empNum << payRate // Put results into file
<< hours << wages;
cout << "Enter employee number: "; // Prompt
cin >> empNum; // Read ID number
}
cout << "Total payroll is " // Print total payroll
<< total << endl; // on screen
return 0; // Indicate successful
} // completion
//******************************************************************
void CalcPay( /* in */ float payRate, // Employee's pay rate
/* in */ float hours, // Hours worked
/* out */ float& wages ) // Wages earned
// CalcPay computes wages from the employee's pay rate
// and the hours worked, taking overtime into account
{
if (hours > MAX_HOURS) // Is there overtime?
wages = (MAX_HOURS * payRate) + // Yes
(hours - MAX_HOURS) * payRate * OVERTIME;
else
wages = hours * payRate; // No
}
|
Answer the following questions (list lines in order seperated by commas - for example "1,4,6"):