Question
In C++ Implement the class Date defined as follows: /* date.h */ #ifndef DATE_H_ #define DATE_H_ class Date { public: Date(int=1, int=1, int=2000); // sets
In C++
Implement the class Date defined as follows:
/* date.h */
#ifndef DATE_H_
#define DATE_H_
class Date {
public:
Date(int=1, int=1, int=2000); // sets day, month, year
void printDate() const; // print date to the screen
private:
int day;
int month;
int year;
};
#endif /* DATE_H_ */ /*
date.cpp */
#include
#include "date.h"
using namespace std;
// Constructor
Date::Date (int d, int m, int y)
{
day = d;
month = m;
year = y ;
}
// print date
void Date::printDate() const
{
cout << month << "/" << day << "/" << year << " ";
}
a. Add a new function to the class Date that sets the date. The function should take three arguments that represents the day, month, and year and sets the data members of the class Date. Ensure that the dates are valid. For example, you should not have a day which is beyond 31. Assume that we do not deal with leap years (a year with an extra day).
b. Add a new function to the class Date that returns the month in letters (e.g., January, February, etc.).
c. Add a new function that returns the number of days between two given dates.
d. Test the new functions of the class Date by creating statically two objects and invoking the new member functions on both objects so as to validate their correctness.
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