Question: Consider the following class declaration: class Date { public: / / constructors Date ( ) ; Date ( int day, int month, int year )
Consider the following class declaration:
class
Date
public:
constructors
Date;
Dateint day, int month, int year;
accessors
int getDay
const; int
getMonth const;
int getYear
const;
mutators
void setDayint day;
void setMonthint
month; void
setYearint year;
operators to calculate next and previous
days Date &operator;
Date &operator;
bool operatorconst Date
&d;
private:
the current day month and year
int theday;
int themonth;
int theyear;
return the length of current month, taking into
account leap
years int
monthLength;
;
Implement and test the Date class, taking the following guidelines into account:
a The default constructor should initialise the date to September
b The overloaded constructor should initialise the date with the given day, month and year.
c The functions getDay getMonth and getYear should return the current
day, month and year respectively.
d The functions setDay setMonth and setYear should change the current
day, month or year to the given value.
e The operator should advance the date by one, and return the new date.
f The operator should set the date back by one day, and return the new date.
g The operator should calculate whether the receiving date object left
argument precedes the parameter date right argument
For example, Date Date
h The private member function monthLength should return the length of the current
month, taking into account leap years. A year is a leap year if it is either i divisible by
but not by or ii divisible by In a leap year, February has days,
otherwise it has days.
i Also overload the insertion operator to output a date to the screen. For example,
the date in a above should be written as: September
Test the Date class in a C program that will do the following:
Declare a new Date object called d
Display the day, month and year of d on the screen.
Change the date to February
Advance this date by one and display the new date on the screen.
Now change the date to January
Set this date back by one and display the new date on the screen.
Finally change the date to December
Advance this date by one and display the new date on the screen.
Declare a second date object d
Determine if d is earlier than d and write the result on the screen.
Operators and are declared as member functions in the class
declaration above. Implement these operators as friend functions of class
Date also. Run your program twice each time with a different version of
the overloaded operator and ; comment the other versions out during each run
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
