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>
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++;
}
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 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:
}
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
First of all, the next time you post code, please use [ code ] [ /code ] tags (remove the spaces) and indent it. More people might be willing to help if the code is easy to read.
Now, to the error messages:
error C3861: 'theJulianDate': identifier not found
This one is pretty obvious. Inside FancyDateClass::getDayOfWeek(), you call theJulianDate(), but the function you declared is called julianDate().
error C2063: 'FancyDateClass::isLeapYear' : not a function
This is also pretty clear. Look at your declaration of what was supposed to be FancyDateClass::isLeapYear(). You forgot the parameter list.
The third error message is not as clear, but it still points out the problem:
cannot convert from 'int' to 'const std::basic_string<_Elem,_Traits,_Ax>'
Somewhere in your code you're trying to pass an int where an std::string is required. Check the return value of FancyDateClass::toString().
On a side note, the use of (void) as a parameter list is not necessary in C++. An empty list will do it.
Finally, there's no inheritance in the above code. You should review the subject.