Answer to Question #168983 in C++ for Rose

Question #168983

Project Description

 

There are two main systems for measuring distance, weight and temperature, the Imperial System of Measurement and the Metric System of Measurement. Most countries use the Metric System, which uses the measuring units such as meters and grams and adds prefixes like kilo, milli and centi to count orders of magnitude. In the United States, we use the older Imperial system, where things are measured in feet, inches and pounds.

 

 

Write a program that shows the following menu options and lets the user to convert from Metric to Imperial system:

 

Converter Toolkit

--------------------

   1. Temperature Converter

   2. Distance Converter

   3. Weight Converter

   4. Quit

 

·      If the user enters 1, the program should ask for the temperature in Celsius and convert it to Fahrenheit

 

·       If the user enters 2, the program should ask for the distance in Kilometer and convert it to Mile

 

·       If the user enters 3, the program should ask for the weight in Kilogram and convert it to Pound

 

·       If the user enters 4, the program should end.

 

 

Project Specifications

 

Input for this project:

·       the user must enter an number to select a menu option

·       the user must enter temperature in Celsius

·       the user must enter distance in Kilometer

·       the user must enter weight in Kilogram

·       the user must enter a country name

Input Validation: 

·       Do not accept a number outside the range of 1 through 4 for the menu option. Be sure to display appropriate error message if the input is invalid.

·       Do not accept negative numbers for distance and weight. Be sure to display appropriate error message if the input is invalid.

 

 

Output: The program should display the following:

·       a menu for Converter Toolkit

·       temperature in Fahrenheit, distance in miles or weight in pounds

·       a country name

·       Programmer’s full name

·       project number

·       a due date

 

Processing Requirements

 

1.  The program should use at least one selection control structure (if – else statement)

2.  Be sure to convert as specified. For example, convert temperature from Celsius to Fahrenheit, not the other way around.

3.  Use the following for converting input:

·       1 kilometer = 0.6 mile,

·       1 kilogram = 2.2 pounds,

·       The formula for converting Celsius degree to Fahrenheit is:

F = (9/5)*C + 32 where F is the temperature in Fahrenheit and C is the temperature in Celsius

4.  Convert temperature to a whole number such as 78, distance to two positions after decimal point (for example 84.56) and weight to one position after decimal point (For example 121.6).

 

 

 

 

 

 

 

1
Expert's answer
2021-03-04T15:51:44-0500
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;

int main() {

   //setting the precision to two decimal places
   std::cout << std::setprecision(2) << std::fixed;


   //Declaring variables
int choice;
double celsius,fahrenheit,kilometer,mile,km,pound;
  
/* This while loop continues to execute
* until the user chooses valid choice or Choice is 4
*/

while(true)
{
       //displaying the menu
cout<<"\nConverter Toolkit:"<<endl;
   cout<<"--------------------"<<endl;
cout<<"1. Temperature Converter"<<endl;
cout<<"2. Distance Converter"<<endl;
cout<<"3. Weight Converter"<<endl;
cout<<"4. Quit"<<endl;    
  
//getting the choice entered by the user
cout<<"Enter Choice :";
cin>>choice;
  
   //Based on the user choice the corresponding case will be executed
switch(choice)
{
   case 1:{
       //Getting the input entered by the user
       cout<<"Enter temperature (in Celsius) :";
       cin>>celsius;
      
       fahrenheit=(9.0/5.0)*celsius+32.0;
      
       cout<<"Temperature in Fahrenheit :"<<fahrenheit<<"F"<<endl;
           continue;
       }
       case 2:{
           //Getting the input entered by the user
       cout<<"Enter Distance (in Kilometers):";
       cin>>kilometer;
       mile=kilometer*0.621371;
       cout<<"Disrtance in miles :"<<mile<<endl;
           continue;
       }
       case 3:{
           //Getting the input entered by the user
       cout<<"Enter Weight in (kilograms):";
       cin>>kilometer;
       pound=kilometer*2.20462;
       cout<<"Weight in Pounds :"<<pound<<endl;
      
           continue;
       }
       case 4:{
      
           break;
       }
       default:{
       cout<<"** Invalid Choice **"<<endl;
           continue;
       }
      
      
      
   }
   break;
  
   }

   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS