Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We will make a simple, menu-driven conversion software package, called English-M

ID: 3851224 • Letter: W

Question

We will make a simple, menu-driven conversion software package, called English-Metric Converter. Our software package will present the user with a menu of choices and execute the operation specified. The menu must look exactly like this:

English-Metric Converter
1) Convert from feet to meters
2) Convert from meters to feet
3) Compute area of a rectangle in square feet given length and width in meters
4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet
5) Quit the Program
Please enter a number (1-5) ->

Implementation Notes:
1. You will create a function named menu() that will be called repeatedly from a loop in main().
2. Function int menu() will show the alternatives as above and take user input (1 - 5), until a number on that range is entered. It will then return the legal user choice.
3. Inside a loop in main(), the program will repeatedly call menu(). When menu() returns a legal selection, code in main() will get all necessary inputs from the user, call the function that computes the result, and displays output.
4. The feet-to-meters and meters-to-feet functions should have one parameter (the input value) and a return value (the converted length). This means that you must get the length to be converted BEFORE calling the conversion function. Note that there are 0.3048 meters in a foot.
5. For the area problem, you are to get the length and width of the rectangle in meters, and pass them to a function. Inside the function, convert length and width to the new units using the other functions you have created for that purpose, and compute the area. Return the area to the caller. the caller will output the length, width, and area in meters and the area in square feet, properly labeled. Follow a similar approach for the volume problem (but obviously, with three parameters).
6. We will NOT know how many times the user will want to execute a function from the menu.

Explanation / Answer

Code:

#include <stdio.h>

#include <math.h>

/* function declaration */

int menu();

float feet_to_metres(float);

float metres_to_feet(float);

float area_of_rect(float, float);

float rect_volume(float, float, float);

int main()

{

int option;

float feet, metres, length, width, height;

while(1){

option = menu();

if(option == 1){

printf(" Enter a number in feet to convert to metres: ");

scanf("%f", &feet);

printf(" Feet %f in Metres is: %f", feet, feet_to_metres(feet));

}

else if(option == 2){

printf(" Enter a number in metres to convert to feet: ");

scanf("%f", &metres);

printf(" Metres %f in Feet is: %f", metres, metres_to_feet(metres));

}

else if(option == 3){

printf(" Enter the length in metres: ");

scanf("%f", &length);

printf(" Enter the width in metres: ");

scanf("%f", &width);

printf(" Area of rectange with length %f and width %f is: %f", length, width, area_of_rect(length, width));

}

else if(option == 4){

printf(" Enter the lengths: ");

scanf("%f", &length);

printf(" Enter the width: ");

scanf("%f", &width);

printf(" Enter the height: ");

scanf("%f", &height);

printf(" Volume of rectanular solid for given length %f, width %f and height %f is %f", length, width, height, rect_volume(length, width, height));

}

else if(option == 5)

break;

}

return 0;

}

/* feet to metres function */

float feet_to_metres(float feet)

{

return feet * 0.3048;

}

/* metres to feet function */

float metres_to_feet(float metres)

{

return metres * 3.28084;

}

/* area of rectangle function */

float area_of_rect(float len, float wid)

{

return len * wid;

}

/* volume of rectangular solid function */

float rect_volume(float len, float wid, float ht)

{

return len * wid * ht;

}

int menu()

{

int n = -1;

/* Menu will repeatedly display until user gives an n value from 1 to 5 */

while(n < 1 || n > 5){

printf(" English-Metric Converter");

printf(" 1) Convert from feet to Metres");

printf(" 2) Convert from Metres to feet");

printf(" 3) Compute area of a rectangle in square feet given length and width in meters");

printf(" 4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet");

printf(" 5) Quit the Program");

printf(" Please enter a number (1-5) -> ");

scanf("%d", &n);

}

return n;

}

Execution and output:

Unix Terminal> ./a.out

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 10

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 1

Enter a number in feet to convert to metres: 10

Feet 10.000000 in Metres is: 3.048000

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 2

Enter a number in metres to convert to feet: 2

Metres 2.000000 in Feet is: 6.561680

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 3

Enter the length in metres: 10

Enter the width in metres: 20

Area of rectange with length 10.000000 and width 20.000000 is: 200.000000

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 4

Enter the lengths: 2

Enter the width: 3

Enter the height: 4

Volume of rectanular solid for given length 2.000000, width 3.000000 and height 4.000000 is 24.000000

English-Metric Converter

1) Convert from feet to Metres

2) Convert from Metres to feet

3) Compute area of a rectangle in square feet given length and width in meters

4) Compute volume of a rectangular solid in cubic meters given length, width, and height in feet

5) Quit the Program

Please enter a number (1-5) -> 5

Unix Terminal>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote