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
|
class Calendar {
public:
void setDate(int d, int m, int y) {
bool day_check = false; bool month_check = false;
if (m < Month::January || m > Month::December) {
cerr << "Month does not exist." << endl;
}
else {
month_check = true;
}
if (d < Day::Monday || d > Day::Sunday) {
cerr << "Day does not exist." << endl;
}
else {
day_check = true;
}
if (month_check == true && day_check == true) {
year = y;
month = m;
day = d;
}
else {
cerr << "Error with checking dates!" << endl;
}
}
enum Month {
January = 1,
February,
March,
May,
June,
July,
August,
September,
October,
November,
December
};
enum Day {
Monday = 1,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
friend ostream& operator <<(ostream& os, Month m) {
return os << month_table[m]; // Checking a vector with strings Jan - Dec.
}
friend ostream& operator <<(ostream& os, Day d) {
return os << day_table[d]; // Checking a vector with strings Mon - Sun.
}
int getYear() { return year; }
Month getMonth() { return Month(month); }
Day getDay() { return Day(day); }
private:
int year;
int month;
int day;
};
|