Write a unit conversion program that asks user sto identify the unit from which
ID: 3650214 • Letter: W
Question
Write a unit conversion program that asks user sto identify the unit from which they want to convert and the unit to which they want to convert. Legal units are in, ft, mi, mm, cm, m, and km. Declare two objects of a class UnitConverter that convert between meters and a given unit.--- Teachers notes ---
prompt a user to input a number and then prompt for the measurement type. Only those in the book are allowed (linear measurements in metric or English standard). Then prompt for the output measurement type, and display the conversion answer. I think this should be pretty straight forward, but if you have problems let me know. HINT: Instead of having tons of different methods, what you want to do is convert the measurement into either inches or millimeters, then have a method to convert the number to all possible output measurement types. This should be cleaner....
Explanation / Answer
4 down vote accepted Use a general calculating unit, e.g. meter. Say you use meters to calculate everything, the user chooses 'inch to foot'. Then you have to calculate the first unit into meters and meters again to mile. This way you only have to implement the scaling factors x for meter->unit (you can accomplish metertoUnit(unit), which converts a single meter to the corresponding value of the second unit, then you just have to use userInput * 1/meter->toUnit(firstUnit) * meter->toUnit(secondUnit) = outputRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.