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
Step: 1
Given code modification dateTypeh ifndef dateTypeH define dateTypeH class dateType public void setDa...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