Question: Define a class called Date with month, day and year as its only integer data. Make sure the class can be derived from. Include a
Define a class called Date with month, day and year as its only integer data. Make sure the class can be derived from.
Include a constructor with default values for all 3 data members, such as 1, 1, 1900, a destructor and a set() member function that takes 3 parameters for month, day and year and uses them to set month, day and year to the values passed to it.
Include non-member friend functions for overloading << and >> for outputting from and inputting values into Date objects.
Also, overload >, < and == to compare two dates, returning true or false, depending on the result of the comparison.
Then, publicly derive a class called hDate from Date. hDate will have an additional data member called holiday of boolean type, in addition to inheriting Date's data.
Overload << and >> operators (remeber hDate has month, day, year and holiday members). When inputting data, the user must be asked if the entered data is a holiday or not, and when displaying, it must show if it's a holiday.
Include for hDate a default constructor which calls the default constructor of Date and sets the holiday to false, as well as a constructor that takes 4 parameters: month, day, year and holiday, passing the first parameters to Date's constructor. Also, include a destructor to delete any dynamically allocated objects.
Define a class called hDateArray with two private data members: an integer called size indicating the number of hDate objects in the array and an hDate pointer called ptr to point to the first element of the array.
Define a constructor for it that takes an integer for the array size as a parameter and dynamically allocates size hDates, assigning the returned pointer to ptr.
Also, include a destructor that will release the dynamically allocated array.
Also, include a function called input() for inputting size hDates into the array and a function called output() for displaying all the hDate objects within the array.
The main program is provided to give you an idea of what is expected:
int main() { int size; //size fo the array
cout << "Enter a size for the array of dates: "; cin >> size;
//create an object of hDateArray called dates with size parameter passed to its //constructor
hDateArray dates(size);
//dates as an object of hDateArray is an array of size hDate objects each derived from //Date class
dates.input(); //enter values into the array
cout << " You entered: "; dates.output(); //display the dates entered along with if any of them is a holiday
cout << " Press any key to continue."; _getch(); return 0; }
must be c++ code please and thank you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
