Hi, I'm new to C++ and have been trying to learn on my own with a book. I've been tearing my hair out trying to figure out why the following won't compile. I simplified the class to help debug.
Header File:
.cpp file:
Header File:
#ifndef DATE_H
#define DATE_H
class Date
{
Public:
Date(int monthValue, int dayValue, int yearValue);
Date();
int GetMonth();
int GetDay();
int GetYear();
void Input();
bool Set(int m, int d, int y);
static int daysInMonth[13];
Private:
int month;
int day;
int year;
bool LeapYear(int theYear);
};
int Date::daysInMonth[] = {29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
#endif
.cpp file:
#include <iostream>
#include "date.h"
using namespace std;
Date:ate(int monthValue, int dayValue, int yearValue)
{
bool dateSet = Set(monthValue, dayValue, yearValue);
if (!dateSet)
{
month = 1;
day = 1;
year = 2000;
}
}
int Date::GetMonth()
{
return month;
}
int Date::GetDay()
{
return day;
}
int Date::GetYear()
{
return year;
}
void Date::Input()
{
int m, d, y;
char temp;
cout << "Please enter a date of the form M/D/Y: ";
cin << m << temp << d << temp << y << endl;
bool dateSet = Set(m, d, y);
do
{
cout << "Sorry, that was an invalid date. Please try again: ";
cin << m << temp << d << temp << y << endl;
bool dateSet = Set(m, d, y);
} while (!dateSet);
}
bool Date::Set(int m, int d, int y)
{
if ((m == 2) && LeapYear(y))
m = 0;
if ((m >= 1) && (m <= 12))
if ((d >= 1) && (d <= daysInMonth[m]))
if (y > 0)
{
month = m;
day = d;
year = y;
return true;
}
return false;
}
bool Date::LeapYear(int theYear)
{
bool leap;
if(theYear%400 == 0)
leap = true;
else if(theYear%100 == 0)
leap = false;
else if(theYear%4 == 0)
leap = true;
else
leap = false;
return leap;
}