diff options
feat(Week02): Add solutions
1 files changed, 21 insertions, 0 deletions
| -rw-r--r-- | Week02/Exercise02/temperature.cpp | 21 |
diff --git a/Week02/Exercise02/temperature.cpp b/Week02/Exercise02/temperature.cpp new file mode 100644 index 0000000..3e497b9 --- /dev/null +++ b/Week02/Exercise02/temperature.cpp @@ -0,0 +1,21 @@ +#include "temperature.h" + +void Temperature::fromCelsius(double C) { + this->C = C; + F = (C * 1.8) + 32; + K = C + 273.15; +} + +void Temperature::fromFahrenheit(double F) { + fromCelsius((F - 32) / 1.8); +} + +void Temperature::fromKelvin(double K) { + fromCelsius(K - 273.15); +} + +Temperature Temperature::Sum(const Temperature& other) { + Temperature t; + t.fromCelsius(this->C + other.C); + return t; +} |
