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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
CSC 205-E1
Assignment #7
The purpose of this assignment write a program that will compute the total pay of each employee and the total payroll amount of the company.
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
struct incomeInfo {
string emp_id;
double pay;
double bonus;
double totPay;
};
// Function Prototypes
void getInfo(incomeInfo[], int);
void compute(incomeInfo* wPtr, int);
void totPayroll(incomeInfo, int);
void display(incomeInfo[], int);
void highpay(incomeInfo[], int);
int main()
{
const int NUM_EMPS = 5; // Number of employee
incomeInfo employee[NUM_EMPS]; // Array of structures
// Function calls
getInfo(employee, NUM_EMPS);
compute(employee, NUM_EMPS);
// totPayroll(employee, NUM_EMPS);
display(employee, NUM_EMPS);
highpay(employee, NUM_EMPS);
// Exits program
cin.get();
cout << "Press ENTER to quit.";
cin.get();
return 0;
}
void getInfo(incomeInfo employee[], int NUM_EMPS)
{
// Get employee pay data.
cout << "Enter the ID pay and Bonus' for each employee.\n \n";
for (int index = 0; index < NUM_EMPS; index++)
{
// Get the employee's ID #.
cout << "Enter the ID for employee #" << (index + 1);
cout << ": ";
cin >> employee[index].emp_id;
// Get the employee's pay.
cout << "How much was employee #";
cout << (index + 1) << " paid: ";
cin >> employee[index].pay;
// Get the employee's Bonus.
cout << "How much was employee #";
cout << (index + 1) << " bonus: ";
cin >> employee[index].bonus;
cout << endl;
}
return;
}
void compute(incomeInfo * wPtr, int NUM_EMPS)
{
// Calculates each employee's total pay.
for (int index = 0; index < NUM_EMPS; index++)
{
(wPtr + index)->totPay = (wPtr + index)->pay + (wPtr + index)->bonus;
}
return;
}
void totPayroll(incomeInfo employee, int NUM_EMPS)
{
// Calculates total payroll.
for (int index = 0; index < NUM_EMPS; index++)
{
}
return;
}
void display(incomeInfo employee[], int NUM_EMPS)
{
// Display each employee's gross pay.
cout << "Here is the gross pay for each employee:\n";
cout << fixed << showpoint << setprecision(2);
cout << "ID." << setw(13) << "Pay" << setw(20) << "Bonus" << setw(20) << "Total Pay\n";
for (int index = 0; index < NUM_EMPS; index++)
cout << employee[index].emp_id << setw(14) << employee[index].pay << setw(20) << employee[index].bonus << setw(20) << employee[index].totPay << endl;
return;
}
void highpay(incomeInfo employee[], int NUM_EMPS)
{
double high = employee[0].totPay;
for (int index = 0; index < NUM_EMPS; index++)
{
if (employee[index].totPay > high)
{
high = employee[index].totPay;
}
}
cout << fixed << showpoint << setprecision(2);
cout << "\n \n Highest Pay = $" << high << endl;
return;
}
|