Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Exercise - C++ Classes Create a Date class that contains: Three private data members: a month day o year setters and getters for
Lab Exercise - C++ Classes Create a "Date" class that contains: Three private data members: a month day o year "setters" and "getters" for each of the data (6 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 1 and 31 inclusive. one default constructor (no arguments). Assign default values to the date. Example: 1,1,1 one constructor with three arguments: month, day, and year Add statements to enforce reasonable conditions. . a print Date function. This function will have no arguments and return void. a sameMonth function. This function will have one Date argument and a boolean return type. In main (in the following order): 1. Instantiate one date object (datel) using the default constructor 2. Use the getter methods to display the month, day, and year of datel (should print the default values) 3. Read keyboard input from the user for a month, day and year 4. Use the setters to set the values of datel to the values that came from the user 5. Read keyboard input from the user for a second date 6. Use the constructor with three arguments to instantiate date2 to the second date input from the user 7. Print both objects using print Date 8. Print a message to say if the two months are the same (testing the sameMonth 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 Testing the default constructor and the getters The initialized date is (M-D-Y):1-1-1 Please enter a date: (Month Day Year): 11 03 1976 Please enter a second date: (Month Day Year): 03 03 1999 Printing the two days: The date is (M-D-Y): 11-3-1976 The date is (M-D-Y): 3-3-1999 The months are different
Step by Step Solution
★★★★★
3.49 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
Dateh ifndef DATEH define DATEH include include include class Date private int month int day int yea...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