Question: Lab Exercise - - ADTs Implemented with C + + Classes Create a Date class that contains: three private data members: month day year (
Lab Exercise ADTs Implemented with C Classes
Create a "Date" class that contains:
three private data members:
month
day
year
I leave it to you to decide the type
"setters" and "getters" for each of the data functions in total
One advantage of a "setter" is that it can provide error checking. Add assert statements to the setter to enforce reasonable conditions. For example, day might be restricted to between and inclusive.
one default constructor no arguments
one constructor with three arguments: month, day, and year
Add assert statements to enforce reasonable conditions.
a printDate function. This function will have no arguments and return void
a sameDay function. This function will have one Date argument and a boolean return type
In main in the following order:
instantiate one date object date using the default constructor
use the getters to display the month, day, and year of dateshould print the default values
read keyboard input from the user for a month, day and year
use the setters to set the values of date to the values that came from the user
read keyboard input from the user for a second date
use the constructor with three arguments to instantiate date to the second date input from the user
print both objects using printDate
print a message to say if the two days are the same testing the sameDay function
Your code should be in three files:
Date.h
@ contains the class definition
Date.cpp
includes "Date.h
contains the functions for the class
main.cpp
includes "Date.h
tests the class
Sample Output Two Runs
main
Testing the default constructor and the getters
The initialized date is MDY:
Please enter a date:Month Day Year:
Please enter a second date:Month Day Year:
Printing the two days:
The date is MDY:
The date is MDY:
The days are the sameYou have forgotten the semicolon after the closing curly bracket for the class definition in the Date. h fileYou have forgotten the scope resolution as in: void Date: : setYearint yin the Date.cpp fileYou forgot the after the function name. For example, you should write: cout
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
