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



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);


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;


{ case 1 :

case 3 :

case 5 :

case 7 :

case 8 :

case 10:

case 12: if (day > 31)



case 4 :

case 6 :   

case 9 :

case 11: if (day > 30)



case 2 : if(isLeapYear(year))






{cout<<"invalid date "<<month<<"/"<<day<<"/"<<year<<" entered. Jan 1, 2000 being used\n";





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 ";



dateType d2(2,29,2008);

cout<<"Second date is ";




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.

It looks like your tutor/lecturer/teacher/mentor is trying to get you to look into operator overloading. Here is a nice starting point:

In particular it reads as though you should be aiming to overload '++' and '--' intially and then move on to the relational and stream operators. Once they are overloaded you should be able to achieve something like the following:

dateType myDateTypeInstance;
myDateTypeInstance++; // Increment the 'day' value
myDateTypeInstance--; // Decrement the 'day' value

Since you haven't asked for help with anything in particular I can't really offer any specific advice (DaniWeb encourages people to do their own homework/assignments etc. - its the only way you will learn!). Once you have attempted to wrap your head around the concept of operator overloading I will be more than happy to clarify anything that you may be struggling to understand. If you think that you understand but still can't make much progress with your code then post any attempts that you've made to solve the problem and I'm sure I can point you in the right direction :)