Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
const float labor = 0.35;
const float tax = 0.085;
void getData (int &length, int&width, int &discount, float &cost);
void calculate (int length, int width, int discount, float cost, float &totalLabor, float &totalCarpet, float &installation, float &subtotal, float &total, float &taxamount, float &discountamount);
void printResult(int length, int width,int discount,float cost,float totalLabor,float totalCarpet,float installation,float discountamount,float subtotal,float taxamount,float total);
int main ()
{
int length,width,discount;
float cost,totalLabor,totalCarpet,installation,subtotal,total,discountamount,taxamount;
getData(length,width,discount,cost);
calculate(length,width,discount,cost,totalLabor,totalCarpet,installation,subtotal,total,taxamount,discountamount);
printResult(length,width,discount,cost,totalLabor,totalCarpet,installation,discountamount,subtotal,taxamount,total);
system ("PAUSE");
return EXIT_SUCCESS;
}
void getData(int &length, int &width, int &discount, float &cost)
{
cout << "Length of the room (feet)? " << endl;
cin >> length;
cout << "Width of the room (feet)? " << endl;
cin >> width;
cout << "Customer discount (percent)? " << endl;
cin >> discount;
cout << "Cost per square feet (xxx.xx)? " << endl;
cin >> cost;
}
float calcInstall (int length, int width, float cost, float &totalLabor, float &totalCarpet)
{
totalLabor=length*width*labor;
totalCarpet=length*width*cost;
return totalLabor+totalCarpet;
}
float calcSubtotal (float installation,int discount,float &discountamount)
{
discountamount = installation*(discount/100);
return installation-discountamount;
}
float calcTotal (float subtotal,float &taxamount,float &total)
{
taxamount=subtotal*tax;
total=subtotal+taxamount;
return total;
}
void calculate (int length, int width, int discount, float cost, float &totalLabor, float &totalCarpet, float &installation, float &subtotal, float &total, float &taxamount, float &discountamount)
{
installation=calcInstall(length,width,cost,totalLabor,totalCarpet);
subtotal=calcSubtotal(installation,discount,discountamount);
total=calcTotal(subtotal,taxamount,total);
}
void printMeasurement (int length,int width)
{
cout<<" THE BROOKLYN COLLEGE CARPET STORE" << endl;
cout <<" ABDOOL RAHEEM, Owner" <<endl << endl << endl;
cout <<" MEASUREMENT" << endl << endl;;
cout << right << setw(35) << "Length" << setw(10) << length << left << setw(34)
<<" feet" << endl;
cout << right << setw(35) << "Width" << setw(10) <<width << left << setw(34)
<< " feet" << endl;
cout << right << setw(35) << "Area" << setw(10) << length * width << left
<< setw(34) <<" square feet" << endl << endl << endl;
}
void printCharges(float cost,float totalCarpet,float totalLabor,float installation,int discount,float discountamount,float subtotal,float taxamount,float total)
{
cout <<" CHARGES"<<endl<<endl;
cout << left << setw(20) << "DESCRIPTION" << right << setw(20)
<< "COST/SQ FT" << setw(20) << "CHARGE/ROOM" << endl;
cout << left << setw(20) << "Carpet" << right << setw(20)<< fixed
<< setprecision(2) << cost << setw(20)
<< setprecision(2) << totalCarpet << endl;
cout << left << setw(20)<< "Labor" << right << setw(20) << "0.35"
<< setw(20) << setprecision(2) << totalLabor << endl << endl;
cout << left << setw(20) << "INSTALLED PRICE" << right << setw(20)
<< "" << setw(20) << setprecision(2) << installation << endl;
cout << left << setw(20) << "Discount" << right << setw(20) << ""
<< setw(20) << setprecision(2) << discountamount << endl;
cout << right << setw(60) << "----------" << endl;
cout << left << setw(20) << "Sub Total" << right << setw(20) << ""
<< setw(20) << setprecision(2) << subtotal << endl;
cout << left << setw(20) << "Tax" << right << setw(20) << "" << setw(20)
<< setprecision(2) << taxamount << endl;
cout << left << setw(20) << "Total" << right << setw(20) << "" << setw(20)
<< setprecision(2) << total << endl;
}
void printResult(int length, int width,int discount,float cost,float totalLabor,float totalCarpet,float installation,float discountamount,float subtotal,float taxamount,float total)
{
printMeasurement (length,width);
printCharges (cost,totalCarpet,totalLabor,installation,discount,discountamount,subtotal,taxamount,total);
}