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;
}

/]

You should figure out how to use [code=syntax]...code tags... [/code] so that people can read your code.

It's hard to tell, but it appears that your constructors are definitely not right. Also, how do you plan to get Celsius from Kelvin if you only return CelsiusTemperature; ? From what I can tell CelsiusTemperature doesn't exist. In addition, last I checked Kelvin and Celsius are not the same...

Some reading would be suggested.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.