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.
The file is suppose to read/write to/from a file.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <ostream>
#include <ifstream>
using namespace std;
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 = 2000);
//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.
bool isLeapYear(int);
private:
int dMonth; //variable to store the month
int dDay; //variable to store the day
int dYear; //variable to store the year
};
void dateType::setDate(int month, int day, int year)
{bool error=false;
int max=28;
switch(month)
{ case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12: if (day > 31)
error=true;
break;
case 4 :
case 6 :
case 9 :
case 11: if (day > 30)
error=true;
break;
case 2 : if(isLeapYear(year))
max=29;
if(day>max)
error=true;
}
if(error)
{cout<<"invalid date "<<month<<"/"<<day<<"/"<<year<<" entered. Jan 1, 2000 being used\n";
month=1;
day=1;
year=2000;
}
dMonth = month;
dDay = day;
dYear = year;
}
bool dateType::isLeapYear(int year)
{ if((year%4==0&&year%100!=0)||(year%400!=0))
return true;
return false;
}
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)
{
setDate(month, day, year);
}
int main()
{dateType d1(2,29,2011);
cout<<"First date is ";
d1.printDate();
cout<<endl;
dateType d2(2,29,2008);
cout<<"Second date is ";
d2.printDate();
cout<<endl;
system("pause");
return 0;
}
i'm not sure how to fix this. I wrote this code to check for leap year. But i dont want leap year instead i want the above mentioned. Thanks for any and all help.