# C++ Operator Overload Classic Date difference question



## roberteastvillag (Apr 7, 2007)

Hi Everyone,

Hopefully I can get a lifeline here. I have a C++ assignment due monday night and am running into a brick wall. I have to create a Date Class that accepts data as: int date, int month, int year. The one part of the program I am stonewalled on is declaring a member function that returns the number of days between two dates expressed as date objects Date D1 and Date D2. I am supposed to use an overloaded operator and month array = {31,28,31....31}.

I have the enum and array declared. There are a bunch of further questions but I am stuck up front. If someone could get me going on the overloaded funstion part so I can complete the exam I would be eternally greatful. This is the last problem and I fought my way through the rest of the assignment. i am using MS Visual C++ 2005 Express edition.

This is what I have so far..... HHHHEEEEEEEEELLLLLP! Please advise.

//Question number 2
#include "stdafx.h"
#include <iostream>
using namespace std;

class Date
{
public:
Date();
Date (int day, int month, int year);
Date (const Date &); //copy constructor
~Date(); //destructor
int GetdaDay ()const {return *theDay;}
int GetdaMonth () const {return *theMonth;}
int GetdaYear () const {return *theYear;}
void SetdaDay (int setDay) {*theDay = setDay;}
void SetdaMonth (int setMonth) {*theMonth = setMonth;}
void SetdaYear (int setYear) {*theYear = setYear;}
private:	
int *theDay;
int *theMonth;
int *theYear;
};
Date:ate()
{
theDay=new int;
theMonth=new int;
theYear=new int;
*theDay=0; 
*theMonth=0;
*theYear=0;
}
Date:ate(const Date & rhs)
{
theDay=new int;
theMonth=new int;
theYear=new int;
*theDay=rhs.GetdaDay();
*theMonth=rhs.GetdaMonth();
*theYear=rhs.GetdaYear();
}
Date::~Date()
{
delete theDay;
theDay=0;
delete theMonth;
theMonth=0;
delete theYear;
theYear=0;
}
int main()
{
enum months {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,Dec,MonthsinYear};
int month_yearArray[MonthsinYear]={31,28,31,30,31,30,31,31,30,31,30,31};
int month_yearCount[MonthsinYear]={1,2,3,4,5,6,7,8,9,10,11,12};
int baseLeap = 2000;


----------

