Question: dateType.h #include #include dateType.h using namespace std; void dateType::setDate(int month, int day, int year) { if (month >= 1 && month dMonth = month; }

 dateType.h #include #include "dateType.h" using namespace std; void dateType::setDate(int month, int

dateType.h

#include

#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)

{

if (month >= 1 && month

dMonth = month;

}

if (day >= 1 && day

dDay = day;

}

if (year >= 1900) {

dYear = year;

}

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

// print date in mm-dd-yyyy format

cout

cout

}

//Constructor with parameters

dateType::dateType(int month, int day, int year)

{

setDate(month, day, year);

}

// return true if lear is leap year else false

bool dateType::isLeapYear()

{

return (dYear % 400 == 0 || (dYear % 100 != 0 && dYear % 4 == 0));

}

dateTypeImp.cpp

#include

#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)

{

// Checking month is valid

while(month12)

{

cout

cout

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day31)

{

cout

cout

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout

cout

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout

}

void dateType::isLeapYear() const

{

if ( dYear%400 == 0)

cout

else if ( dYear%100 == 0)

cout

else if ( dYear%4 == 0 )

cout

else

cout

}

//Constructor with parameters

dateType::dateType(int month, int day, int year)

{

// Checking month is valid

while(month12)

{

cout

cout

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day31)

{

cout

cout

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout

cout

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

main.cpp

#include

#include "dateType.h"

#include

using namespace std;

int main()

{

// create an instance of dateType using parameterized constructor

cout

dateType date(9, 2, 2000);

// print the date

date.printDate();

// check if the year is leap year

cout

// create an instance of dateType using setDate method

cout

dateType date2;

date2.setDate(32, 10, 1780);

// print the date

date2.printDate();

// check if the year is leap year

cout

}

Instructions In this chapter, the was designed to implement the date in a program, but the member function 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 and the constructor so that the values for the month. day, and year are checked before storing the date into the member variables. Add a member function. isLeapYear , to check whether a year is a leap year. Moreover. write a test program to test your class. Input should be format with each separated by a space. Output should resemble the following: Date \#: month-day-year An example of the program is shown below: Date 1: 3-15-2008 this is a leap year If the year is a leap year. print the date and a message indicating it is a leap year. otherwise print a message indicating that it is not a leap year. The header file for the has been provided for you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!