Question
Write a C++ program which includes two functions that calculate unit conversions between a distance expressed in feet and inches , and in meters .
Write a C++ program which includes two functions that calculate unit conversions between a distance expressed in feet and inches, and in meters. The formulas for the unit conversions are:
1 inch = 0.0254 meters |
1 foot = 12 inches |
The program must meet the following requirements:
Requirements:
Throughout the program:
A distance can only be positive or zero (i.e. cant be negative).
A distance in feet and inches will consist of a whole number of feet, and a number (that can include a fraction) of inches that is less than 12.
A distance in meters will be a number that can include a fraction.
Write the function bodies for the two functions listed below:
// Converts meters to feet and inches, and sets the references parameters
// feet and inches to the result
void meters_to_feet_and_inches(double meters, int& feet, double& inches)
{
}
// Converts feet and inches to meters and returns the result double feet_and_inches_to_meters(int feet, double inches)
{
}
The function meters to feet and inches must only calculate the feet-and-inches value that is equivalent to its parameter meters, and set the values of its reference parameters to this calculated value.
The function feet and inches to meters must only calculate and value of meters that is equivalent to the sum of its parameters feet and inches, and return this calculated value.
In particular, these two functions must not contain any cin or cout statements.
In addition to the required functions listed above, you may use functions of your own design to organize your program if you want.
The program must display a menu of choices to the user, accept their selection from the menu and respond to it, then display the menu again, until the user chooses to quit.
The valid menu choices are the numbers 1, 2, and 3. If the user enters an invalid integer, the menu must be redisplayed. The program is only required to work if the menu choice is an integer.
If the user chooses to do a conversion, the corresponding conversion function listed above must be called as part of processing the users request, but getting the value to convert and displaying the result must be done outside of the conversion function (although you can write another function for this if you want).
For the measurements to be converted, the program must accept and convert numbers entered by the user with or without a fractional part (except for feet which doesnt have a fraction). The resulting converted values must be displayed in the format shown in the sample run below.
If the user enters a negative value for any distance, or a number of inches that isnt smaller than 12, then display a suitable message informing them of the valid range of values, and redisplay the menu, as shown in the sample run below.
A sample run of your program should look like:
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 1
Enter number of meters: 1
1.000 meters = 3 feet and 3.370 inches
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 2
Enter number of feet: 5
Enter number of inches: 2.7
5 feet and 2.700 inches = 1.593 meters
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 1
Enter number of meters: 3.8
3.800 meters = 12 feet and 5.606 inches
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 1
Enter number of meters: -4
This program doesnt convert negative distances.
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 2
Enter number of feet: 6
Enter number of inches: 14
To convert a distance, neither feet nor inches can be negative and inches must be less than 12.
Available choices:
1. Convert meters to feet and inches
2. Convert feet and inches to meters
3. Quit
Enter the number of your choice: 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started