Question
c Implementing a Date ClassObjective To practice working with classes and class methods. Tasks Implement each of the class methods in the lab file: Each
c Implementing a Date ClassObjective
To practice working with classes and class methods.
Tasks
Implement each of the class methods in the lab file:
Each of the setter functions should be close to identical. In each, only set the classs attribute if the argument is an acceptable value (eg day must be between 1 and 31, month between 1 and 12, etc). If the argument isnt acceptable, output an error message to the user.
Each of the getter functions will just return the raw value for the corresponding class attribute. They should be virtually identical.
The print function should just output a standard date format (your choice of format as long as it includes year, day, and month). Dont output newline characters. Use the getter functions to get the values rather than outputting the variables directly. Make sure that the month and date get outputted with two digits (eg if the day is the 1st , it should be outputted as 01)
The class constructor should set each of the year, month, and date using the built in setter functions.
In int main, create two instances of the date class. With the first instance, use the constructor to set the instances attributes equal to a date of personal importance. With the second instance, use the classs setter functions to set the instances attributes to your graduation date (you can make up a date if you dont recall this offhand). Finally, use the class print function to output both of those dates.
Sample Output (note: your output will probably differ if you pick different dates or a date format)
Personal date: 1990-10-07
Graduation: 2016-12-20
#includeusing namespace std; class Date { private: int year; int month; int day; public: Date () {} Date(int y, int m, int d); void setYear(int y); void setMonth(int m); void setDay(int d); int getYear(); int getMonth(); int getDay(); void print(); }; int main() { return 0; }
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