Question: The class date Type was designed to implement the date in a program, but the member function set Date and the constructor do not check

The class date Type was designed to implement the date in a program, but the member function set Date and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function set Date and the constructor so that the values for the month (1 to 12), day (1 to 31), and year (4 digits) are checked before storing the date into the member variables. Add a member function, is Leap Year, to check whether a year is a leap year. Moreover, write a test program to test your class.

Thats the header file.

#ifndef dateType_H

#define 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.

Private:

int dMonth; //variable to store the month

int dDay; //variable to store the day

int dYear; //variable to store the year

};

#endif

Thats the implementation file

//Implementation file date

#include <iostream>

#include "dateType.h"

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)

{

dMonth = month;

dDay = day;

dYear = year;

}

I need the mainprogram.cpp and edit the headerfile and the implemenation file.

Step by Step Solution

3.54 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To address the question we need to rewrite the dateType class to validate the date when setting or initializing it Well also implement a function to check for leap years and create a test program Here... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!