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.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Write a C++
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.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images