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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
File: lab4.cpp
Author: Dennis Hensley
Description: This application is an ordering system for wood floors.
*/
#include<iostream>
using namespace std;
bool isValid(char floorType); //Returns if an invalid floor type is entered.
int calculateNumBoxes(int squareFeet); //Function that is used to calculate number of boxes.
void calculateReceipt(char floorType, int Num_Boxes, double& subtotal, double& tax,
double& total, double& downpayment); //Calculates tax, subtotal, total, and down payment.
void printReceipt(int Num_Boxes, double subtotal, double tax, double total, double
downpayment); //Prints number of boxes, subtotal, total, tax, and down payment.
const int SQ_FT_PER_BOX=30;
const double LAMINATE_COST=2.59;
const double ENGINEERED_COST=3.19;
const double WOOD_COST=3.99;
const double TAX=0.0925;
const double MAX_DOWN_PAYMENT=500;
//Declaring constants.
int main()
{
int Num_Boxes;
char floorType;
double subtotal;
double tax;
double total;
double downpayment;
int squareFeet;
cout<< "Welcome to Wood Floors R Us!\n";
//Print menu
cout<< "To order your flooring, type:\n";
cout<< "\tL:Laminate ($2.59/sq ft)\n";
cout<< "\tE:Engineered hardwood ($3.19/sq ft)\n";
cout<< "\tW:Solid wood ($3.99/sq ft)\n";
cout<< "\tQ:To quit/exit"<<endl;
//Prompt user for floor type
cout<< "Floor type: ";
cin>> floorType;
while (floorType!='Q' && floorType!='q')
{
isValid(floorType);
//If isValid returns true
if(isValid(floorType))
{
cout<< "Square feet required: ";
cin>>squareFeet;
//If user enters a negative square feet, print error message
while(squareFeet<=0)
{
cout<< "Square feet must be positive.\n";
cout<< "Square feet required: ";
cin>> squareFeet;
}
//Call functions
calculateNumBoxes(squareFeet);
calculateReceipt(floorType, Num_Boxes, subtotal, tax, total, downpayment);
printReceipt(Num_Boxes, subtotal, tax, total, downpayment);
}
//If isValid returns false...do this.
else
{
cout<< "Invalid floor type!";
cout<< "To order your flooring, type:\n";
cout<< "\tL:Laminate ($2.59/sq ft)\n";
cout<< "\tE:Engineered hardwood ($3.19/sq ft)\n";
cout<< "\tW:Solid wood ($3.99/sq ft)\n";
cout<< "\tQ:To quit/exit"<<endl;
//Prompt user again for floor type
cout<< "Floor type: ";
cin>> floorType;
}
//Ask user again for floortype and print menu
cout<< "To order your flooring, type:\n";
cout<< "\tL:Laminate ($2.59/sq ft)\n";
cout<< "\tE:Engineered hardwood ($3.19/sq ft)\n";
cout<< "\tW:Solid wood ($3.99/sq ft)\n";
cout<< "\tQ:To quit/exit"<<endl;
//Prompt user again for floor type
cout<< "Floor type: ";
cin>> floorType;
}
//Print Good-bye message
cout<< "Thankyou for your patronage!"<<endl;
return(0);
}
bool isValid(char floorType)
{
if(floorType=='E' || floorType=='e' || floorType=='L' || floorType=='l' ||
floorType=='W' || floorType=='w')
{
return(true);
}
else
{
return(false);
}
}
int calculateNumBoxes(int squareFeet)
{
int Num_Boxes; //Number of boxes user needs
Num_Boxes=squareFeet/30;
if(Num_Boxes%30!=0)
{
Num_Boxes++;
}
return(Num_Boxes);
}
void calculateReceipt(char floorType, int Num_Boxes, double& subtotal, double& tax,
double& total, double& downpayment)
{
if(floorType=='E' || floorType=='e')
{
subtotal=Num_Boxes*SQ_FT_PER_BOX*ENGINEERED_COST;
tax= subtotal*TAX;
total= subtotal + tax;
//Calculate downpayment
if(total< MAX_DOWN_PAYMENT)
{
downpayment=total;
}
else
{
downpayment= MAX_DOWN_PAYMENT;
}
}
if(floorType=='L' || floorType=='l')
{
subtotal=Num_Boxes*SQ_FT_PER_BOX*LAMINATE_COST;
tax= subtotal*TAX;
total= subtotal + tax;
//Calculate downpayment
if(total< MAX_DOWN_PAYMENT)
{
downpayment=total;
}
else
{
downpayment= MAX_DOWN_PAYMENT;
}
}
if(floorType=='W' || floorType=='w')
{
subtotal=Num_Boxes*SQ_FT_PER_BOX*WOOD_COST;
tax= subtotal*TAX;
total= subtotal + tax;
//Calculate downpayment
if(total< MAX_DOWN_PAYMENT)
{
downpayment=total;
}
else
{
downpayment= MAX_DOWN_PAYMENT;
}
}
}
void printReceipt(int Num_Boxes, double subtotal, double tax, double total, double downpayment)
{
//Set values two places to the right of the decimal
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Print receipt to user
cout<<"Number of Boxes:" <<Num_Boxes<< endl;
cout<<"Sub total:" <<subtotal<< endl;
cout<<"Tax (9.25%):" <<tax<< endl;
cout<<"Total:" <<total<< endl;
cout<<"Required downpayment:" <<downpayment<< endl;
}
|