I have written my code for my class and i keep getting a couple of errors. Could someone take a look for me and point me in the right direction.
Here is my code:
// DateProject.cpp : Defines the entry point for the console application.
//
/*specification: Create a date class with constructors and a destructor */
#include <stdarg.h>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class FancyDateClass
{
private:
int day;
int month;
int year;
static int objectCount;
public:
string toString(void);
string getMonth(void);
int getDayOfWeek(void);
int julianDate(void);
bool isLeapYear;
int setDate(int theDay, int theMonth, int theYear);
// int subtract(FancyDateClass &aDateObj);
void getDate(int &theDay, int &theMonth, int &theYear);
void displayDate(void);
//constructors
FancyDateClass();
FancyDateClass(int theDay, int theMonth, int theYear);
FancyDateClass(const FancyDateClass &aDateObj);
//destructor
~FancyDateClass();
};
int FancyDateClass::objectCount = 0;
int main (void)
{
}
FancyDateClass::FancyDateClass()
{
//default constructor
day = 0;
month = 0;
year = 0;
objectCount++;
}
FancyDateClass::FancyDateClass(int theDay, int theMonth, int theYear)
{
//parameterized constructor
setDate(theDay, theMonth, theYear);
objectCount++;
}
FancyDateClass::FancyDateClass(const FancyDateClass &aDateObj)
{
//copy constructor
day = aDateObj.day;
month = aDateObj.month;
year = aDateObj.year;
objectCount++;
}
FancyDateClass::~FancyDateClass()
{
//destructor
objectCount--;
cout << "Number of DateClass objects instantiated " << objectCount << endl;
}
int FancyDateClass::julianDate(void)
{
//return the Julian date for the current date. The equation to calculate the Julian date is:
//this conversion algorithm is thanks to the work of Fliegel & Van Flandern
int theJulianDate = ( 1461 * ( year + 4800 + ( month - 14 ) / 12 ) ) / 4 + ( 367 * ( month - 2 - 12 * ( ( month - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( year + 4900 + ( month - 14 ) / 12 ) / 100 ) ) / 4 + day - 32075;
return theJulianDate;
}
int FancyDateClass::getDayOfWeek(void)
{
// return the day of week (M, Tu, Wed...) based on the date.
// Use the follow equation to calculate a day of week integer:
int day = theJulianDate() % 7;
// Where: Monday = 0, Tues = 1, Wed = 3
return day;
}
bool FancyDateClass::isLeapYear()
{
bool leapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
return isLeapYear;
}
string FancyDateClass::toString(void)
{
std::stringstream ss;
int month = 10;
string str;
ss << month;
ss >> str;
return month;
}
int FancyDateClass::setDate(int theDay, int theMonth, int theYear)
{
//gives the member variables a value
//returns an error code if invalid date is entered
//Error codes: 0 -valid date, 3 - bad year, 2 - bad month, 1 bad day
//check each arguement to ensure it is valid
int dateCode = 0;
//check the year
//check the year
if(theYear < 1)
dateCode = 3;
//check the month
if(theMonth < 1 || theMonth > 12)
dateCode = 2;
//check the day
int maxDays = 31;
switch (theMonth)
{
case 2:
maxDays = 28;
break;
case 4:
case 6:
case 9:
case 11:
maxDays = 30;
break;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxDays = 31;
break;
}
if (theDay < 1 || theDay > maxDays)
dateCode = 1;
//set the values right or wrong...
month = theMonth;
day = theDay;
year = theYear;
return dateCode;
}
void FancyDateClass::getDate(int &theDay, int &theMonth, int &theYear)
{
//set the value of the arguements
theDay = day;
theMonth = month;
theYear = year;
}
void FancyDateClass::displayDate(void)
{
//display the date to the screen
cout <<"\n\n";
cout << "day : " << day << endl
<< "month : " << month << endl
<< "year : " << year << endl;
}
Here are the errors:
1> error C3861: 'theJulianDate': identifier not found
1> error C2063: 'FancyDateClass::isLeapYear' : not a function
1> error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'int' to 'const std::basic_string<_Elem,_Traits,_Ax> &'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> Reason: cannot convert from 'int' to 'const std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Any help would be great
Thanks in advance!!