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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void welcome();
void getInfo (string &, string &);
int selectShape();
void getLenWid(double &, double &);
double calcSqFeet(double, double);
double getDiam();
double calcSqFeet(double);
int selectFloorGrade();
double calcTotalPrice (int, double);
void displayEstimate(string, string, double, int, double);
void goodBye();
const double PI = 3.14;
double STANDARD = 41.50;
double PREMIUM = 63.75;
// function main
int main()
{
string answer;
string name = " ", phoneNum = " ";
double length, width, diameter, squareFeet, total;
int shape, grade;
cout << setprecision(2) << fixed << showpoint;
welcome(); // calls the welcome function
getInfo(name, phoneNum); // calls the getInfo function
do
{
cout <<"\t\t\tEstimates" << endl << endl;
shape = selectShape(); // calls selectShape function
if (shape == 1)
{
getLenWid(length,width); // floor size
squareFeet = calcSqFeet(length, width); // square feet
}
else
{
diameter = getDiam();
squareFeet = calcSqFeet(diameter);
}
grade = selectFloorGrade();
total = calcTotalPrice(grade,squareFeet);
cout << "Would you like to do another estimate [Y or N]?: ";
cin >> answer;
} while (answer == "y" || answer == "Y"); // trap
goodBye();
return 0;
}
// function definition (welcomes the user)
void welcome()
{
cout << "\t\tWelcome to Carters Concrete Suppliers" << endl;
cout << "\t\tServing the California area since 1930" << endl << endl;
}
// function definition (obtains user name & number)
void getInfo (string& name, string& phoneNum)
{
cout << "Please enter your name: " << endl;
cin >> name;
cout << "Please enter your phone number (ex: 000.000.0000): " << endl;
cin >> phoneNum;
}
// function definition (asks user shape of the floor)
int selectShape()
{
int num;
do{
cout << "\t\t\tEstimate" << endl << endl;
cout << "To describe the shape of the floor, please select 1 or 2: " << endl;
cin >> num;
cout << "1. Rectangular" << endl;
cout << "2. Circular" << endl << endl;
cout << "Selection: " << num << endl << endl;
}while (num != 1 && num!= 2);
return num;
}
// function definition (gets the floor's length & width)
void getLenWid (double &length, double &width)
{
do
{
cout << "Please enter the length of your floor" << endl;
cout << "\t(rounding up to the nearest half foot. ex: 10.5): " << endl << endl;
cin >> length;
}
while (length >0);
do
{
cout << "Please enter the width of your floor" << endl;
cout << "\t(rounding up to the nearest half foot. ex: 10.5): " << endl << endl << endl;
cin >> width;
}
while (width >0);
}
// function definition (sq footage calculator)
double calcSqFeet (double length, double width)
{
return length * width;
}
double getDiam()
{
double diameter;
do
{
cout << "Please enter your diameter: " << endl;
cout << "\t(rounding up to the nearest half foot. ex: 10.5): " << endl << endl;
cin >> diameter;
} while (diameter >=0);
return diameter;
}
double calcSqFeet (double diameter)
{
return (PI*(diameter/2)*(diameter/2));
}
int selectFloorGrade()
{
int grade;
cout << "There are 2 grades of floor that are avaliable." << endl;
cout << "All prices are based on square feet and includes all materials and labor." << endl << endl;
cout << "1. Standard grade\t\t4 inches thick\t\t$41.50 per sq foot" << endl;
cout << "2. Premium grade\t\t6 inches thick\t\t$63.75 per sq foot" << endl << endl;
cout << "To select your type of floor, please select 1 or 2: ";
cin >> grade;
return grade;
}
double calcTotalPrice(int grade)
{
double finalPrice;
if(grade == 1)
{
finalPrice = STANDARD * squareFeet;
}
else if ((grade = 2))
{
finalPrice = PREMIUM * squareFeet;
}
return finalPrice;
}
void displayEstimate (string &name, string &phoneNum, double squareFeet, int grade, double finalPrice)
{
cout << "Estimate: " << endl;
cout << "Customer Name: "<< name << endl;
cout << "Phone Number: "<< phoneNum << endl;
cout << "Square Feet : $" << squareFeet << endl;
if (grade == 1)
{
cout << "Floor Grade: Standard\tPrice per sqaure foot " << STANDARD;
}
else if (grade == 2)
{
cout << "Floor Grade: Premium\tPrice per sqaure foot " << PREMIUM;
}
cout << "\t Total Cost: $" << finalPrice;
cout << "Date: Jan 1, 2037" << endl;
cout << "This estimate is valid for 30 days from the date above. ";
}
void goodBye()
{
cout << "\tThank you for visiting Carters Concrete Suppliers";
cout << "Please call 123-456-7890 to schedule an on-site appointment." << endl;
|