Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise01 / date.cpp
diff options
context:
space:
mode:
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Week02/Exercise01/date.cpp31
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;
+}