Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise02 / main.cpp
diff options
context:
space:
mode:
Commitf18c44909c604a01bb0265d006a84223ee88d603 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-03-01 18:33:54 +0200
Committer
 Syndamia <kamen@syndamia.com>
2026-03-01 18:33:54 +0200
Files513a5b000add253f698901c7d636ed921f6913f2 /Week02/Exercise02/main.cpp
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar.gz
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.zip
Parentfcf38e62e8160f2c9901bdfd33760afed28beb8d (diff)
feat(Week02): Add solutions
1 files changed, 30 insertions, 0 deletions
-rw-r--r--Week02/Exercise02/main.cpp30
diff --git a/Week02/Exercise02/main.cpp b/Week02/Exercise02/main.cpp
new file mode 100644
index 0000000..4d43037
--- /dev/null
+++ b/Week02/Exercise02/main.cpp
@@ -0,0 +1,30 @@
+#include <iostream>
+#include "temperature.h"
+
+Temperature readTemperature() {
+ double degrees;
+ std::cin >> degrees;
+ char scale;
+ std::cin >> scale;
+
+ Temperature t;
+ switch (scale) {
+ case 'C': t.fromCelsius(degrees); break;
+ case 'F': t.fromFahrenheit(degrees); break;
+ case 'K': t.fromKelvin(degrees); break;
+ }
+
+ return t;
+}
+
+void printTemperature(const Temperature& t) {
+ std::cout << t.C << " C " << t.F << " F " << t.K << " K" << std::endl;
+}
+
+int main() {
+ Temperature first = readTemperature(), second = readTemperature();
+
+ printTemperature(first.Sum(second));
+
+ return 0;
+}