subject

In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate 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 setDate 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 month day year with each seperated by a space. Output should:
Date #: month-day-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 class dateType has been provided for you.
Where is the problem located?
Here is my code
//dateType. h
#ifndef dateType_H
#define dateType_H
class dateType
{
private:
int dMonth;
int dDay;
int dYear;
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;

int getMonth() const;

int getYear() const;

void printDate() const;
//Function to output the date in the form mm-dd-.

bool isLeapYear(int year);

dateType(int month = 0, int day = 0, int year = 0);

};

#endif

//dateTypeImp. cpp

#include
#include "dateType. h"

using namespace std;

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

int noDays;
if(year<=2008)
{
dYear=year;
if(month<=12)
{
dMonth=month;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: noDays=31;
break;
case 4:
case 6:
case 9:
case 11: noDays=31;
break;
case 2: if(isLeapYear(year))
noDays=29;
else
noDays=28;
}
if(day<=noDays)
{
dDay=day;
}
else
{
cout<<"Invalid Day"< dDay=0;
}
}
else
{
cout<<"Invalid Month"< dMonth=0;
}
}
else
{
cout<<"Invalid Year"< dYear=0;
}
}

bool dateType::isLeapYear(int year)
{
if(year%4==0)
return true;
else
return false;
}
void dateType::printDate()const
{
cout<
int dateType::getMonth()const;
{
return dMonth;
}

int dateType::getDay()const;
{
return dDay;
}

int dateType::getYear()const;
{
return dYear;
}

int dateType::dateType(int month, int day, int year)
{
dMonth=month;
dDay=day;
dYear=year;
};
}

//main. cpp

#include
#include "dateType. h"
using namespace std;

int main()
{
int m, d,y;
dateType date(0,0,0);

cout<<"Enter Month";
cin>>m;
cout<<"Enter day";
cin>>d;
cout<<"Enter Year";
cin>>y;
date. setDate(m, d,y);
bool check =date. isLeapYear(y);
if(check)
cout<<"Leap Year:";
date. printDate();
system("pause");
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
Choose the best explanation for the following statement communication is symbolic
Answers: 3
question
Computers and Technology, 22.06.2019 16:00
Why should characters such as / \ " ' * ; - ? [ ] ( ) ~ ! $ { } < > # @ & | space, tab, and newline be avoided in file names?
Answers: 2
question
Computers and Technology, 22.06.2019 19:10
10. when you create a pivottable, you need to specify where to find the data for the pivottable. is it true
Answers: 2
question
Computers and Technology, 23.06.2019 13:30
Select the correct answer from each drop-down menu. which types of computer networks are bigger as well as smaller than a man? a man is a network of computers that covers an area bigger than a , but smaller than a .
Answers: 1
You know the right answer?
In this chapter, the class dateType was designed to implement the date in a program, but the member...
Questions
question
Health, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
question
Social Studies, 13.10.2020 01:01
question
Chemistry, 13.10.2020 01:01
question
History, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
question
Mathematics, 13.10.2020 01:01
Questions on the website: 13722362