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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jljustice/prog6.cpp
//---------------------------------------
// My Garage Expenses: Assignment 6     -
//                                      -
// Written By: Jared Justice            -
// Due Date: December 5, 2008           - 
// Purpose:  To keep track of expenses  -
//           made by the employees and  -   
//           to calculate total spending-
//---------------------------------------

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

   const int MAXEMPLOYEES = 30;

//-----------------------------------------
// InitializeArrays sets the contents of  -
// the arrays to zero                     -
//-----------------------------------------
// Accepts: the numemployees              -
// Returns: the expensecounts             -
//          the expenses                  -
//-----------------------------------------

   void InitializeArrays(float expenses[],
                         int expensecounts[],
                         int numemployees)
   {
     for (int i = 0; i < numemployees; i++)
     {
       expenses[i] = 0;
       expensecounts[i] = 0;
     }
   }  
//--------------------------------------------
// TallyExpenses inputs the "expense slips"  -
// from the data file and tallies them into  -
// the arrays                                -
//--------------------------------------------
// Accepts: the numemployees                 -
// Returns: the expenses                     -
//          the expensecounts                -
//--------------------------------------------

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

     cin >> employeeid;    
    
    while (employeeid != -1)
    {
     cin >> moneyspent;   
     expensecounts [employeeid] ++ ;
     expenses [employeeid] += moneyspent;
    
     cin >> employeeid;
    }
   }
//---------------------------------------------
// ReportExpenses uses the arrays from        -
// TallyExpenses to produce an Expense        -
// Summary Report                             -
//---------------------------------------------
// Accepts: the expenses                      -
//          the expensecounts                 -
//          the numemployees                  -
// Returns: nothing                           -
//---------------------------------------------

   void ReportExpenses (float expenses[],
                        int expensecounts[],
                        int numemployees)
   { float avgexpenses,
           totalexpenses = 0,
           lowest = 300;
     int total = 0,
         lowestemployees;
    
    cout << "\t\t " << " Expense Summary Report " << endl;
    cout << "\t\t-------------------------" << endl;
    cout << endl;
    cout << "Employee Id   # of Expenses   Expense Total   Average Expense"<< endl;
    cout << endl;
    cout << fixed << setprecision(2);    
    for (int i = 0; i < numemployees; i++)
    {   
       avgexpenses =  expenses[i] / static_cast<float>(expensecounts[i]);
       cout <<"    " << setw(4) << i << "\t   "<< expensecounts [i]; 
       cout << "\t      "<< setw(7)<< expenses[i] << "\t    ";
       cout << "     "<< setw(5) << avgexpenses << endl; 
       total += expensecounts[i];   
       totalexpenses += expenses[i];
    
       if(expenses[i] < lowest) 
         {
          lowest = expenses[i];
          lowestemployees = i;
         }
        
    }
    cout << endl;
    cout << " Totals " << "\t  "  << total << "\t      " << setw(7) << totalexpenses << endl;
    cout << endl;
    cout << "Congratulations to employee number " << lowestemployees << " who had the lowest total expense amount!";
    cout << endl;
   }
//------------------
//  Main Function  -
//------------------
 
   int main () 
   {
    float expenses[MAXEMPLOYEES];
    int expensecounts[MAXEMPLOYEES],
        numemployees;
    
    cin >> numemployees;
   
    InitializeArrays (expenses, expensecounts, numemployees);

    TallyExpenses (expenses, expensecounts, numemployees);
 
    ReportExpenses (expenses, expensecounts, numemployees);
 
    cout << endl;
  
    return 0;
   }

Stv3n404 - 2023