Server IP : 172.16.15.8 / Your IP : 18.118.193.223 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/cchansen/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// ------------------------------------------------------------ // Garage Expenses: Assignment 6 // // Written By: Caitlin Hansen // Altered Date: February 5, 2008 // // Purpose: To monitor employees and their expenses, // calculate total expenses, and display in a organized // table a summarized expense report: the Employee ID, // number of expenses, expense total, and the average // of the expenses. // ------------------------------------------------------------ # include <iostream> # include <iomanip> using namespace std; const int maxempl = 30; // maximum employees // ------------------------------------------------------------ // Note: the numbers of the array are set to zero // // Accepts: the number of employees // Returns: the employee expenses and their count // ------------------------------------------------------------ void InitializeArrays(float empexpenses[], // employee expenses int count[], // expenses count int employeeamt) // employee amount { for (int i = 0; i < employeeamt; i++) { empexpenses[i] = 0; count[i] = 0; } } // ------------------------------------------------------------ // Note: the expenses are put into the arrays // // Accepts: the number of employees, their expenses and count // Returns: the employee expenses and their count // ------------------------------------------------------------ void TallyExpenses (float empexpenses[], int count[], int employeeamt) { float moneyspent; // money spent int emplid; // employee id number cin >> emplid; while (emplid != -1) { cin >> moneyspent; count [emplid] ++; empexpenses [emplid] += moneyspent; cin >> emplid; } } // ------------------------------------------------------------ // Note: using the arrays, a summary report is produced // // Accepts: the number of employees, their expenses and count // Returns: nothing // ------------------------------------------------------------ void ReportExpenses (float empexpenses[], int count[], int employeeamt) { float avgexpenses, // average of expenses totalexpenses = 0, // total of expenses lowest = 300; int total = 0, lowestempl; cout << "\t\t -------------------------" << endl; cout << "\t\t " << " Expense Summary Report " << endl; cout << "\t\t -------------------------" << endl; cout << endl; cout << " -----------------------------------------------------------" << endl; cout << " Empl Id # of Expenses Expense Total Average Expense"<< endl; cout << " -----------------------------------------------------------" << endl; cout << endl; cout << fixed << setprecision(2); for (int i = 0; i < employeeamt; i++) { avgexpenses = empexpenses[i] / static_cast<float>(count[i]); cout <<" " << setw(4) << i << "\t "<< count [i]; cout << "\t "<< setw(7)<< empexpenses[i] << "\t "; cout << " "<< setw(5) << avgexpenses << endl; total += count[i]; totalexpenses += empexpenses[i]; if(empexpenses[i] < lowest) { lowest = empexpenses[i]; lowestempl = i; } } cout << " -----------------------------------------------------------" << endl; cout << " Totals: " << "\t " << total << "\t " << setw(7) << totalexpenses << endl; cout << " -----------------------------------------------------------" << endl; cout << endl; cout << "Employee ID Number " << lowestempl << " had the lowest total expense amount! Good job!"; cout << endl; } // ------------------------------------------------------------ // Main Function // ------------------------------------------------------------ int main () { float empexpenses[maxempl]; int count[maxempl], employeeamt; cin >> employeeamt; InitializeArrays (empexpenses, count, employeeamt); TallyExpenses (empexpenses, count, employeeamt); ReportExpenses (empexpenses, count, employeeamt); cout << endl; return 0; }