Question: Consider the class dateType given in Chapter 1 1 . In this class, add the functions to overload the increment and decrement operators to increase

Consider the class dateType given in Chapter 11. In this class, add the functions to overload the increment and decrement operators to increase the date by a day and decrease the date by a day, respectively; relational operators to compare two dates; and stream operators for easy input and output. (Assume that the date is input and output in the form MM-DD- YYYY.) Also write a program to test your class.
There are three files in this: main.cpp, dataType.h, and dataType.cpp
main.cpp
#include
using namespace std;
int main(){
// Write your main here
return 0;
}
dataType.h
#ifndef dateType_H
#define dateType_H
#include
using namespace std;
class dateType
{
friend ostream& operator<<(ostream&, const dateType&);
friend istream& operator>>(istream&, dateType&);
public:
void setDate(int, int, int);
void setMonth(int);
void setDay(int);
void setYear(int);
int getMonth() const;
int getDay() const;
int getYear() const;
// Declare overloaded operator functions
bool isLeapYear();
int getDaysInMonth();
dateType(int =1, int =1, int =1900);
private:
int dMonth;
int dDay;
int dYear;
};
#endif
dataType.cpp
#include
#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;
}
}
}
void dateType::setMonth(int m)
{
dMonth = m;
}
void dateType::setDay(int d)
{
dDay = d;
}
void dateType::setYear(int y)
{
dYear = y;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getYear() const
{
return dYear;
}
int dateType::getDaysInMonth()
{
int noOfDays;
switch (dMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
noOfDays =31;
break;
case 4:
case 6:
case 9:
case 11:
noOfDays =30;
break;
case 2:
if (isLeapYear())
noOfDays =29;
else
noOfDays =28;
}
return noOfDays;
}
bool dateType::isLeapYear()
{
if (((dYear %4==0) && (dYear %100!=0))|| dYear %400==0)
return true;
else
return false;
}
dateType::dateType(int month, int day, int year)
{
setDate(month, day, year);
}
// Overload Operators
My problem is to add and define the overloaded operators ++,--,<,<=,>,>=
and to write a main.cpp all in C++
Please try to work this with three files instead of one

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!