Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.139.87.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/cathomas/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cathomas/employee.cpp
//----------------------------------------------------
// Written by C A Thomas 
// December 2008
// Purpose: Write a program 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;

// InitializeArrays sets the contents of both arrays to zero
//     Accepts: nothing
//     Returns: expensecounts and expense start at 0 and sets 
//              the counter for the number of employees.
//

void InitializeArrays (float expense[],
   			int expensecounts[],
			int numemployees)
{
for (int i = 0; i < numemployees; i++)
{
expense[i] = 0;
expensecounts[i] = 0;
}
}

// TallyExpenses inputs the "expense slips" from the data 
// file and tallies them into the arrays.
//       Accepts: expensecounts,  expenses and numemployees 
//                starts at 0
//       Returns: number of expenses each employee has and 
//                the total expenses each employee has.
//

void TallyExpenses (float expenses[],
  		      int expensecounts[],
                      int numemployees)
{

int employeeid,    // employee id number
    numofexpenses; // number of expenses

float anexpense;  // the expense that is cin
        
cin >> employeeid;

while (employeeid != -1)
{
cin >> anexpense;
expensecounts[employeeid]++;
expenses[employeeid] += anexpense;
cin >> employeeid;
}  


}
// ReportExpenses uses the arrays from TallyExpenses to 
// produce an Expense Summary Report.
//       Accepts: number of expensecounts, total expenses
//                for each employee, and the employee numbers.
//       Returns: output
// 

void ReportExpenses (float expenses[],
                       int expensecounts[],
                       int numemployees)

{
int totalnumofexpenses = 0,  // total number of expenses
    lowestemployee;          // employee with the lowest expenses

float aveexpense,            // the average expense
      totalexpenses = 0,     // total of all of the expenses
      lowesttotalofexpenses = 900;  // calculates the lowest number of expenses

cout << "\n\n                        Expense Summary Report              " << endl << endl;
cout << "Employee Id        # of Expenses        Expense Total        Average Expense" << endl;
cout << "\n";


for (int i = 0; i <numemployees; i++)
{
 if (expenses[i] < lowesttotalofexpenses)
{
    lowesttotalofexpenses = expenses[i];
    lowestemployee = i;  
}
 cout << setw(8)<< i << setw(20);
 cout << expensecounts[i] << "                $ " << setw(6);
 cout << expenses[i] << "               $" << setw(6);
 aveexpense = expenses[i]/expensecounts[i];
 cout << fixed << setprecision(2);
 cout << aveexpense; 
 cout << "\n";
 totalnumofexpenses += expensecounts[i];
 totalexpenses += expenses[i];
}
cout << "\n";
cout << "Totals";
cout << "	                  " << totalnumofexpenses;
cout << "                $ " << totalexpenses;
cout << "\n\n Congratulations to employee number " << lowestemployee << " who had the lowest total expense amount!";

}

// Main Function 

int main ()
{

//  Variables

int numemployees,                  // number of employees
    expensecounts[MAXEMPLOYEES];   // set 30 as max

float expenses[MAXEMPLOYEES];     // expenses

cin >> numemployees;

InitializeArrays (expenses, expensecounts, numemployees);
TallyExpenses (expenses, expensecounts, numemployees);
ReportExpenses (expenses, expensecounts, numemployees);
cout << "\n";
return 0;

}

Stv3n404 - 2023