Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Date
- {
- public:
- Date (const string & date)
- {
- // if (stoi(date.substr(0,2)) > 31 || stoi(date.substr(3,2)) > 12 ||
- // (stoi(date.substr(0,2)) > 29 && stoi (date.substr(3,2)) == 2))
- // throw "Error! A non valid date!";
- this->day = stoi(date.substr(0,2));
- this->month = stoi(date.substr(3,2));
- this->year = stoi(date.substr(6,4));
- }
- string DateAfter (string& date, int days);
- string DateBefore (string& date, int days);
- bool LeapYear (string& date)
- {
- return this->year % 4 == 0;
- }
- void SetDay (unsigned day)
- {
- this->day = day;
- }
- void SetMonth (unsigned month)
- {
- this->month = month;
- }
- void SetYear (unsigned year)
- {
- this->year = year;
- }
- unsigned GetDay ()
- {
- return this->day;
- }
- unsigned GetMonth ()
- {
- return this->month;
- }
- unsigned GetYear ()
- {
- return this->year;
- }
- //compare dates
- bool operator == (Date & other)
- {
- return this->day == other.day && this->month == other.month && this->year == other.year;
- }
- bool operator != (Date & other)
- {
- return this->day != other.day || this->month != other.month || this->year == other.year;
- }
- unsigned DaysBetween ();
- private:
- unsigned day;
- unsigned month;
- unsigned year;
- // const static enum daysInMonth = {31;28;31;30;31;30;31;31;30;31;30;31};
- };
- int main()
- {
- cout << "Enter the date in dd.mm.yyyy format: ";
- string new_date;
- getline(cin, new_date);
- try
- {
- Date first_date(new_date);
- }
- catch (const std::exception &ex)
- {
- cout << ex.what() << endl;
- }
- cout << "The year of the first date is " << first_date.GetYear();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement