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
|
#include <iostream>
#include <map>
using namespace std;
enum class DAY { MON , TUE , WED , THU , FRI , SAT , SUN };
const map<DAY,string> mDAY { {DAY::MON,"Monday"},{DAY::TUE,"Tuesday"},
{DAY::WED,"Wednesday"},{DAY::THU,"Thursday"},
{DAY::FRI,"Friday"},{DAY::SAT,"Saturday"},
{DAY::SUN,"Sunday"} };
DAY operator++( DAY day )
{
return static_cast<DAY>((static_cast<int>(day)+1)%mDAY.size());
}
DAY operator--( DAY day )
{
auto iday {static_cast<int>(day)-1};
return static_cast<DAY>( iday<0?mDAY.size()-1:iday );
}
ostream& operator<<( ostream& out , const DAY& day )
{
out << mDAY.at(day);
return out;
}
class Day
{
private:
DAY day;
public:
Day( DAY day_ ): day {day_} {}
Day tomorrow() const { return ++day; }
Day yesterday() const { return --day; }
Day& operator++(){ day = ++day; return *this; }
Day& operator--(){ day = --day; return *this; }
friend ostream& operator<<( ostream& out , const Day& day )
{
out << day.day << endl;
return out;
}
};
int main()
{
Day day {DAY::MON};
cout << day << day.tomorrow();
--day;
cout << day << day.yesterday();
return 0;
}
| |