Question
#include pch.h #include #include using namespace std; class Date { private: int year; int month; int day; const int NMONTHS = 12; int numDays[12] =
#include "pch.h" #include
class Date { private: int year; int month; int day; const int NMONTHS = 12; int numDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public:
Date() { year = 1; month = 1; day = 1; }
Date(int month, int day, int year) { if (month <= 0 || month > NMONTHS) { cout << "Invalid month entered!!!" << endl; } else if (day <= 0 || day > numDays[month - 1]) { cout << "Invalid day entered!!!" << endl; } else if (year < 1900 || year>2025) { cout << "Invalid year entered!!!" << endl; } else { this->year = year; this->month = month; this->day = day; } }
void USDateDisplay() { cout << "US date format : "; if (month < 9) { cout << "0" << month; } else { cout << month; } cout << "/"; if (day < 9) { cout << "0" << day; } else { cout << day; } cout << "/"; cout << year << endl;
}
void displayDateFormate1() { if (month < 9) { cout << "0" << month; } else { cout << month; } cout << "/"; if (day < 9) { cout << "0" << day; } else { cout << day; } cout << "/"; cout << year << endl;
}
string nameOfMonth(int month) { month--; string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return months[month]; }
void displayDateFormate2() { cout << nameOfMonth(month) << " " << day << "," << year << endl;
}
void displayDateFormate3() { cout << day << " " << nameOfMonth(month) << " " << year << endl; }
void setDay(int dayIn) { if (dayIn <= 0 || dayIn > numDays[month - 1]) { cout << "Invalid day entered!!!" << endl; } else { day = dayIn; } }
void setMonth(int monthIn) { if (monthIn <= 0 || monthIn > NMONTHS) { cout << "Invalid month entered!!!" << endl; } else { month = monthIn; } } };
int main() {
Date date(12, 25, 2020); date.displayDateFormate1(); date.displayDateFormate2(); date.displayDateFormate3();
}
REQUIREMENTS:
Problem Description:
- Extend the Date Class that was created above
Include the following methods:
- Default Constructor: Initializes Date object to Jan 1, 1900
- Parameterized Constructor
- Copy Constructor
- Destructor
- static isValidYear predicate method: valid range: 1900 to current year.
- static isValidMonth predicate method
- static isValidDay predicate method for a given month
- static isLeapYear predicate method
In C++, please do not google
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started