Server IP : 172.16.15.8 / Your IP : 3.129.216.15 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/mrlong/../dobutler/../drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//-------------------------------------------------------------------------------------------------- // Dale Sparks // Due Date: December 5, 2008 // // This project was created to produce a report that will sort employees by number, calculate // the number of expenditures each has, calculate the total number of expenses, to calculate // the average amount spent by each employee, and to calculate who spent the lowest amount of // money. //-------------------------------------------------------------------------------------------------- #include <iostream> #include <iomanip> #include <cmath> using namespace std; const int MAXEMPLOYEERS = 30; //-------------------------------------------------------------------------------------------------- // InitializeArrays presets all of the arrays to zero. //-------------------------------------------------------------------------------------------------- // Accepts: array for expenses from each employee // array for number of expenses from each employees // number of employees // Returns: nothing //-------------------------------------------------------------------------------------------------- void InitializeArrays (float expenses[], int expensecounts[], int numemployees) { for (int i=0; i < numemployees; i++) { expenses[i] = 0; expensecounts[i] = 0; } } //-------------------------------------------------------------------------------------------------- // TallyExpenses count the number of purchases by each employee and calculates the total amount // that each employee spends. //-------------------------------------------------------------------------------------------------- // Accepts: array for expenses from each employee // array for number of expenses from each employees // number of employees // Returns: expenses of each employee // total number of expenses for each employee //-------------------------------------------------------------------------------------------------- void TallyExpenses (float expenses[], int expensecounts[], int numemployees) { int employnum; // used to input employee numbers float expense; // used to input expenses by employees cin >> employnum; cin >> expense; while (employnum != -1) { expensecounts[employnum]++; expenses[employnum] += expense; cin >> employnum; cin >> expense; } } //-------------------------------------------------------------------------------------------------- // ReportExpenses calculates the average and the lowest amount spent by an employee. It also // produces the output for the report. //-------------------------------------------------------------------------------------------------- // Accepts: expenses from each employee // number of expenses from each employees // number of employees // Returns: nothing //-------------------------------------------------------------------------------------------------- void ReportExpenses (float expenses[], int expensecounts[], int numemployees) { int lowest; // used to determine which employee spent the least int count = 0; // total number of purchases made by all employees float expense; // total amount spent by all employees float low = 999; // lowest amount of the individual employees float average; // average cout << "\n Expense Summary Report \n" << endl; cout << "Employee ID # of Expenses Expenses Total Average Expense" << endl << endl; cout << fixed << setprecision(2); for (int i=0; i < numemployees; i++) { if (expenses[i] < low) { lowest = i; low = expenses[i]; } average = expenses[i] / expensecounts[i]; count += expensecounts[i]; expense += expenses[i]; cout << " " << setw(2) << i << " " << setw(3) << expensecounts[i]; cout << " $" << setw(8) << expenses[i] << " $" << setw(7); cout << average << endl; } cout << "\nTotals " << count << " $"; cout << setw(8) << expense << endl; cout << "\nCongratulations to employee number " << lowest; cout << " who had the lowest total amount!\n\n"; } int main ( ) { int expensecounts[MAXEMPLOYEERS], // number of purchase for each employee numemployees; // number of employees float expenses[MAXEMPLOYEERS]; // amount spent by each employee cin >> numemployees; InitializeArrays (expenses, expensecounts, numemployees); TallyExpenses (expenses, expensecounts, numemployees); ReportExpenses (expenses, expensecounts, numemployees); return 0; }