Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.15.143.18
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/bmmassie/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bmmassie/prog6.cpp
//----------------------------------------------------------------
// Programming Assignment #6
// 
// Written by: B M Massie
//
// Purpose: To identify the employee's id number and the amount 
//          of the expense. Also to tally up number of expenses 
//          and the total expense amount for each employee using 
//          a table.
//----------------------------------------------------------------

#include <iostream>
#include <iomanip>
using namespace std;

const int MAXEMPLOYEES = 30;

//----------------------------------------------------------------
// InitializeArrays sets the contents of both arrays to zero
//----------------------------------------------------------------
// Accepts: the array of expenses, the array of expensecounts,
//           and the number of employees.
// Returns: Nothing 
//----------------------------------------------------------------

void InitializeArrays (float expenses[],int expensecounts[],int numemployees)
{
   int i;

   for(i = 0; i < numemployees; i++)
    {
     expenses[i] = 0;
     expensecounts[i] = 0;
    }
}
      
//-------------------------------------------------------------------
// TallyExpenses inputs the "expense slips" from the data file and  
// tallies then into the arrays.
//-------------------------------------------------------------------
// Accepts: the array of expenses, the array of expensecounts,
//           and the number of employees.
// Returns: Nothing
//-------------------------------------------------------------------

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

{
  int nuemployees,
      anid;
  
  float anexpense;
    
  cin >> anid;

  while (anid != -1)
  {
    cin >> anexpense;
  
    expensecounts[anid]++;
    expenses[anid]+= anexpense;  
   
    cin >> anid;
  } 
}
//--------------------------------------------------------------------
// ReportExpenses uses the arrays from TallyExpenses to produce an
// Expense Summary Report.
//--------------------------------------------------------------------
// Accepts: the array of expenses, the array of expensecounts, and
//          the number of employees.
// Returns: Nothing
//-------------------------------------------------------------------

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

{
 int 
     i,
     numexpenses = 0, // tallying number of expenses
     loempnum;        // lowest employee number
 float 
     loexp = 1000,  // lowest expense
     totalexp = 0,    // total expenses
     avgexpense;      // average expense


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

 for(i = 0; i < numemployees; i++)
   {
    if (expenses[i] < loexp)
     {
       loexp = expenses[i];
       loempnum = i;
     }

    avgexpense = expenses[i] / expensecounts[i];
    cout << fixed << setprecision(2);
    cout << endl;

    cout << setw(8) << i  << setw(15);
    cout << expensecounts[i];
    cout << "           $ " << setw(8) << expenses[i] << "          $" << setw(8) << avgexpense;
    
   
    numexpenses += expensecounts[i];
    
    totalexp += expenses[i];
   }

  cout << endl << endl;
  cout << "   Totals";
  cout << "     " << setw(9) << numexpenses;
  cout << "           $" << setw(9) << totalexp;

  cout << endl;
 
  cout << "\nCongratulations to employee number " << loempnum  << " who had the lowest total expense amount!" << endl;
}



int main ()
{

   int expensecounts[MAXEMPLOYEES],  // array for counting the expenses
       numemployees;                 // number of employees  

   float expenses[MAXEMPLOYEES];     // array for the expenses

   
   cin >> numemployees;

   InitializeArrays (expenses,expensecounts,numemployees);
   TallyExpenses (expenses,expensecounts,numemployees);
   ReportExpenses (expenses,expensecounts,numemployees);

   cout << endl;

   return 0;
}

Stv3n404 - 2023