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

This should be completed in C++, specifically emphasizing the use of classes and

ID: 3870298 • Letter: T

Question

This should be completed in C++, specifically emphasizing the use of classes and objects

Create a Temperature class that internally stores a temperature in degrees Kelvin. Create functions named set_temp kelvin, set_temp_ fahrenheit, and set_temp_celsius that take an input temperature in the specified temperature scale, convert the temperature to Kelvin, and store that temperature in the class member variable. Also, create accessor functions that return the stored temperature in degrees Kelvin, Fahrenheit, or Celsius. Write a main function to test your class. Use the following equations to convert between the three temperature scales: Kelvin = Celsius + 273.15 Celsius (5.0/9) X (Fahrenheit -32)

Explanation / Answer

#include<iostream>

using namespace std;

class Temperature {
    private:
        double value;
    public:
       void set_temp_kelvin(){
            double temp;
            cout << "Enter temperature in kelvin :";
            cin >> temp;
            value = temp;
       }
       void set_temp_fahrenheit(){
          double temp;
          cout << "Enter temperature in fahrenheit :";
          cin >> temp;
          value = (5.0/9) * (temp - 32);
          value = value + 273.15;
       }
       void set_temp_celsius(){
          double temp;
          cout << "Enter temperature in celsius :";
          cin >> temp;
          value = temp + 273.15;
       }
       double get_temp_kelvin(){
            return value;
       }
       double get_temp_fahrenheit(){
          value = value - 273.15;
          value = (9/5.0)*value + 32;
          return value;
       }
       double get_temp_celsius(){
           value = value - 273.15;
           return value;
       }
};


int main(){

     Temperature t;
     t.set_temp_kelvin();
     cout << "Temperature in kelvin : " << t.get_temp_kelvin() << endl;

     t.set_temp_fahrenheit();
     cout << "Temperature in fahrenheit : " << t.get_temp_fahrenheit() << endl;

     t.set_temp_celsius();
     cout << "Temperature in celsius : " << t.get_temp_celsius() << endl;
}

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