Server IP : 172.16.15.8 / Your IP : 3.137.181.69 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/lmking1/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//------------------------------------------------------------------------------- // CS 112 Fall 2008 // Program Assignment #6 // Purpose: To help a company tally their employee expense data and // produce an Expense Summary Report. // Due Date: 5 December 2008 // Written by: L'Tia King //------------------------------------------------------------------------------- #include <iostream> #include <iomanip> using namespace std; const int MAXEMPLOYEES = 30; // there are at most 30 employees //------------------------------------------------------------------------------- // InitializeArrays sets the contents of both arrays to zero //------------------------------------------------------------------------------- // Accepts: the number of employees // Returns: both the expenses array and the expensecounts array //------------------------------------------------------------------------------- void InitializeArrays (float expenses [], int expensecounts [], int numemployees) { for (int i = 0; i < numemployees; i ++) { expenses [i] = 0; expensecounts [i] = 0; } } //------------------------------------------------------------------------------- // TallyExpense inputs the "expense slips" from the data file and tallies // them into the arrays //------------------------------------------------------------------------------- // Accepts: the data file // Returns: returns the expenses and the number of expenses //------------------------------------------------------------------------------- void TallyExpenses (float expenses [], int expensecounts [], int numemployees) { float empexpense; // employee expenses int empid; // employee id number cin >> empid; while (empid >= 0) { cin >> empexpense; expensecounts [empid] ++; expenses [empid] += empexpense; cin >> empid; } } //------------------------------------------------------------------------------- // ReportExpenses uses the arrays from TallyExpenses to produce an Expense // Summary Report //------------------------------------------------------------------------------- // Accepts: both the expenses array and the expensecounts array //------------------------------------------------------------------------------- void ReportExpenses (float expenses [], int expensecounts [], int numemployees) { float avgexp, // average expense minexp = 5000, // minimum expense totalexp = 0; // total of all expenses int totalnum = 0, // total number expenses empid, // employee id number empidmin; // employee with minimum expenses cout << " Expense Summary Report \n\n"; cout << "Employee Id # of Expenses Expense Total Average Expense\n\n"; for(int i = 0; i < numemployees; i++) { cout << fixed << setprecision (2); // Find the total number of expenses for each employee totalnum += expensecounts [i]; // Calculate the total expense amounts for each employee totalexp += expenses [i]; // Calculate the average expense of each total expense avgexp = expenses [i] / expensecounts [i]; cout << setw(7) << i << setw(16) << expensecounts [i]; cout << setw(14) << " $ " << setw(7) << expenses [i]; cout << setw(11) << " $ " << setw(7) << avgexp << endl; if (expenses [i] < minexp) { minexp = expenses [i]; empidmin = i; } } cout << "\nTotals" << setw(17) << totalnum <<setw(13) << "$"; cout << setw(8) << totalexp << endl; cout << "\nCongratulations to employee number " << empidmin; cout << " who had the lowest total expense amount!"; } //------------------------------------------------------------------------------- // Main function //------------------------------------------------------------------------------- int main () { // --- Variables float expenses [MAXEMPLOYEES]; // tallies the expense amounts int expensecounts [MAXEMPLOYEES], // tallies the expense counts numemployees; // holds the actual number of employees // Get the actual number of employees cin >> numemployees; // First set the contents of both arrays to zero InitializeArrays (expenses, expensecounts, numemployees); // Next input the "expense slips" and tally them TallyExpenses (expenses, expensecounts, numemployees); // Then produce the report ReportExpenses (expenses, expensecounts, numemployees); cout << "\n\n"; return 0; }