0

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

/]

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by Fbody
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.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.