Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++: Help with combining two programs: Hi. In my c++ class, I have made two programs that convert feet and inches entered by the user

c++: Help with combining two programs:

Hi. In my c++ class, I have made two programs that convert feet and inches entered by the user into meters(No centimeters, just meters), and a second one that does vice versa. Now I have to make a third program that combines the two programs, and I've hit a wall.

The question at hand:

Program # 4, Combination of Programs # 2 and # 3

  • This program will combine the functionality of the previous 2 programs. It will:
  • Ask the user if he or she wants to convert from feet and inches to meters or from meters to feet and inches.
  • The user responds by entering 1 to convert from feet and inches or 2 to convert from meters.
  • Your program will read the users selection and then execute an if else statement to where each branch will contain a call to an appropriate function which will then drive the rest of the application based on that selection.
  • You must use the following definition of main.The only modification to main should be the addition of the code to insure the user enters either 1 or 2 for the choice of conversion. You will build the rest of your program using the functions that you created in problems 2 and 3.

int main()

{

char ans; //loop control variable

int which; //stores the choice of conversion

do

{

//Add a loop here to insure that the user enters either 1 or 2

cout

cin >> which;

if (1 == which)

ConvertToMetric();//calls the ConvertToMetric functions

else

ConvertToEnglish();//calss the ConvertToEnglish functions

cout

cin >> ans;

} while ('y' == ans || 'Y' == ans);

return 0;

}

The two programs I've done: Project 2(Feet and Inches to Meters):

//Header file selection #include using namespace std; //function prototypes void input(double &feet, double &inches); void calculate(double feet, double inches, double &metersPerFoot, double &metersPerinch); void display(double metersPerFoot, double metersPerinch, double feet, double inches); int main() { //variable declaration double feet, inches, metersPerinch, metersPerFoot; char ans; do { cout //function call to input input(feet, inches); //function call to calculate calculate(feet, inches, metersPerFoot, metersPerinch); //function call to display display(metersPerinch, metersPerFoot, feet, inches); //inputting choice cout cin >> ans; } while (ans == 'y' || ans == 'Y'); return 0; }

void input(double &feet, double &inches) { //inputting feet cout cin >> feet; while (feet //This loop will repeat if the user enters feet less than 0. { cout cin >> feet; } //inputting inches cout cin >> inches; while (inches //This loop will repeat if the user enters inches less than 0. { cout cin >> inches; } } //End input //Calculating meters and cm void calculate(double feet, double inches, double &metersPerFoot, double &metersPerinch) { //convert the inches and feet to meters metersPerFoot = feet * 0.3048; metersPerinch = inches * 0.0254; }//end calculate void display(double metersPerinch, double metersPerFoot, double feet, double inches) { cout }//end display

And Project 3 (Meters to Feet and Inches):

//Header file selection #include using namespace std; //function prototypes void input(double &meters); void calculate(double &feet, double &inches, double meters); void display(double meters, double feet, double inches); int main() { //variable declaration double feet, inches, meters; char ans; do { cout //function call to input input(meters); //function call to calculate calculate(feet, inches, meters); //function call to display display(meters, feet, inches); //inputting choice cout cin >> ans; } while (ans == 'y' || ans == 'Y'); return 0; } void input(double &meters) { //inputting meters cout cin >> meters; while (meters //This loop will repeat if the user enters meters less than 0. { cout cin >> meters; } } //End input //Calculating meters and cm void calculate(double &feet, double &inches, double meters) { //convert the meters into feet and inches inches = meters * 39.37; while (inches > 12) { if (inches > 12) inches = inches - 12; feet++;

} }//end calculate void display(double meters, double feet, double inches) { cout }//end display

I'd appreciate any help in combining the two. Thank you in advance!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions