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
|
#include<iostream>
#include<cmath>
const double FEET = 3.2808;
const double METER = 0.3048;
using namespace std;
void instruction();// Tells user how to operate program
void menu();//List the possible selection choices
void getFeet(double&);//Gets number of feet to converts to meters
void giveFeet(double, double);//Displays the converted output
void getMeters(double&);//Gets number of meters to converts to feet
void giveMeters(double, double);//Displays the converted output
void getSqFt(double&, double&);//Gets dimensions from user in feet to convert into meters
void giveSqFt(double, double, double, double, double, double);//Displays the square feet converted to meters
void getSqM(double&, double&);//Gets dimensions from user in meters to convert into feet
void giveSqM(double, double, double, double, double, double);//Displays the square meters converted to feet
double convertFt(double, double);//Conducts the conversion
double convertM(double, double);//Conducts the conversion
double conSqFt(double, double, double, double);//Conducts the conversion
double conSqM(double, double, double, double);//Conducts the conversion
int main()
{
instruction();
int selection;
char exitLoop;
double amount, meters, conversion, quantity, feet, change, sqFt, lengthFt_M, lengthM_Ft;
double lengthFt, widthFt, areaFt, areaM, lengthM, widthM, sqM, widthFt_M, widthM_Ft;
do
{
do
{
menu();
cin >> selection;
selection = toupper (selection);
if(selection < 1 || selection > 5)
cout << "That is not a valid choice." <<endl;
}
while(selection != 1 && selection != 2 && selection != 3 && selection != 4 && selection != 5);
if (selection == 1)
{
getFeet(amount);
convertFt(amount, meters);
giveFeet(amount, conversion);
}
else if (selection == 2)
{
getMeters(quantity);
convertM(quantity, feet);
giveMeters(quantity, change);
}
else if(selection == 3)
{
getSqFt(lengthFt, widthFt);
conSqFt(lengthFt, widthFt, areaFt, meters);
giveSqFt(lengthFt, widthFt, areaFt, areaM, lengthFt_M, widthFt_M);
}
else if (selection == 4)
{
getSqM(lengthM, widthM);
conSqM(lengthM, widthM, sqM, feet);
giveSqM(lengthM, widthM, sqM, sqFt, lengthM_Ft, widthM_Ft);
}
else if (selection == 5)
{
cout << "Are you sure you would like to exit this program? (Y = yes, N = no)" << endl;
cin >> exitLoop;
}
}
while(exitLoop != 'Y' || exitLoop != 'y');
}
void instruction()
{
cout << "This program allows users to convert measurements\n"
<< "from feet to meters and meters to feet. Please\n"
<< "select an option from the main menu.\n"
<< " "<< endl;
}
void menu()
{
cout << "English-Metric Junior" << endl;
cout << "1) Convert from feet to meters." << endl;
cout << "2) Convert from meters to feet." << endl;
cout << "3) Convert the area of a rectangle in square feet to the area in square meters." << endl;
cout << "4) Convert the area of a rectangle in square meters to the area in square feet." << endl;
cout << "5) Quit the program." << endl;
cout << "Please enter the number that corresponds to the option you would like (1-5)." << endl;
}
void getFeet(double& amount)
{
cout << "Enter the distance in feet you wish to convert." << endl;
cin >> amount;
}
double convertFt(double amount, double meters)
{
double amnt, METERS, resultFt;
resultFt = amnt * METERS;
return resultFt;
}
void giveFeet(double amount, double conversion)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);
cout << amount << " feet is equal to " << conversion << " meters!" << endl;
}
void getMeters(double& quantity)
{
cout << "Enter the distance in meters you wish to convert." << endl;
cin >> quantity;
}
double convertM(double quantity, double feet)
{
double qty, FEET, resultM;
resultM = qty * FEET;
return resultM;
}
void giveMeters(double quantity, double change)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);
cout << quantity << " meters is equal to " << change << " feet!" << endl;
}
void getSqFt(double& lengthFt, double& widthFt)
{
cout << "Enter the length in feet." << endl;
cin >> lengthFt;
cout << "Enter the width in feet." << endl;
cin >> widthFt;
}
double conSqFt(double lengthFt, double widthFt, double areaFt, double meters)
{
double lFt, wFt, sqFt, METERS, resultSqFt;
resultSqFt = ((lFt * METERS) * (wFt * METERS));
return resultSqFt;
}
void giveSqFt(double lengthFt, double widthFt, double areaFt, double areaM,double lengthFt_M, double widthFt_M)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);
cout << "A length of " << lengthFt << " feet and width of " << widthFt << " feet produces an area of " << areaFt << " square feet."
<< "The converted length is " << lengthFt_M << " meters and the converted width is " << widthFt_M << " meters which produces an area of " << areaM << " square meters." << endl;
}
void getSqM(double& lengthM, double& widthM)
{
cout << "Enter the length in meters." << endl;
cin >> lengthM;
cout << "Enter the width in meters." << endl;
cin >> widthM;
}
double conSqM(double lengthM, double widthM, double sqM, double feet)
{
double lM, wM, resultSqM, FEET;
resultSqM = ((lM * FEET) * (wM * FEET));
return resultSqM;
}
void giveSqM(double lengthM, double widthM, double sqM, double sqFt, double lengthM_Ft, double widthM_Ft)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);
cout << "A length of " << lengthM << " meters and width of " << widthM << " meters produces an area of " << sqM << " square meters."
<< "The converted length is " << lengthM_Ft << " feet and the converted width is " << widthM_Ft << " feet which produces an area of " << sqFt << " square feet." << endl;
}
|