a. create a constructor that takes 3 integers
i. in the order month, day, year
ii. assigns the month, day, year parameters to the corresponding data items.
iii. Use the ‘setter’ to assign the values
b. a 'default' constructor - no arguments
i. using the ‘setters’ assign
1. 1 to the month
2. 1 to the day
3. 1900 to the year
/****************************************
* class definitions
****************************************/
class Date
{
private:
int month;
int day;
int year;
public:
// setters
void setMonth(int m) {month = m;}
void setDay(int d) {day = d;}
void setYear(int y) {year = y;}
void setDate(int m,int d, int y) //should this
{month = m; day = d; year = y;} //be here
// getter
int getMonth() {return month;}
int getDay() {return day;}
int getYear() {return year;}
// 'member' functions
bool calcLeapYear();
void display();
// constructors
Date();
Date(int month, int day, int year);
};
/****************************************
* member functions for above class
****************************************/
bool Date :: calcLeapYear()
{
if(year % 400 == 0)
{
returntrue;
}
if(year % 100 == 0)
{
returnfalse;
}
if(year % 4 == 0)
{
returntrue;
}
returnfalse;
}
Date :: Date() //default constructor
{
int month = 1;
int day = 1;
int year = 1900;
}
Date :: Date(int m, int d, int y) //constructor
{
month = m;
day = d;
year = y;
}
void Date :: display()
{
cout << endl;
cout << "The month is " << getMonth() << endl;
cout << "The day is " << getDay() << endl;
cout << "The year is " << getYear() << endl;
bool calcLeapYear(getYear());
if (calcLeapYear == true)
{
cout << getYear() << "is a leap year" << endl;
}
else
{
cout << getYear() << "is not a leap year" << endl;
}
}
void testDate02() //tests constructors
{
cout << "*** test 02 ***\n";
Date d2;
d2.setDate(12,25,2000); //how am I screwing this up?
}
I don't have enough to run your program but line 79 above is ringing alarm bells to me. Shouldn't this be a separate method, also without a ; at the end?
bool calcLeapYear( ) as a class method using private year property would be better and probably work with the logic you have.
In main your program line would then be bool leapTest = calcLeapYear( d2.getYear() );