Question

In: Computer Science

Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program...

Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program should allow the user to select one of the options according to whether lengths, weights or volume are to be converted, read the volue to be converted and the units, and then call the appropriate function to carry out the conversion
In unit out unit
I C (inch to centimeter 1 in = 2.4 cm)
F C (feet to centimeter 1 ft = 30.4 cm)
F M (feet to meter 1 ft = 0.304 m)
Y M (yard to centimeter 1 in = 2.4 m)
M K (miles to kilometer 1 mi = 1.60 km)
O G (ounces to grams 1 oz = 28.34 g)
P K (pounds to kilograms 1 LB = .4 kg)
P L (pints to centimeter 1 PT = 0.47 L)
Q L (quarts to liters 1 QT = 0.94 L)
G L (gallons to liters 1 gal = 3.7 L)

NEED THIS IN C++

Solutions

Expert Solution

Here is the solution,

// your code starts here
#include <iostream>

using namespace std;

int main()
{
// variable declarations
int choice;
float inches,feet,yard,pints;
float miles,ounces,pounds,quarts,gallons;

// function declarations
// function for printing menu
void printMenu();
// function to convert to length
void convert_length(float,string,string);
// function to convert to weight
void convert_weight(float,string);
// function to convert to volumn
void convert_volumn(float,string,string);

// loop until users chose to exit
do {
cout<<endl<<endl;
printMenu();
cout<<"Enter your choice:";
cin>>choice;

switch(choice)
{
case 1:
// accept inches
cout<<"Enter Inches:";
cin>>inches;
// call to convert_length function
convert_length(inches,"inches","centimeter");
break;
case 2:
// accept feet
cout<<"Enter feets:";
cin>>feet;
// call to convert_length function
convert_length(feet,"feet","centimeter");
break;
case 3:
// accept feets
cout<<"Enter feets:";
cin>>feet;
// call to convert_length function
convert_length(feet,"feet","meter");
break;
case 4:
// accept yards
cout<<"Enter Yards:";
cin>>yard;
// call to convert_length function
convert_length(yard,"yard","centimeter");
break;
case 5:
// accept miles
cout<<"Enter Miles:";
cin>>miles;
// call to convert_length function
convert_length(miles,"miles","kilometer");
break;
case 6:
// accept ounces
cout<<"Enter Ounces:";
cin>>ounces;
// call to convert_weight function
convert_weight(ounces,"grams");
break;
case 7:
// accept pounds
cout<<"Enter Pounds:";
cin>>pounds;
// call to convert_weight function
convert_weight(pounds,"kilograms");
break;
case 8:
// accept Pints
cout<<"Enter Pints:";
cin>>pints;
// call to convert_volumn function
convert_volumn(pints,"pints","liter");
break;
case 9:
// accept Quarts
cout<<"Enter Quarts:";
cin>>quarts;
// call to convert_volumn function
convert_volumn(quarts,"quarts","liter");
break;
case 10:
// accept Gallons
cout<<"Enter Gallons:";
cin>>gallons;
// call to convert_volumn function
convert_volumn(gallons,"gallons","liter");
break;
case 11:
exit(0);
break;
}

}while(choice!=11);

return 0;
}

void printMenu()
{
cout<<"1) Convert Inches to centimeters" <<endl;
cout<<"2) Convert feet to centimeters" <<endl;
cout<<"3) Convert feet to meter" <<endl;
cout<<"4) Convert yard to centimeter" <<endl;
cout<<"5) Convert miles to kilometer"<<endl;
cout<<"6) Convert ounces to grams" <<endl;
cout<<"7) Convert pounds to kilograms" <<endl;
cout<<"8) Convert pints to liters" <<endl;
cout<<"9) Convert quarts to liters" <<endl;
cout<<"10) Convert gallons to liters" <<endl;
cout<<"11) Exit"<<endl;

}


void convert_length(float value,string s1,string s2)
{
// inches to centimeter
if(s1=="inches" && s2 == "centimeter")
{
cout<<"Centimeter is : "<<value * 2.54;
}
// feet to centimeter
else if(s1=="feet" && s2 == "centimeter")
{
cout<<"Centimeter is : "<<value * 30.4;
}
// feet to meter
else if(s1=="feet" && s2 == "meter")
{
cout<<"Meter is : "<<value * 0.304 ;
}
// yard to centimeter
else if(s1=="yard" && s2 == "centimeter")
{
cout<<"Centimeter is : "<<value * 91.44;
}
// miles to kilometer
else if(s1=="miles" && s2 == "kilometer")
{
cout<<"Kilometer is : "<<value * 1.60;
}
}

void convert_weight(float value,string s)
{
// ounces to grams
if(s == "grams")
{
cout<<"Grams is : "<<value * 28.34;
}
// pounds to kilogram
else if (s == "kilograms") {
cout<<"Kilograms is : "<<value * 0.4;
}
}

void convert_volumn(float value,string s1,string s2)
{
// pints to liter
if(s1=="pints" && s2 == "liter")
{
cout<<"Liter is : "<<value * 0.47;
}
// quarts to liter
else if(s1=="quarts" && s2 == "liter")
{
cout<<"Liter is : "<<value * 0.94;
}
// gallons to liter
else if(s1=="gallons" && s2 == "liter")
{
cout<<"Liter is : "<<value * 3.78;
}
}
// code ends here

here is the sample output:-

here is the screenshot of the code:-

Thank You.


Related Solutions

This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
Write a menu driven Java program which uses a method for each of the following operations:...
Write a menu driven Java program which uses a method for each of the following operations: (Note : The user should be allowed to repeat the operations as long as he wants to. Use appropriate number of parameters and return type for each method.) A. to find the sum of the following series (up to N terms). The program should    display the terms:              22 + 42 + 62… For example, if N=4, then the program should display the following...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file has unknown number of records of inventory items, but no more than 100; one record per line in the following order: item ID, item name (one word), quantity on hand , and a price All fields in the input file are separated by a tab (‘\t’) or a blank ( up to you) No error checking of the data required Create a menu which...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT