Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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 #include using namespace std;

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:

  1. Default Constructor: Initializes Date object to Jan 1, 1900
  2. Parameterized Constructor
  3. Copy Constructor
  4. Destructor
  5. static isValidYear predicate method: valid range: 1900 to current year.
  6. static isValidMonth predicate method
  7. static isValidDay predicate method for a given month
  8. static isLeapYear predicate method

In C++, please do not google

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions