Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note: This question was incomplete and very confuseing, please help. C++ languag

ID: 3767785 • Letter: N

Question

Note: This question was incomplete and very confuseing, please help. C++ language please help

Create a Temperature class that internally stores a temperature in degrees Kelvin. Create functions named setTempKelvin, setTempFarenheit, and setTemCelcius that an input in the specified scale, converts the temperature to Kelvin, and store the temperature in the class member variable. Also create functions that return and stored temperature in Kelvin, Fahrenheit, or Celsius. Write the main functions to test your class. Use the equations:

Kelvin = Celsius + 273.15

Celsius = (5.0/9) X (Fahrenheit -32.0)

Explanation / Answer

program: #include class Temperature { public: enum Scale { CELSIUS, KELVIN, FAHRENHEIT }; Temperature(long double val) : _degrees(val) {} void set_kelvin(double val) { _degrees = val; } void set_celsius(double val) { _degrees = convert(val, CELSIUS, KELVIN); } void set_fahrenheit(double val) { _degrees = convert(val, FAHRENHEIT, KELVIN); } double as_kelvin() const { return _degrees; } double as_celsius() const { return convert(_degrees, KELVIN, CELSIUS); } double as_fahrenheit() const { return convert(_degrees, KELVIN, FAHRENHEIT); } static constexpr long double convert(long double x, Scale from, Scale to) { return (x - scales[from].waterfreeze)* (scales[to].waterboil - scales[to].waterfreeze)/ (scales[from].waterboil - scales[from].waterfreeze) + scales[to].waterfreeze; } private: struct TempScale { long double waterfreeze; long double waterboil; const char *name; }; static constexpr TempScale scales[3]{ { 0, 100, "C" }, { 273.15, 373.15, "K" }, { 32, 212, "F" }, }; // all temperatures are internally stored as Kelvin double _degrees; }; constexpr Temperature::TempScale Temperature::scales[]; constexpr long double operator"" _c(long double deg) { return Temperature::convert(deg, Temperature::CELSIUS, Temperature::KELVIN); } constexpr long double operator"" _f(long double deg) { return Temperature::convert(deg, Temperature::FAHRENHEIT, Temperature::KELVIN); } constexpr long double operator"" _k(long double deg) { return deg; } int main() { Temperature t1{20.0_c}; std::cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote