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 192 193 194 195 196 197 198 199 200 201 202 203
|
Purpose: Convert between meters/centimeters and feet/inched at user's option.
*/
#include "pch.h"
#include <iostream>
#include <sstream>
using namespace std;
const double meters_per_foot = 0.3048;
const double inches_per_foot = 12.0;
const double centimeters_per_meter = 100.0;
// needed to organize functions for input, processing, and outputting.
void input_M (int& meters, double& centimeters); //placing in metric
void input_E(int& feet, double& inches); // placing in English
void convert_E_to_M(int feet, double inches, int& meters, double& centimeters);
void convert_M_to_E(int& feet, double& inches, int& meters, double centimeters);
void convert_M_to_E(int & feet, double & inches, int meters, double centimeters);
void output(int feet, double inches, int meters, double centimeters);
void E_TO_M(); //English measure, converts to metric, outputs both
void M_to_E(); //metric measure, converts to english, will output
int main()
//calls: English_to_metric(), Metric_to_English()
{
int choose; //choose which conversion em - for english to metric, me - for metric to english
char ; //user will be asked if they want to go through loop once more
void Metric_to_English();
void English_to_Metric();
cout << "This program will convert the feet and inches to meters and centimeters\n" << endl;
cout << "the conversion can also convert meters and centimeters to feet and inches." << endl;
do
{
cout << "\nEnter 1 for english to metric or\n"
<< "Enter 2 for metric to english conversion\n";
cout << "you choose:";
cin >> choose;
if (choose == 1)
English_to_Metric();
else if (choose == 2)
Metric_to_English();
else
cout << "\n\a" << choose << "is not accurate. " << endl;
cout << "\n Would you like to do another conversion of another sort (Y/N)?";
cin >> choose;
} while (choose == 'y' || choose == 'Y');
cout << "\nConversion Completed. Thank you" << endl;
return 0;
//end of english to metric, metric to english
}
void English_to_metric()
//Parameter: zero
//Returns: zero
//Calls: Input_E(), convert_E_to_M, output()
{
int feet, meters;
double inches, centimeters;
char choose;
do
{input_E(feet, inches);
convert_E_to_M(feet, inches, meters, centimeters);
output(feet, inches, meters, centimeters);
cout << "\nWould you like to do another English to metric conversion (Y/N) ?";
cin >> choose;
} while (choose == 'y' || choose == 'Y');
} //end of English_to_Metric()
void Metric_to_english()
#include <sstream>
//parameters:zero
//Returns: zero
//Calls : input_M(), convert_Mto_E(), output()
{
int feet, meters;
double inches, centimeters;
char choose;
int inputme(meters, centimeters);
int convert_m_to_e(feet, inches);
do
{
inputme(meters, centimeters);
convert_m_to_e(feet, inches, meters, centimeters);
output(feet, inches, meters, centimeters);
cout << "\nWould you like to do another metric to English conversion (Y/N)?";
cin >> choose;
} while (choose == 'y' || choose == 'Y');
} // End of metric_to_english()
void input_e(int& feet, double& inches)
//Parameters: Variables that mean feet and inches
//Returns:zero
//Calls:none
{
cout << "\nEnter feet as an integer:";
cin >> feet;
cout << "Enter inches as a double:";
cin >> inches;
} // Executed input_E()
void input_M(int& meters, double& centimeters)
//parameters: is referred to variables that mean meters and centimeters
//returns:zero
//calls:zero
{
cout << "\nEnter meters as an integer:";
cin >> meters;
cout << "Enter of centimeters as a double:";
cin >> centimeters;
} //executed input_M()
void input_E(int & feet, double & inches)
{
}
//convert english measure to metric
void convert_E_to_M(int feet, double inches, int& meters, double& centimeters)
//parameters:feet and inches valued to be converted to meters and centimeters
//returns: zero
//calls: zero
{
double total_feet;
double total_meters;
double INCHES_PER_FOOT;
double METERS_PER_FOOT;
double CENTIMETERS_PER_METER;
total_feet = feet + inches / INCHES_PER_FOOT;
total_meters = METERS_PER_FOOT * total_feet;
meters = int(total_meters);
centimeters = (total_meters - meters) * CENTIMETERS_PER_METER;
} //Execution of converting_E_to_M()
void convert_M_to_E(int & feet, double & inches, int & meters, double centimeters)
{}
//convert metric to english measure
void convert_M_to_E(int& feet, double& inches, int meters, double centimeters);
double CENTIMETERS_PER_METER;
double METERS_PER_FOOT;
double INCHES_PER_FOOT;
//parameters: Meters and centimeters values to be converted to feet and inches
//and references to variables that mean feet and inches
//returns: zero
//calls:zero
{ double total_feet;
double total_meters;
total_meters = meters + centimeters / CENTIMETERS_PER_METER;
total_feet = total_meters / METERS_PER_FOOT;
feet = int(total_feet);
inches = (total_feet - feet) * INCHES_PER_FOOT;
} //executed to convert_M_to_E()
void output(int feet, double inches, int meters, double centimeters)
//parameters: feet and inches values and equivalent meters and centimeters values
//returns:zero
//calls:zero
{cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.precision(1);
cout << "\n" << meters << " meters and " << centimeters << " centimeters "
"corresponds to\n" << feet << " feet and " << inches << " inches." << endl;
} // End of output()
void E_TO_M()
{
"\nenglish_to_metric";
}
void M_to_E()
{
"\nMetric_to_English";
}
return 0;
}
|