You are on page 1of 4

#include<iostream> #include<string> #include<stdlib.

h> using namespace std; class cl_date {int date, month, year; public: void input_data (long int x) { date = x % 100; x = x / 100; month = x % 100; x = x / 100; year = x; } int check_date () { if (year < 0 || year > 9999) { cout<<"Error year range exceeded"<<endl; return 0; } if (month < 1 || month > 12) { cout<<"Error month range exceeded"<<endl; return 0; } if (date <1|| date >31) { cout<<"Error date range exceeded"<<endl; return 0; } else { if ((month == 4 || month == 6 || month == 9 || month == 11) && date >30) { cout<<"Error month cannot have these many days"<<endl; return 0; } else { if((!(year%4) && (year%100)) || !(year%400)) { if(month==2 && date >29) { cout<<"Error month cannot have these many days"<<endl; return 0; } else { cout<<"OK"<<endl; return 1; } } else {

if(month==2 && date >28) { cout<<"Error month cannot have these many days"<<endl; return 0; } else { cout<<"OK"<<endl; return 1; } } } } } void display () { string mon[12] = { "Jan", "Feb", "March", "Apr", "May", "June", "July", "Aug", "Sep", "Oct" , "Nov", "Dec" }; cout << mon[month - 1] << " " << date << ", " << year << endl; } void add_to_date () { if ((!(year % 4) && (year % 100)) || !(year % 400)) { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { if (date <= 30) date++; else { date = 1; if (month < 12) month++; else { month = 1; if (year < 9999) year++; else { cout << "Increment Not Possible"; exit (1); } } }

} else { if (month == 2) if (date < 29) date++ ; else { date = 1; month++; } else if (month == 4 || month == 6 || month == 9 || month == 11) { if (date < 30) date++; else { date = 1; month++; } } } } else { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { if (date <= 30) date++; else { date = 1; if (month < 12) month++; else { month = 1; if (year < 9999) year++; else { cout << "Increment Not Possible"; exit (1); } } }

} else { if (month == 2) if (date < 29) date++; else { date = 1; month++; } else if (month == 4 || month == 6 || month == 9 || month == 11) { if (date < 30) date++; else { date = 1; month++; } } } } } };

main () { int k; long int joint_date; cout << "Enter date\n"; cin >> joint_date; cl_date obj_date; obj_date.input_data(joint_date); k=obj_date.check_date(); if(k) { obj_date.display(); obj_date.add_to_date(); obj_date.display(); } }

You might also like