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

Write the following C++ Program Conversion Program: Write a program that perform

ID: 3752713 • Letter: W

Question

Write the following C++ Program

Conversion Program: Write a program that perform conversions that we use often. Program should display the following menu and ask the user to enter the choice. For example, if choice 1 is selected, then the program should ask the user to enter the Fahrenheit temperature and call the function double fahrenheitToCilsuis(double fTemp) to get the conversion. So, you need to implement following functions in your program Welcome to the Conversion Program 1. 2. 3. 4. Fahrenheit to Celsius Miles to kilometers Liters to Gallons Exit from the program You should implement this program using functions and your program need to have following functions void displayMenu() double fahrenheitToCilsuis(double fTemp) double milesToKilometers(double miles) double litersToGallons(doube liters)

Explanation / Answer

#include<iostream>

using namespace std;

void displayMenu()

{

cout<<" Welcome to the Conversion Program ";

cout<<" ================================= ";

cout<<"1. Fahrenheit to Celsius ";

cout<<"2. Miles to Kilometers ";

cout<<"3. Liters to Gallons ";

cout<<"4. Exit from the program ";

}

double fahrenheitToCelsius(double fTemp)

{

// 5

// C = --- ( F - 32 )

// 9

double cTemp = ( fTemp - 32.0 ) * 5.0 / 9.0;

return cTemp;

}

double milesToKilometers(double miles)

{

// 1 mile = 1.60934 km

double km = miles * 1.60934;

return km;

}

double litersToGallons(double liters)

{

// 1 liter = 0.264172 gallon

double gallon = liters * 0.264172;

return gallon;

}

int main()

{

double km, gallon, fTemp, cTemp, liter, miles;

// infinite loop

while(1)

{

displayMenu();

int choice;

cin>>choice;

switch(choice)

{

// Fahrenheit to Celsius

case 1 : cout<<"Enter temperature in Fahrenheit : ";

cin>>fTemp;

  

cTemp = fahrenheitToCelsius( fTemp );

  

cout<<"Temperature in Celsius : "<<cTemp<<endl;

  

break;

  

// Miles to Kilometers

case 2 : cout<<"Enter distance in miles : ";

cin>>miles;

  

km = milesToKilometers( miles );

  

cout<<"Distance in Kilometers : "<<km<<endl;

  

break;

  

// Liters to Gallons

case 3 : cout<<"Enter volume in liters : ";

cin>>liter;

  

gallon = litersToGallons( liter );

cout<<"Volume in Gallons : "<<gallon<<endl;

  

break;

// exit the program

case 4 : exit(0);

}

}

}