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
|
#include<iostream>
using namespace std;
// Constant factor converting feet to meters: 3.28 feet = 1 meter
const double FTM_FACTOR = 0.304878048; // (1 / 3.28)
// TODO: Modify convertToMeters function declaration so that it is
// a "value returning" function instead of a void function.
void getFeetAndInches(int& ft, double& in);
double convertToMeters (int ft, double in);
void displayResults (int ft, double in, double m);
// ********************************************
int main()
{
// Declare program variables.
int feet;
double inches, meters;
getFeetAndInches(feet, inches);
// TODO: Modify convertToMeters function call statement
// as necessary for a value returning function.
convertToMeters(feet, inches);
displayResults(feet, inches, meters);
return 0;
}
// ********************************************
void getFeetAndInches(int& ft, double& in)
{
cout << "Enter feet: ";
cin >> ft;
cout << "Enter inches: ";
cin >> in;
}
// ********************************************
// TODO: Modify convertToMeters as necessary so that it is
// a value returning function intead of a void function
double convertToMeters(int ft, double in)
{
double m;
// convert feet to fractional feet
double fractionalFeet = double(ft);
// convert inches to feet, then add to fractional feet
fractionalFeet = fractionalFeet + (in / 12.0);
// return converted feet through reference parameter
m = fractionalFeet * FTM_FACTOR;
return m;
}
void displayResults(int ft, double in, double m)
{
// Display formatted output
cout << endl
<< ft << "'-" << in
<< "\" = "
<< m << " meter(s)."
<< endl;
}
|