Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In your class, use three private integer data member variables to represent the date ( month , day, and year ) . Supply the following
In your class, use three private integer data member variables to represent the date month day, and year
Supply the following
Supply the following public member functions in your class.
A default constructor taking no arguments that initializes the Date object to Jan
A constructor taking three arguments month day, year that initializes the Date object to the parameter values.
It sets the Date's year to if the year parameter is less than
It sets the Date's month to if the month parameter is outside the range of to
It sets the Date's day to if the day parameter is outside the range of days for the specific month. Assume February always has days for this test.
A getDay member function that returns the Date's day value.
A getMonth member function that returns the Date's month value.
A getYear member function that returns the Date's year value.
A getMonthName member function that returns the name of the month for the Date's month eg if the Date represents it returns "February" You can return a const char or a std::string object from this function.
A print member function that prints the date in the numeric form MMDDYYYY to cout eg Month and day must be two digits with leading zeros as needed.
A printLong member function that prints the date with the month's name in the form dd month yyyy eg February to cout. This member function should call the getMonthName member function to get the name. No leading zeroes required for the day.
The class data members should be set to correct values by the constructor methods so the get and print member functions simply return or print the data member values. The constructor methods must validate their parameter values eg verify the month parameter is within the range of to and only set the Date data members to represent a valid date, thus ensuring the Date object's data members ie its state always represent a valid date.
The print member function should output the date in the format MMDDYYYY with leading zeros as needed, using the C IOStreams cout object. To get formatting to work with C IOStreams cout look at the setw and setfill manipulator descriptions, or the width and fill functions in the chapter on the C IO System.
#include
#include
#include
using namespace std; or use individual directives, eg using std::string;
class Date
methods and data necessary
;
Use separate files for the Date class definition in Date.h implementation of the member functions Datecpp and the attached test main function DateDemocpp The shortest member functions like getDay may be implemented in the class definition so they will be inlined Other member functions should be implemented in the Date.cpp file. Both Date.cpp and DateDemo.cpp will need to #include the Date.h file since they both need the Date class definition in order to compile and other include files that are needed eg iostream, string, etc
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