// Kurt Feiereisel CSC5 Chapter 7, p. 445, #8
/*******************************************************************************
*
* Calculate Wages for Employee ID Numbers
* _____________________________________________________________________________
* This program allows a user to enter the number of hours worked by an employee
* ID number, and the payrate of an employee ID number. The program will then
* calculate and report the gross wages for each employee ID number, and the
* hours worked by each employee ID number.
* _____________________________________________________________________________
* Formula:
* wages[NUM] = payRate[NUM] * hours[NUM]
*
* INPUT:
* empId[] : Employee's ID numbers
* hours[] : Number of hours worked by an employee Id number
* payRate[] : Payrate for an employee ID number
*
* OUTPUT:
* wages[] : The gross wages for an employee ID number
*
* ****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
void getInfo(int empId[], int hours[], float payRate[], int NUM);
void calcGross(int hours[], float payRate[], float wages[], int NUM);
void displayArray(int empId[], int hours[], float wages[], int NUM);
int main()
{
// Initialize Constants
const int NUM = 7;
// Declare / Initialize Array's
int empId[] = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
7580489}; // Input : Employee ID numbers
int hours[NUM]; // Input : Hours worked
float payRate[NUM]; // Input : Pay rate
float wages[NUM]; // Output : Gross Wages
// Call Functions
getInfo(empId, hours, payRate, NUM);
calcGross(hours, payRate, wages, NUM);
displayArray(empId, hours, wages, NUM);
return 0;
}
/*
* Definition of getInfo Function
* This function allows a user to enter hours worked, pay rate, and wages of
* an employee ID.
*/
void getInfo(int id[], int h[], float p[], int num)
{
// Input Hours for Employee ID
for (int index = 0; index < num; index++)
{
cout << "Enter Employee #" << id[index] << "'s information:\n";
// Input Hours
cout << "Hours: ";
cin >> h[index];
// Input Verification
while(h[index] < 0)
{
cout << "Please enter a positive number for hours.";
cin >> h[index];
}
// Input PayRate
cout << "Pay Rate: ";
cin >> p[index];
// Input Verification
while (p[index] < 6.00)
{
cout << "Please enter a pay rate more than $6.00.";
cin >> p[index];
}
cout << endl;
}
}
/*
* Definition of calcGross
* This function calculates the gross wages for an employee ID
*/
void calcGross(int h[], float p[], float w[], int num)
{
// Calculate and Store Gross Wages
for(int index = 0; index < num; index++)
w[index] = (h[index] * p[index]);
}
/*
* Definition of displayArray
* This function will display the hours and wages for each employee ID
*/
void displayArray(int id[], int h[], float w[], int num)
{
// Display Header
cout << "Employee ID" << setw(4) << "| " << setw(6)
<< "Hours" << setw(4) << "| " << setw(6) << "Wages" << endl;
cout << "-----------------------------------" << endl;
// Implement for loop to display hours and wages for each employee ID
for(int index = 0; index < num; index ++)
{
cout << fixed << setprecision(2) << showpoint;
cout << id[index] << setw(7) << "|" << " " << h[index]
<< setw(6) << "|" << " " << w[index] << endl;
}
}