Write a C++ program to convert kilometers to miles or miles to kilometers. The user will choose which conversion they want from a menu as shown below. Use a pretest loop with a flag that ends the loop and program when the user enters 3 for the menu choice. Include the following methods: Return Methods Method to get the number of kilometers (double type) Method to get the number of miles (double type) Method to convert kilometers to miles (1 km = .621371192 miles) Method to convert miles to kilometers (1 mi = 1.60934 km) Void Methods Method to display this conversion menu: Choose the conversion from this menu          1 – Convert miles to kilometers          2 – Convert kilometers to miles          3 – Exit  Choice: One method to display the output, formatted like this (no matter which conversion you choose): 124.8 miles is equal to 200.8 kilometers. Test your program with 200.8 kilometers, then 124.8 miles and 575.9 miles, then 926.8 kilometers.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
icon
Related questions
Question

Write a C++ program to convert kilometers to miles or miles to kilometers. The user will choose which conversion they want from a menu as shown below. Use a pretest loop with a flag that ends the loop and program when the user enters 3 for the menu choice.

Include the following methods:

Return Methods

  • Method to get the number of kilometers (double type)
  • Method to get the number of miles (double type)
  • Method to convert kilometers to miles (1 km = .621371192 miles)
  • Method to convert miles to kilometers (1 mi = 1.60934 km)

Void Methods

  • Method to display this conversion menu:

    Choose the conversion from this menu
             1 – Convert miles to kilometers
             2 – Convert kilometers to miles
             3 – Exit 
    Choice:

  • One method to display the output, formatted like this (no matter which conversion you choose):

    124.8 miles is equal to 200.8 kilometers.

Test your program with 200.8 kilometers, then 124.8 miles and 575.9 miles, then 926.8 kilometers.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr