Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Date.h"
- using namespace std;
- int main()
- {
- Date A, B;
- cout << "Input the first month and day" << endl;
- A.GetDate();
- cout << "Input the second month and day" << endl;
- B.GetDate();
- A.WriteDate();
- A.Validate();
- B.WriteDate();
- B.Validate();
- }
- #ifndef DATE_H
- #define DATE_H
- class Date
- {
- private:
- int month;
- int day;
- public:
- Date();
- void setMonth(int m){month = m;}
- void setDay(int d){day = d;}
- int getMonth(){return month;}
- int getDay(){return day;}
- void GetDate();
- void WriteDate();
- bool Validate();
- };
- #endif
- #include <iostream>
- #include "Date.h"
- using namespace std;
- char monthNames[30][12] = {"January", "February", "March", "April", "May",
- "June", "July", "August", "September", "October", "November", "December"};
- int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- Date::Date()
- {
- month = 1;
- day = 1;
- }
- void Date::GetDate()
- {
- cout << "Input the month: ";
- int x;
- cin >> x;
- Date::setMonth(x);
- cout << "Input the day: ";
- int y;
- cin >> y;
- Date::setDay(y);
- cout << "n";
- }
- void Date::WriteDate()
- {
- cout << "The date is " << monthNames[getMonth() - 1] << " " << day <<
- "nn";
- }
- bool Date::Validate()
- {
- bool check = false;
- if((getMonth() > 0 && getMonth() < 12) && (getDay() > 0 && getDay() <=
- days[getMonth() - 1])){
- check = true;
- }
- else{
- cout << "The date is invalid. Date will be reset now" << endl;
- Date();
- }
- return check;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement