-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.cpp
125 lines (111 loc) · 2.88 KB
/
date.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "date.h"
#include <iostream>
#include <string>
#include <sstream>
Date::Date(string date) {
original_date_string = date;
// Finds first instance of '/' character for month
int slash_index = date.find("/");
string month_str = date.substr(0, slash_index);
month = stoi(month_str);
// Finds second instance of '/' character that separates day and year
int new_slash_index = date.find("/", slash_index + 1);
string day_str = date.substr(slash_index + 1, new_slash_index - (slash_index + 1));
day = stoi(day_str);
string year_str = date.substr(new_slash_index + 1);
year = stoi(year_str);
}
void Date::print_date() {
switch(month) {
case 1:
month_name = "January";
break;
case 2:
month_name = "February";
break;
case 3:
month_name = "March";
break;
case 4:
month_name = "April";
break;
case 5:
month_name = "May";
break;
case 6:
month_name = "June";
break;
case 7:
month_name = "July";
break;
case 8:
month_name = "August";
break;
case 9:
month_name = "September";
break;
case 10:
month_name = "October";
break;
case 11:
month_name = "November";
break;
case 12:
month_name = "December";
break;
default:
month_name = "Month out of range";
}
cout << month_name << " " << day << ", " << year << endl;
}
string Date::get_date()
{
switch(month) {
case 1:
month_name = "January";
break;
case 2:
month_name = "February";
break;
case 3:
month_name = "March";
break;
case 4:
month_name = "April";
break;
case 5:
month_name = "May";
break;
case 6:
month_name = "June";
break;
case 7:
month_name = "July";
break;
case 8:
month_name = "August";
break;
case 9:
month_name = "September";
break;
case 10:
month_name = "October";
break;
case 11:
month_name = "November";
break;
case 12:
month_name = "December";
break;
default:
month_name = "Month out of range";
}
std::ostringstream oss;
// Print month name, day, and year into the stringstream
oss << month_name << " " << day << ", " << year;
// Return the string from stringstream
return oss.str();
}
string Date::get_og_date() {
return original_date_string;
}