Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise02 / temperature.cpp
blob: 3e497b9ef9e4a3306af85d0f905aa3d6c854eab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}