Extra Credit Wiki- x(M Hold Notce-swaf/X Syllabus-201720( x xLab10.pdf rd.odu.ed
ID: 3735718 • Letter: E
Question
Extra Credit Wiki- x(M Hold Notce-swaf/X Syllabus-201720( x xLab10.pdf rd.odu.edu/bbcswebdav/pid. 6703685-dt-content-rid-78948205-2/courses/201 720-SPRNG-CS 150-22463/Lab 10.1 Task2 Write a program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. Use at least three functions one for input, one or more for calculating and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches in a foot Enter feet as an integer: Enter inches as a double: 7 the value of feet, inchess,7.00 converted to meters, centimeters is 1.70 Y or y continues, any other character quits Enter feet as an integer: 12 Enter inches as a double: 5 the value of feet, inches12,5.00 converted to meters, centimeters is 3.78 or y continues, any other character quits Process returned o (oxo) execution time : 90.692 s ress any key to continue. Sotes 1 You might ask your teaching assistance for help. 2, Save the source code tile asourli!«Name-Your Last Name-Labro-rask2 eppExplanation / Answer
Below is your code. I have added comments to help you understand it. Let me know in comments in case you find understanding any of this
#include <iostream>// for cout and cin
#include<iomanip> // for setprecision
using namespace std;
//Methods declarations
void userInput(int& feet, double& inches);
void conversion(int feet, double inches,double& metersAndCenti);
void output(int feet, double inches,double metersAndCenti);
//main method to run the program
int main()
{
//declaration of variables
int feet;
double inches, metersAndCenti;
//choice sets whether user wants to continue or not
char choice = 'y';
//do while loop to repeat till user quits
do {
//method call to take user input
userInput(feet, inches);
//method call to do the conversion
conversion(feet, inches, metersAndCenti);
//method call to print the output
output(feet, inches, metersAndCenti);
//asking user if wants to try again
cout<<"Y or y continues, any other character quits"<<endl;
cin>>choice;
} while(choice == 'y' || choice == 'Y'); // end do while
return 0;
}
//method to take userinpur - pass by reference
void userInput(int& feet, double& inches)
{
cout << "Enter feet as an integer: ";
cin >> feet;
cout << "Enter inches as a double: ";
cin >> inches;
}
//method to convert from feet/inches to metersAndCenti
void conversion(int feet, double inches,double& metersAndCenti)
{
double ftInMeter,inchToMet;
//First convert feet to meters and then inches to meters
ftInMeter = (double)feet*0.3048;
inchToMet = (inches /12.0);
inchToMet = inchToMet * 0.3048;
//values assignment pass by reference
metersAndCenti = ftInMeter + inchToMet;
}
//method to print the output
void output(int feet, double inches,double metersAndCenti)
{
//setprecision to only display 2 decimal places
cout << "The value of feet, inches " << feet << "," <<fixed<<setprecision(2)<< inches <<endl;
cout << " converted to meters, centimeters is " << metersAndCenti;
cout << " ";
}
Output
Enter feet as an integer: 5
Enter inches as a double: 7
The value of feet, inches 5,7.00
converted to meters, centimeters is 1.70
Y or y continues, any other character quits
y
Enter feet as an integer: 12
Enter inches as a double: 5
The value of feet, inches 12,5.00
converted to meters, centimeters is 3.78
Y or y continues, any other character quits
n
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.