Code:
#include <iostream.h>
const int SIZE=10000;
void EMPID (int& EmployeeID);
void Trip (int &Trips);
void Mileage (int Trips, double Miles[SIZE],int EmployeeID, double COST,
double
&TOTAL_SUM, double & Total, double &Total_Miles, double A);
float Cost (int Trips, double Miles [SIZE], double & COST, double
TOTAL_SUM,double A);
void LINE ();
void LARGEST_TRIP (double COST, double & A);
float SMALLEST_TRIP (double COST);
void IndivResults (int Trips, double Miles[SIZE], double COST, double
TOTAL_SUM,
int EmployeeID, double Total, double A, double Total_Miles);
void Totals ();
void main ()
{
int EmployeeID;
EMPID(EmployeeID);
}
//-------------------------------------------------------------------
void EMPID (int& EmployeeID)
{
int Trips=0;
double Miles [SIZE];
double COST=0;
double TOTAL_SUM=0;
double Total=0;
double A=0;
double Total_Miles=0;
cout << "Employee ID or 0 to end program" << endl;
cin >> EmployeeID;
if (EmployeeID < 0)
{cout << "PLEASE ENTER A VALID EMPLOYEE ID NUMBER GREATER THAN 0." << endl;
cin >> EmployeeID;
}
if (EmployeeID==0)
{Totals();
}
if (EmployeeID >= 1)
{
Trip(Trips);
Mileage(Trips,Miles,EmployeeID,COST, TOTAL_SUM,Total,Total_Miles,A);
SMALLEST_TRIP (COST);
LARGEST_TRIP (COST,A);
LINE();
IndivResults (Trips, Miles, COST,
TOTAL_SUM,EmployeeID,Total,A,Total_Miles);
LINE();
}
}
//-------------------------------------------------------------------
void Trip (int &Trips)
{
cout << "Enter the Number of Trips ";
cin >> Trips;
if (Trips < 0)
{cout << "Trips must be greater than or equal to 0." << endl;
cin >> Trips;
}
}
//-------------------------------------------------------------------
void Mileage (int Trips, double Miles[SIZE],int EmployeeID , double COST,
double & TOTAL_SUM, double & Total, double &Total_Miles,double A)
{
for (int i=0; i < Trips; i++)
{
cout << "Enter the Mileage ";
cin >> Miles[i];
if (Miles[i] < 0)
{cout << "Mileage must be greater than or equal to 0." << endl;
cin >> Miles[i];
}
Total_Miles += Miles[i];
TOTAL_SUM = Miles[i];
Cost(Trips,Miles,COST,TOTAL_SUM,A);
cout << "Employee "<< EmployeeID << " Cost for the mileage of " << Miles[i]
<<
"is" << Cost(Trips,Miles,COST,TOTAL_SUM,A) << endl;
Total += COST;
}
}
//-------------------------------------------------------------------
float Cost (int Trips, double Miles [SIZE],double & COST, double
TOTAL_SUM,double A)
{
const float First_Range = 1;
const float Second_Range = 2000;
const float First_Rate= .12;
const float Second_Rate= .10;
const float Base_Charge = 2;
if ((TOTAL_SUM >= First_Range) && (TOTAL_SUM < Second_Range))
{COST = (First_Rate * TOTAL_SUM) + (Base_Charge);
}
if ((TOTAL_SUM >= Second_Range))
{COST = ((TOTAL_SUM - Second_Range) * (Second_Rate)) + (Second_Range *
First_Rate) + (Base_Charge);
}
return COST;
}
//-------------------------------------------------------------------
void LINE ()
{
cout << "---------------------------------------------" << endl;
}
//-------------------------------------------------------------------
void LARGEST_TRIP (double COST, double &A)
{
A=0;
if (COST >= A)
{
A=COST;
}
}
//-------------------------------------------------------------------
float SMALLEST_TRIP (double COST)
{
double B=1000000;
if (COST<= B)
{B=COST;
}
return B;
}
//-------------------------------------------------------------------
void IndivResults (int Trips, double Miles[SIZE], double COST, double
TOTAL_SUM,
int EmployeeID, double Total, double A, double Total_Miles)
{
cout.setf (ios::fixed);
cout.precision (2);
cout << "Total Cost for Employee "<< EmployeeID << " is " << Total
<<
endl;
cout << "Number of trips for employee " << EmployeeID<<" is
"<<Trips<<endl;
cout << "Average dollar trip for employee " << EmployeeID<< " is " <<
Total/Trips <<endl;
cout << "Average mileage trip for employee " << EmployeeID << " is "
<<Total_Miles/Trips <<endl;
cout << "The smallest charge is" << SMALLEST_TRIP(COST) << endl;
cout << "The largest dollar cost for employee " << EmployeeID << " is " <<
A
<< endl;
cout<<endl<<endl;
main();
}
//--------------------------------------------------------------------
void Totals ()
{
cout << "Total Cost for all employees is " << endl;
cout << "The total number of trips is " << endl;
cout << "The total miles for all the trips is" << endl;
cout << "The number of Employees is" << endl;
cout << "The average cost per employee is " << endl;
cout << "The average cost per trip is " << endl;
cout << "The average miles per trip is "<< endl;
cout << "The largest cost of an employee trip is "<<endl;
cout << "The smallest cost of an employee trip is " << endl;
}