Question: C++ exercise: For this exercise, you will use C++ data types: char, int and double. Use casting as needed. Use this style of casting: static_cast
C++ exercise:
For this exercise, you will use C++ data types: char, int and double. Use casting as needed. Use this style of casting: static_cast < new_type > (value). For example: static_cast < double > (number).
Write one program that performs distance conversions. A distance may be entered in centimeters, inches or feet. The program converts the distance input into alternative units. Here is one conversion example: Distance in centimeters (whole number)? 100 integer: centimeters=100 inches=39 feet=3 precise: centimeters=100 inches=39.3701 feet=3.28084
Perform conversions with constant variables CENTIMETERS_IN_INCH, INCHES_IN_FOOT: const double CENTIMETERS_IN_INCH{2.54}; const int INCHES_IN_FOOT{12};
Do calculations using both int and double. Show output in both types. Note that double provides more accurate results than int. Use casting to convert int to double as needed.
Enhance your program to support multiple conversions for multiple units. Here is some example output for what is expected:
This program performs some distance conversions. Enter option letter for distance unit: c)entimeter i)nch f)eet q)uit: c Distance in centimeters (whole number)? 100 integer: centimeters=100 inches=39 feet=3 precise: centimeters=100 inches=39.3701 feet=3.28084
Enter option letter for distance unit: c)entimeter i)nch f)eet q)uit: i Distance in inches (whole number)? 100 integer: centimeters=254 inches=100 feet=8 precise: centimeters=254 inches=100 feet=8.33333
Enter option letter for distance unit: c)entimeter i)nch f)eet q)uit: f Distance in feet (whole number)? 100 integer: centimeters=3048 inches=1200 feet=100 precise: centimeters=3048 inches=1200 feet=100
Enter option letter for distance unit: c)entimeter i)nch f)eet q)uit: t Option t is invalid. Please try again.
Enter option letter for distance unit: c)entimeter i)nch f)eet q)uit: q Good-bye!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
