Question
The class dateType, prints the date in numerical form. Some applications might require the date to printed in another form, such as March 24, 2003.
The class dateType, prints the date in numerical form. Some applications might require the date to printed in another form, such as March 24, 2003. Derive the class extDateType so that the date can be printed in either form.
Add a data member to the class extDateType so that the month can also be stored in string form.
Add a function member to output the month in the string format followed by the year -- for example, in the form March 2003.
Write the definitions of the functions to implement the operations for the class extDateType.
Needed Files:
1) dateType.h
2) dateType.cpp
3) extDateType.h
4) extDateType.cpp
5) main.cpp
________________________________________________________________________________________________
dateType.h:
class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; dYear = year
int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned.
int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned.
int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned.
void printDate() const; //Function to output the date in the form mm-dd-yyyy.
dateType(int month = 1, int day = 1, int year = 1900); //Constructor to set the date //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; dYear = year. If // no values are specified, the default values are used to // initialize the member variables.
bool isLeapYear(); int DayinMonth(); int numberOfDaysPassed(); int numberOfDaysRemaining(); private: int dMonth; //variable to store the month int dDay; //variable to store the day int dYear; //variable to store the year };
______________________________________________________________
// dateType.cpp
#include
using namespace std;
void dateType::setDate(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; }
int dateType::getDay() const { return dDay; }
int dateType::getMonth() const { return dMonth; }
int dateType::getYear() const { return dYear; }
void dateType::printDate() const { cout << dMonth << "-" << dDay << "-" << dYear; }
//Constructor with parameters dateType::dateType(int month, int day, int year) { setDate(month, day, year); }
bool dateType::isLeapYear(){ return dYear % 4 == 0; } int dateType::DayInMonth(){ if(dMonth == 2){ if(isLeapYear()){ return 29; } else{ return 28; } } else if(dMonth == 4 || dMonth == 6 || dMonth == 9 || dMonth == 11){ return 30; } else{ return 31; } }
int dateType::numberOfDaysPassed(){ int tMonth = dMonth; int count = dDay; dMonth--; while(dMonth > 0){ count += DayInMonth(); dMonth--; } dMonth = tMonth; return count; } int dateType::numberOfDaysRemaining(){ int tMonth = dMonth; int count = DayInMonth() - dDay; dMonth++; while(dMonth <= 12){ count += DayInMonth(); dMonth++; } dMonth = tMonth; return count; }
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