|
|
|
|
|
|
|
As long as the employee number is not 0, repeat the following steps:
Prompt the user for the employee's hourly pay rate
Read the pay rate
Prompt the user for the number of hours worked
Read the number of hours worked
Perform the subalgorithm for calculating pay (below)
Add the employee's wages to the total payroll
Write the employee number, pay rate, hours worked, and wages onto the list (file payFile)
Prompt the user for the employee number
Read the employee number
When an employee number equal to 0 is read, continue with the following steps:
Write the total company payroll on the screen
Stop |
|
|
|
|
|
|
|
|
Subalgorithm for Calculating Pay |
|
|
|
|
|
|
|
|
If hours worked is greater than 40.0, then
wages = (40.0 × pay rate) + (hours worked - 40.0) × 1.5 × pay rate
otherwise
wages = hours worked × pay rate |
|
|
|
|
|
|
|
|
Before we implement this algorithm, we should test it. Case Study Follow-Up Exercise 2 asks you to carry out this test. |
|
|
|
|
|
|
|
|
What follows is the C++ program for this algorithm. It's here to give you an idea of what you'll be learning. If you've had no previous exposure to programming, you probably won't understand most of the program. Don't worry; you will soon. In fact, throughout this book as we introduce new constructs, we refer you back to the Payroll program. One more thing: The remarks following the symbols // are called comments. They are here to help you understand the program; the compiler ignores them. Words enclosed by the symbols /* and */ also are comments and are ignored by the compiler. |
|
|
|
|
|
|
|
|
//******************************************************************
// 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& );
|
|
|
|
|
|