Create a temperature class that internally stores a temperature in degrees Kelvin. However, create functions named setTempKelvin, setTempFahrenheit, setTempCelcius that takes input temperature in the specified scale, converts the temperature to kelvin, and stores that temperature in the class member variable. Also, create functions that return the stored temperature in degrees Kelvin, Fahrenheit, or Celcius.
Kelvin = Celcius + 273.15
Celcius = (5/9)*(fahrenheit - 32)
not sure if I'm on the right track with this or not ..... would appreciate any input .....
here is the code I have so far....
[
#include <iostream>
#include <cmath>
using namespace std;
//Class to implement Temperature object
class Temperature
{
private:
double KelvinTemperature;//instance variable
public:
int Temp();
double getCelsius();
double getFahrenheit();
void setTempCelsius(double Temperature);
void setTempFahrenheit(double Temperature);
void setTempKelvin(double Temperature);
};
//Default constructor
Temp::Temp()
{
CelciusTemperature = 0;
}
//Accessor to get Celsius temperature
double Temperature::getCelsius()
{
return CelsiusTemperature;
}
//Accessor to get Fahrenheit temperature
double Temperature::getFahrenheit()
{
return 9.0*CelsiusTemperature/5.0 + 32.0;
}
{
KelvinTemperature = 0;
}
//Accessor to get Kelvin temperature
double Temperature::getKelvin()
(
return CelsiusTemperature + 273.15
}
//Mutator to set Celcius temperature
void Temperature::setTempCelsius(double Temperature)
{
CelsiusTemperature = Temperature;
}
//Mutator to set Fahrenheit temperature
void Temperature::setTempFahrenheit(double Temperature)
{
CelsiusTemperature = (Temperature - 32.0 ) * 5.0 / 9.0 ;
}
//Mutator to set Kelvin temperature
void Temperature::setTempKelvin(double Temperature)
{
KelvinTemperature = (Temperature + 273.15);
int main()
{
//Test temperature conversion
double Celsius;
double Fahrenheit;
double Kelvin;
return 0;
}
/]