|
|
|
© 1998 by Bobby Griggs.
// Program name: Tree service
// Purpose: To compute a bid for a tree service.
// Win32 console application
#include < iostream.h >
#include < iomanip.h >
#include "myprocs.h"
void Input_info(int &r,double &t,int &g);
void Calculate_bid(int r,double t,int g,double &rc,double &tc,double &gc);
void Display_bid(double rc,double tc,double gc);
const double REMOVAL = 500.00;
const double TRIM = 80.00;
const double STUMP = 25.00;
const double STUMP_EXTRA = 2.00;
const DIAMETER = 10;
const double DISCOUNT = 0.10;
void main()
{
int tree_removal,stump_grind;
double trim_hours,removal_cost,trim_cost,grind_cost;
bool doagain = true;
while (doagain)
{
Input_info(tree_removal,trim_hours,stump_grind);
Calculate_bid(tree_removal,trim_hours,stump_grind,
removal_cost,trim_cost,grind_cost);
Display_bid(removal_cost,trim_cost,grind_cost);
doagain = Again();
}
}
void Input_info(int &r,double &t,int &g)
{
cout << "Bid for Orlando Tree Service, Inc." << endl << endl;
cout << "Enter number of trees to remove ... ";
cin >> r;
cout << endl;
cout << "Enter hours to trim trees ... ";
cin >> t;
cout << endl;
cout << "Enter number of stumps to grind ... ";
cin >> g;
cout << endl;
return;
}
void Calculate_bid(int r,double t,int g,double &rc,double &tc,double &gc)
{
int i,d;
rc = r * REMOVAL;
tc = t * TRIM;
cout << "As prompted, enter diameter of " << g << " stumps.";
cout << endl << endl;
gc = STUMP * g;
for (i = 1;i <= g;i++)
{
cout << "Diameter: ";
cin >> d;
if (d > DIAMETER)
gc = gc + ((d - DIAMETER) * STUMP_EXTRA);
}
cout << endl << endl << endl;
return;
}
void Display_bid(double rc,double tc,double gc)
{
double total;
cout << setiosflags(ios::fixed|ios::right) << setprecision(2);
cout << "The bid is" << endl << endl;
cout << "Tree removal: $" << setw(8) << rc << endl;
cout << "Tree trimming: $" << setw(8) << tc << endl;
cout << "Stump grinding: $" << setw(8) << gc << endl << endl;
total = rc + tc + gc;
if (total > 1000.00)
{
setprecision(0);
cout << DISCOUNT << setprecision(2);
cout << " discount: $" << setw(8) << total * DISCOUNT;
cout << endl << endl;
total = total * (1 - DISCOUNT);
}
cout << "Total cost: $" << setw(8) << total << endl << endl;
return;
}
|