Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Date
- {
- public:
- Date() :Year(2018), Month(1), Day(1) {}
- Date(int d, int m, int y) :Year(y), Month(m), Day(d) {}
- int after_a_specified_number_of_days(int);
- int subtraction_of_a_specified_number_of_days(int);
- int leap_year();
- Date assignment_of_individual_parts(Date d2);
- void date_comparison(Date d2);
- int calculating_the_number_of_days_between_dates(Date d2);
- void set();
- void show();
- private:
- int Year;
- int Day;
- int Month;
- };
- int Date::after_a_specified_number_of_days(int d2)
- {
- return(Day + d2);
- }
- int Date::subtraction_of_a_specified_number_of_days(int d2)
- {
- return(Day - d2);
- }
- int Date::leap_year()
- {
- if (Year / 4 == 0)
- {
- cout << "Year is a leap year";
- }
- else
- {
- cout << "The year is not a leap year";
- }
- }
- Date Date::assignment_of_individual_parts(Date d2)
- {
- return Date(Day + d2.Day, Month + d2.Month, Year + d2.Year);
- }
- void Date::date_comparison(Date d2)
- {
- int D = Day;
- int D2 = d2.Day;
- if (D < D2 && Month <= d2.Month && Year <= d2.Year)
- {
- cout << "The first date is more than the second" << endl;
- }
- else
- if (D > D2 && Month >= d2.Month && Year >= d2.Year)
- {
- cout << "First date less than second" << endl;
- }
- else
- {
- cout << "The first date is equal to the second" << endl;
- }
- }
- int Date::calculating_the_number_of_days_between_dates(Date d2)
- {
- return Day - d2.Day + (Month - d2.Month * 30 + (Year - d2.Year) * 365);
- }
- void Date::set()
- {
- cout << "Enter the day, month and year you want to assign" << endl;
- cin >> Day >> Month >> Year;
- }
- void Date::show()
- {
- cout << Day << '/' << Month << '/' << Year << endl;
- }
- int main()
- {
- Date n1(2018, 12, 20), n2;
- n2.set();
- n1.show();
- n2.show();
- cout << "Date after the specified number of days:" << n1.after_a_specified_number_of_days(10) << endl;
- cout << "Date after subtraction:" << n1.subtraction_of_a_specified_number_of_days(11) << endl;
- cout << "Leap Year:" << n2.leap_year() << endl;
- Date n3 = n1.assignment_of_individual_parts(n2);
- cout << "Date after assignment:";
- n3.show();
- cout << "Days between dates:" << n1.calculating_the_number_of_days_between_dates(n2);
- n1.date_comparison(n2);
- }
Advertisement
Add Comment
Please, Sign In to add comment