A class that stores temperature information, and allows conversion between different units. More...
#include <Temperature.hh>
Public Member Functions | |
Temperature () | |
Default constructor. More... | |
Temperature (const double _temp) | |
Kelvin value constructor. This is a conversion constructor. More... | |
Temperature (const Temperature &_temp) | |
Copy constructor. More... | |
virtual | ~Temperature () |
Destructor. More... | |
double | Celsius () const |
Get the temperature in Celsius. More... | |
double | Fahrenheit () const |
Get the temperature in Fahrenheit. More... | |
double | Kelvin () const |
Get the temperature in Kelvin. More... | |
bool | operator!= (const double _temp) const |
Inequality to operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator!= (const Temperature &_temp) const |
Inequality to operator. More... | |
double | operator() () const |
Accessor operator. More... | |
Temperature | operator* (const double _temp) |
Multiplication operator. More... | |
Temperature | operator* (const double _temp) const |
Multiplication operator. More... | |
Temperature | operator* (const Temperature &_temp) |
Multiplication operator. More... | |
Temperature | operator* (const Temperature &_temp) const |
Multiplication operator. More... | |
const Temperature & | operator*= (const double _temp) |
Multiplication assignment operator. More... | |
const Temperature & | operator*= (const Temperature &_temp) |
Multiplication assignment operator. More... | |
Temperature | operator+ (const double _temp) |
Addition operator. More... | |
Temperature | operator+ (const double _temp) const |
Addition operator. More... | |
Temperature | operator+ (const Temperature &_temp) |
Addition operator. More... | |
Temperature | operator+ (const Temperature &_temp) const |
Addition operator. More... | |
const Temperature & | operator+= (const double _temp) |
Addition assignment operator. More... | |
const Temperature & | operator+= (const Temperature &_temp) |
Addition assignment operator. More... | |
Temperature | operator- (const double _temp) |
Subtraction operator. More... | |
Temperature | operator- (const double _temp) const |
Subtraction operator. More... | |
Temperature | operator- (const Temperature &_temp) |
Subtraction operator. More... | |
Temperature | operator- (const Temperature &_temp) const |
Subtraction operator. More... | |
const Temperature & | operator-= (const double _temp) |
Subtraction assignment operator. More... | |
const Temperature & | operator-= (const Temperature &_temp) |
Subtraction assignment operator. More... | |
Temperature | operator/ (const double _temp) |
Division operator. More... | |
Temperature | operator/ (const double _temp) const |
Division operator. More... | |
Temperature | operator/ (const Temperature &_temp) |
Division operator. More... | |
Temperature | operator/ (const Temperature &_temp) const |
Division operator. More... | |
const Temperature & | operator/= (const double _temp) |
Division assignment operator. More... | |
const Temperature & | operator/= (const Temperature &_temp) |
Division assignment operator. More... | |
bool | operator< (const double _temp) const |
Less than operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator< (const Temperature &_temp) const |
Less than to operator. More... | |
bool | operator<= (const double _temp) const |
Less than or equal operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator<= (const Temperature &_temp) const |
Less than or equal to operator. More... | |
Temperature & | operator= (const double _temp) |
Assignment operator. More... | |
Temperature & | operator= (const Temperature &_temp) |
Assignment operator. More... | |
bool | operator== (const double _temp) const |
Equal to operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator== (const Temperature &_temp) const |
Equal to operator. More... | |
bool | operator> (const double _temp) const |
Greater than operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator> (const Temperature &_temp) const |
Greater than operator. More... | |
bool | operator>= (const double _temp) const |
Greater than equal operator, where the value of _temp is assumed to be in Kelvin. More... | |
bool | operator>= (const Temperature &_temp) const |
Greater than or equal to operator. More... | |
void | SetCelsius (const double _temp) |
Set the temperature from a Celsius value. More... | |
void | SetFahrenheit (const double _temp) |
Set the temperature from a Fahrenheit value. More... | |
void | SetKelvin (const double _temp) |
Set the temperature from a Kelvin value. More... | |
Static Public Member Functions | |
static double | CelsiusToFahrenheit (const double _temp) |
Convert Celsius to Fahrenheit. More... | |
static double | CelsiusToKelvin (const double _temp) |
Convert Celsius to Kelvin. More... | |
static double | FahrenheitToCelsius (const double _temp) |
Convert Fahrenheit to Celsius. More... | |
static double | FahrenheitToKelvin (const double _temp) |
Convert Fahrenheit to Kelvin. More... | |
static double | KelvinToCelsius (const double _temp) |
Convert Kelvin to Celsius. More... | |
static double | KelvinToFahrenheit (const double _temp) |
Convert Kelvin to Fahrenheit. More... | |
Detailed Description
A class that stores temperature information, and allows conversion between different units.
This class is mostly for convenience. It can be used to easily convert between temperature units and encapsulate temperature values.
The default unit is Kelvin. Most functions that accept a double value will assume the double is Kelvin. The exceptions are a few of the conversion functions, such as CelsiusToFahrenheit. Similarly, most doubles that are returned will be in Kelvin.
Example usage
Convert from Kelvin to Celsius
double celsius = Temperature::KelvinToCelsius(2.5);
Create and use a Temperature object
Temperature temp(123.5); std::cout << "Temperature in Kelvin = " << temp << std::endl; std::cout << "Temperature in Celsius = " << temp.Celsius() << std::endl; temp += 100.0; std::cout << "Temperature + 100.0 = " << temp << "K" << std::endl; Temperature newTemp(temp); newTemp += temp + 23.5; std::cout << "Copied the temp object and added 23.5K. newTemp = " << newTemp.Fahrenheit() << "F" << std::endl;
Constructor & Destructor Documentation
◆ Temperature() [1/3]
Temperature | ( | ) |
Default constructor.
◆ Temperature() [2/3]
Temperature | ( | const double | _temp | ) |
Kelvin value constructor. This is a conversion constructor.
- Parameters
-
[in] _temp Temperature in Kelvin
◆ Temperature() [3/3]
Temperature | ( | const Temperature & | _temp | ) |
Copy constructor.
- Parameters
-
[in] _temp Temperature object to copy.
◆ ~Temperature()
|
virtual |
Destructor.
Member Function Documentation
◆ Celsius()
double Celsius | ( | ) | const |
Get the temperature in Celsius.
- Returns
- Temperature in Celsius
◆ CelsiusToFahrenheit()
|
static |
Convert Celsius to Fahrenheit.
- Parameters
-
[in] _temp Temperature in Celsius
- Returns
- Temperature in Fahrenheit
◆ CelsiusToKelvin()
|
static |
◆ Fahrenheit()
double Fahrenheit | ( | ) | const |
Get the temperature in Fahrenheit.
- Returns
- Temperature in Fahrenheit
◆ FahrenheitToCelsius()
|
static |
Convert Fahrenheit to Celsius.
- Parameters
-
[in] _temp Temperature in Fahrenheit
- Returns
- Temperature in Celsius
◆ FahrenheitToKelvin()
|
static |
Convert Fahrenheit to Kelvin.
- Parameters
-
[in] _temp Temperature in Fahrenheit
- Returns
- Temperature in Kelvin
◆ Kelvin()
double Kelvin | ( | ) | const |
Get the temperature in Kelvin.
- Returns
- Temperature in Kelvin
◆ KelvinToCelsius()
|
static |
◆ KelvinToFahrenheit()
|
static |
Convert Kelvin to Fahrenheit.
- Parameters
-
[in] _temp Temperature in Kelvin
- Returns
- Temperature in Fahrenheit
◆ operator!=() [1/2]
bool operator!= | ( | const double | _temp | ) | const |
Inequality to operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- false if the temperatures are the same, true otherwise
◆ operator!=() [2/2]
bool operator!= | ( | const Temperature & | _temp | ) | const |
Inequality to operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- false if the temperatures are the same, true otherwise
◆ operator()()
double operator() | ( | ) | const |
◆ operator*() [1/4]
Temperature operator* | ( | const double | _temp | ) |
◆ operator*() [2/4]
Temperature operator* | ( | const double | _temp | ) | const |
◆ operator*() [3/4]
Temperature operator* | ( | const Temperature & | _temp | ) |
◆ operator*() [4/4]
Temperature operator* | ( | const Temperature & | _temp | ) | const |
◆ operator*=() [1/2]
const Temperature& operator*= | ( | const double | _temp | ) |
Multiplication assignment operator.
- Parameters
-
[in] _temp Temperature in Kelvin
- Returns
- Reference to this instance
◆ operator*=() [2/2]
const Temperature& operator*= | ( | const Temperature & | _temp | ) |
Multiplication assignment operator.
- Parameters
-
[in] _temp Temperature object
- Returns
- Reference to this instance
◆ operator+() [1/4]
Temperature operator+ | ( | const double | _temp | ) |
◆ operator+() [2/4]
Temperature operator+ | ( | const double | _temp | ) | const |
◆ operator+() [3/4]
Temperature operator+ | ( | const Temperature & | _temp | ) |
◆ operator+() [4/4]
Temperature operator+ | ( | const Temperature & | _temp | ) | const |
◆ operator+=() [1/2]
const Temperature& operator+= | ( | const double | _temp | ) |
Addition assignment operator.
- Parameters
-
[in] _temp Temperature in Kelvin
- Returns
- Reference to this instance
◆ operator+=() [2/2]
const Temperature& operator+= | ( | const Temperature & | _temp | ) |
Addition assignment operator.
- Parameters
-
[in] _temp Temperature object
- Returns
- Reference to this instance
◆ operator-() [1/4]
Temperature operator- | ( | const double | _temp | ) |
◆ operator-() [2/4]
Temperature operator- | ( | const double | _temp | ) | const |
◆ operator-() [3/4]
Temperature operator- | ( | const Temperature & | _temp | ) |
◆ operator-() [4/4]
Temperature operator- | ( | const Temperature & | _temp | ) | const |
◆ operator-=() [1/2]
const Temperature& operator-= | ( | const double | _temp | ) |
Subtraction assignment operator.
- Parameters
-
[in] _temp Temperature in Kelvin
- Returns
- Reference to this instance
◆ operator-=() [2/2]
const Temperature& operator-= | ( | const Temperature & | _temp | ) |
Subtraction assignment operator.
- Parameters
-
[in] _temp Temperature object
- Returns
- Reference to this instance
◆ operator/() [1/4]
Temperature operator/ | ( | const double | _temp | ) |
◆ operator/() [2/4]
Temperature operator/ | ( | const double | _temp | ) | const |
◆ operator/() [3/4]
Temperature operator/ | ( | const Temperature & | _temp | ) |
◆ operator/() [4/4]
Temperature operator/ | ( | const Temperature & | _temp | ) | const |
◆ operator/=() [1/2]
const Temperature& operator/= | ( | const double | _temp | ) |
Division assignment operator.
- Parameters
-
[in] _temp Temperature in Kelvin
- Returns
- Reference to this instance
◆ operator/=() [2/2]
const Temperature& operator/= | ( | const Temperature & | _temp | ) |
Division assignment operator.
- Parameters
-
[in] _temp Temperature object
- Returns
- Reference to this instance
◆ operator<() [1/2]
bool operator< | ( | const double | _temp | ) | const |
Less than operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- True if this is less than _temp.
◆ operator<() [2/2]
bool operator< | ( | const Temperature & | _temp | ) | const |
Less than to operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- True if this is less than _temp.
◆ operator<=() [1/2]
bool operator<= | ( | const double | _temp | ) | const |
Less than or equal operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- True if this is less than or equal to _temp.
◆ operator<=() [2/2]
bool operator<= | ( | const Temperature & | _temp | ) | const |
Less than or equal to operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- True if this is less than or equal _temp.
◆ operator=() [1/2]
Temperature& operator= | ( | const double | _temp | ) |
◆ operator=() [2/2]
Temperature& operator= | ( | const Temperature & | _temp | ) |
◆ operator==() [1/2]
bool operator== | ( | const double | _temp | ) | const |
Equal to operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- true if the temperatures are the same, false otherwise
◆ operator==() [2/2]
bool operator== | ( | const Temperature & | _temp | ) | const |
Equal to operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- true if the temperatures are the same, false otherwise
◆ operator>() [1/2]
bool operator> | ( | const double | _temp | ) | const |
Greater than operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- True if this is greater than _temp.
◆ operator>() [2/2]
bool operator> | ( | const Temperature & | _temp | ) | const |
Greater than operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- True if this is greater than _temp.
◆ operator>=() [1/2]
bool operator>= | ( | const double | _temp | ) | const |
Greater than equal operator, where the value of _temp is assumed to be in Kelvin.
- Parameters
-
[in] _temp The temperature (in Kelvin) to compare
- Returns
- True if this is greater than or equal to _temp.
◆ operator>=() [2/2]
bool operator>= | ( | const Temperature & | _temp | ) | const |
Greater than or equal to operator.
- Parameters
-
[in] _temp The temperature to compare
- Returns
- True if this is greater than or equal to _temp.
◆ SetCelsius()
void SetCelsius | ( | const double | _temp | ) |
Set the temperature from a Celsius value.
- Parameters
-
[in] _temp Temperature in Celsius
◆ SetFahrenheit()
void SetFahrenheit | ( | const double | _temp | ) |
Set the temperature from a Fahrenheit value.
- Parameters
-
[in] _temp Temperature in Fahrenheit
◆ SetKelvin()
void SetKelvin | ( | const double | _temp | ) |
Set the temperature from a Kelvin value.
- Parameters
-
[in] _temp Temperature in Kelvin
The documentation for this class was generated from the following file: