Server IP : 172.16.15.8 / Your IP : 3.133.117.113 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/kmmowery/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//---------------------------------------------------------------------- // // Name: Kieara Mowery // Due : Friday, December 5th // Date: Monday, December 1st // Purpose: To help the company tally their employee // expense data and produce an Expense summary report. // //---------------------------------------------------------------------- #include <iostream> #include <iomanip> using namespace std; const int MAXEMPLOYEES = 30; //--------------------------------------------------------------- // Initialize Arrays: Sets the contants of both arrays to zero. //--------------------------------------------------------------- // Accepts: The expenses of each employee. // Returns: The expense counts // The expenses //--------------------------------------------------------------- void InitializeArrays (float expenses[], int expensecounts[], int numemployees) { for ( int i = 0; i < numemployees; i++ ) { expensecounts[i] = 0; expenses[i] = 0; } } //--------------------------------------------------------------- // TallyExpenses: Inputs the "expense slips" from the data file // and tallies them into the arrays. //--------------------------------------------------------------- void TallyExpenses ( float expenses[], int expensecounts[], int numemployees) { int employeeid, numofexpense; float anexpense; cin >> employeeid; while ( employeeid != -1 ) { cin >> anexpense; expensecounts[employeeid]++; expenses[employeeid] += anexpense; cin >> employeeid; } } //--------------------------------------------------------------- // ReportExpenses: Uses the arrays from the TallyExpenses to // Produce an Expense Summary Report. //--------------------------------------------------------------- // Accepts: The expenses // The expense counts // The number of employees // Returns: Nothing until called in Main. //--------------------------------------------------------------- void ReportExpenses ( float expenses[], int expensecounts[], int numemployees) { int totalnumexp = 0, minid, employeeid; float avgexpense, minexp = 50000, totalexp = 0; cout << "\n Expense Summary Report"; cout << "\n\n"; cout << " Employee ID # of Expenses Expense Total Average Expense"; cout << endl; for ( int i = 0; i < numemployees; i++ ) { cout << "\n" << setw(12) << i; cout << fixed << setprecision(2); cout << setw(22) << expensecounts[i]; cout << setw(16) << "$" << setw(10) << expenses[i]; totalexp += expenses[i]; totalnumexp += expensecounts[i]; avgexpense = expenses[i] / expensecounts[i]; cout << setw(10) << " $" << setw(10) << avgexpense; if ( expenses[i] < minexp ) { minexp = expenses[i]; minid = i; } } cout << "\n\n"; cout << setw(12) << "Totals" ; cout << setw(22) << totalnumexp; cout << setw(16) << "$" << " " << totalexp; cout << "\n\n " << "Congratulations to employee number " << minid; cout << " for having the lowest expenses! "; } //--------------------------- // Main Function //--------------------------- int main () { // ---- Variables int numemployees, // Employees to be input. expensecounts[MAXEMPLOYEES]; // The number of expenses. float expenses[MAXEMPLOYEES]; // The expenses of each employee. // ---- Get the number of employees cin >> numemployees; // ---- First Initialize the Arrays and find the total. InitializeArrays ( expenses, expensecounts, numemployees ); // ---- Tally Expenses TallyExpenses ( expenses, expensecounts, numemployees ); // ---- Produce the Expenses Report ReportExpenses ( expenses, expensecounts, numemployees ); cout << "\n\n"; return 0; }