1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
//My function prototypes
bool getdata(double &length, double &width, double &customerDiscount , double &costPerSQ);
void calculate (double length, double width, double customerDiscount , double costPerSQ);
double calcInstall(double length, double width, double costPerSQ);
double calcSubTotal ( double installedPrice, double customerDiscount);
double calcTotaL( double subTotal);
void printResult( double length,double width,double customerDiscount, double installPrice, double costPerSQ, double subTotal, double total );
void printMeasurement (double length, double width);
void printCharges(double length,double width,double customerDiscount, double installPrice, double costPerSQ, double subTotal, double total );
const double LABOR= 0.35; // my constant variables
const double TAXRATE= 8.5;
ofstream outfile; //creates an output file
int main()
{
outfile.open ("output.txt"); //opens output file
if (!outfile.is_open()) { //check to see if file was opened
cout << endl << "ERROR:Unable to open file"<<endl;
system ("PAUSE");
exit(1);
}
double length, width, customerDiscount,costPerSQ;
while (getdata(length,width,customerDiscount,costPerSQ)) {
calculate (length,width,customerDiscount,costPerSQ);
} //end of while loop
system ("PAUSE");
outfile.close(); //closes out file
return 0;
} //end of main
//Function to get data that gets computed
/************************************************************************************/
bool getdata(double &length, double &width, double &customerDiscount , double &costPerSQ) {
cout << "Length of room (feet)? ";
cin >> length;
if (length == 0) {
return false;
}
cout << "Width of room(feet)? ";
cin >> width;
cout << "Customer discount (percent)? " ;
cin >> customerDiscount;
cout << "Cost per square foot (xxx.xx)? ";
cin >> costPerSQ;
return true;
}
//calls three function to do the calculations
/************************************************************************************/
void calculate (double length, double width, double customerDiscount , double costPerSQ) {
double installPrice = calcInstall(length,width,costPerSQ);
double subTotal = calcSubTotal(installPrice,customerDiscount);
double total= calcTotaL(subTotal);
printResult(length,width,customerDiscount,installPrice,costPerSQ,subTotal,total);
}
//Prints results with help from two other functions
/***********************************************************************************/
void printResult( double length,double width,double customerDiscount, double installPrice, double costPerSQ, double subTotal, double total ) {
cout <<" ---------------------CARPET STORE"<<endl;
cout <<" Owner"<<endl<<endl;
printMeasurement(length, width);
cout << endl;
printCharges( length, width,customerDiscount,installPrice,costPerSQ, subTotal, total );
cout << endl;
}
//calculated the install price
/***********************************************************************************/
double calcInstall(double length, double width,double costPerSQ) {
double area= length * width;
return area * costPerSQ + area * LABOR;
}
//calculated the subtotal
/**********************************************************************************/
double calcSubTotal(double installPrice, double customerDiscount) {
return installPrice * (1- customerDiscount/ 100);
}
//calculate the total
/**********************************************************************************/
double calcTotaL(double subTotal) {
return subTotal * ( 1 + TAXRATE /100);
}
//prints out the measurements data
/**********************************************************************************/
void printMeasurement (double length, double width) {
cout <<setw(30)<<"MEASUREMENT"<<endl<<endl;
cout <<" "<<setw(10)<<left<<"Length" <<setw(10)<<right<<setprecision(2)<<fixed<<length<<" feet\n";
cout <<" "<<setw(10)<<left<< "Width" <<setw(10)<<right<<setprecision(2)<<fixed<<width << " feet\n";
cout <<" "<<setw(10)<<left<<"Area"<<setw(10)<<right<<setprecision(2)<<fixed<<length * width << " square feet\n";
}
//prints out the charges data
/**********************************************************************************/
void printCharges(double length,double width,double customerDiscount, double installPrice, double costPerSQ, double subTotal, double total ) {
cout << " CHARGES\n\n";
cout <<setw(19)<<left<<"DESCRIPTION"<<setw(15)<<"COST/SQ.FT."<<setw(14)<<right<<"CHARGES/ROOM\n";
cout <<setw(19)<<left<<"Carpet"<< setw(10)<<right<<costPerSQ<<setprecision(2)<<fixed<<setw(14)<<right<< setw(10)<<"$" << length* width* costPerSQ<<endl;
cout <<setw(19)<<left<<"Labor "<<setw(10)<<right<<LABOR<<setprecision(2)<<fixed<<setw(14)<<right<< LABOR*length*width<<endl;
cout <<setw(19)<<left<<" --------"<<endl<<endl;
cout <<setw(19)<<left<<"INSTALLED PRICE"<<setw(24)<<right<<"$"<<installPrice<<endl;
cout <<setw(19)<<left<<"Discount"<<setw(10)<<right<<customerDiscount<<"%"<<setw(20)<<right<<installPrice*customerDiscount/100<<endl;
cout <<setw(19)<<left<<" --------"<<endl<<endl;
cout <<setw(19)<<left<<"SUBTOTAL"<<setw(24)<<right<<"$"<<subTotal<< endl;
cout <<setw(19)<<left<<"Tax"<<setw(28)<<right<< subTotal * TAXRATE / 100<< endl;
cout <<setw(19)<<left<<"TOTAL"<<setw(23)<<right<<"$"<<total<<endl;
}
/**********************************************************************************/
|