For unlimited access to Homework Help, a Homework+ subscription is required.

you have the following statements define the class dataType.h to implement the date in a program:

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.

 

bool isLeapYear();

//Function to determine whether the year is a leap year.

 

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

};

 

Further, the definitions of the member functions are as follows:

#include <iostream>

#include "dateType.h"

 

using namespace std;

 

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

{

if (year >= 1)

dYear = year;

else

dYear = 1900;

 

if (1 <= month && month <= 12)

dMonth = month;

else

dMonth = 1;

 

switch (dMonth)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

if (1 <= day && day <= 31)

dDay = day;

else

dDay = 1;

break;

case 4:

case 6:

case 9:

case 11:

if (1 <= day && day <= 30)

dDay = day;

else

dDay = 1;

break;

case 2:

if (isLeapYear())

{

if (1 <= day && day <= 29)

dDay = day;

else

dDay = 1;

}

else

{

if (1 <= day && day <= 28)

dDay = day;

else

dDay = 1;

}

}

}

 

int dateType::getDay() const

{

return dDay;

}

 

int dateType::getMonth() const

{

return dMonth;

}

 

int dateType::getYear() const

{

return dYear;

}

 

bool dateType::isLeapYear()

{

 

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

return true;

else

return false;

}

 

void dateType::printDate() const

{

cout << dMonth << "-" << dDay << "-" << dYear;

}

 

//constructor

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

{

setDate(month, day, year);

}

 

 

You have the following statements:

dateType date1(3, 15, 2008);

dateType date2(15, 20, 2008);

dateType date3(2, 30, 2009);

 

 

Write a test main() C++ program to print pintDate() and checking whether the written date has the leap year. Rewrite the definitions of the function SetDate and the constructor so that the values of the month, day, and year are checked before storing the date in the member variables. Add a member function, isLeapYear, to check whether a year is a leap year.

Write a test main() C++ Program:

/*

// Name: Your Name

// ID: Your ID

*/

#include <iostream>

#include "dateType.h"

 

using namespace std;

 

int main()

{

dateType date1(3, 15, 2008);

dateType date2(15, 20, 2008);

dateType date3(2, 30, 2009);

dateType date4;

 

int m, d, y;

 

YOUR CODE HERE

return 0;

}

Avatar image
behshdbv1 asked for the first time
Avatar image
hshekdodk12 asked for the first time
Avatar image
bzhsbehbdk asked for the first time
Avatar image
wazellia asked for the first time
Avatar image
sendry334 asked for the first time
Avatar image
dlkoamedi7 answered this question
Avatar image
dlkoamedi7 answered this question
Avatar image
dlkoamedi7 answered this question

Start filling in the gaps now
Log in