Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise01
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/Exercise01
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.tar.gz
oop-2025-solutions-f18c44909c604a01bb0265d006a84223ee88d603.zip
Parentfcf38e62e8160f2c9901bdfd33760afed28beb8d (diff)
feat(Week02): Add solutions
3 files changed, 56 insertions, 0 deletions
-rw-r--r--Week02/Exercise01/date.cpp31
-rw-r--r--Week02/Exercise01/date.h13
-rw-r--r--Week02/Exercise01/main.cpp12
diff --git a/Week02/Exercise01/date.cpp b/Week02/Exercise01/date.cpp
new file mode 100644
index 0000000..ffc051e
--- /dev/null
+++ b/Week02/Exercise01/date.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+#include "date.h"
+
+const char* monthName(unsigned month) {
+ switch (month) {
+ case 1: return "Jan";
+ case 2: return "Feb";
+ case 3: return "Mar";
+ case 4: return "Apr";
+ case 5: return "May";
+ case 6: return "Jun";
+ case 7: return "Jul";
+ case 8: return "Aug";
+ case 9: return "Sep";
+ case 10: return "Oct";
+ case 11: return "Nov";
+ case 12: return "Dec";
+
+ default: return nullptr;
+ }
+}
+
+void printDate(const Date& d) {
+ std::cout << d.day << '/' << monthName(d.month) << '/' << d.year;
+}
+
+Date readDate() {
+ Date d;
+ std::cin >> d.day >> d.month >> d.year;
+ return d;
+}
diff --git a/Week02/Exercise01/date.h b/Week02/Exercise01/date.h
new file mode 100644
index 0000000..4d2ff1a
--- /dev/null
+++ b/Week02/Exercise01/date.h
@@ -0,0 +1,13 @@
+#ifndef _DATE
+#define _DATE
+
+struct Date {
+ unsigned day;
+ unsigned month;
+ unsigned year;
+};
+
+void printDate(const Date& d);
+Date readDate();
+
+#endif
diff --git a/Week02/Exercise01/main.cpp b/Week02/Exercise01/main.cpp
new file mode 100644
index 0000000..28856ef
--- /dev/null
+++ b/Week02/Exercise01/main.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+#include "date.h"
+
+int main() {
+ for (unsigned i = 0; i < 3; ++i) {
+ printDate(readDate());
+ std::cout << ' ';
+ }
+ std::cout << std::endl;
+
+ return 0;
+}