

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: INTRO COMPUTER PROG FOR ENGR; Subject: Computer Engineering; University: University of Alabama - Huntsville; Term: Unknown 1989;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Electrical and Computer Engineering
1
Problem-Solving Techniques
Electrical and Computer Engineering
2
Problem-Solving Case Study
Electrical and Computer Engineering
3
Case Study (continued)
Electrical and Computer Engineering
4
Main Algorithm
Open file payFile, Set total payroll to zero
Get Data
As long as the employee number is not zero
Compute Result
Add employee’s wages to the total payroll
Output data
Get data
Output total payroll
Electrical and Computer Engineering
5
Get Data
Prompt user for id number
Read id number
Prompt user for pay rate
Read pay rate
Prompt user for number hours worked
Read number hours worked
Electrical and Computer Engineering
6
Compute Results
If hours worked is greater than 40, then
Wages = 40 * pay rate + (hours – 40) * 1.5 * pay
rate
Otherwise
Wages = hours * pay rate
Electrical and Computer Engineering
7
Output Data
Write id number into payFile
Write pay rate into payFile
Write hours worked into payFile
Write wages into payFile
Electrical and Computer Engineering
8
Output Total Payroll
Electrical and Computer Engineering
9
Payroll Program
// Payroll program // This program computes each employee’s wages and the // total company payroll //**********************************************
#include
using namespace std;
void CalcPay (float, float, float&);
const float MAX_HOURS = 40.0; // Maximum normal hours const float OVERTIME = 1.5; // Overtime pay factor
Electrical and Computer Engineering
10
Payroll Program (continued)
int main { float payRate; // Employee’s pay rat 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
Electrical and Computer Engineering
11
Payroll Program (continued)
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 << payRage // Put results in 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
Electrical and Computer Engineering
12
Payroll Program (continued)
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 }