
04-Oct-2008, 21:11
|
|
New Member
|
|
Join Date: Oct 2008
Posts: 1
|
|
|
Error C2664: cannot convert parameter 1 from 'int' to
The problem right now seems to be here:
string 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 = julianDate() % 7;
return day;
// Where: Monday = 0, Tues = 1, Wed = 3
}
And this is the error:
Code:
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it)' : cannot convert parameter 1 from 'int' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it'
// DateProject.cpp : Defines the entry point for the console application.
//
/*specification: Create a date class with constructors and a destructor */
#include "stdafx.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);
string getDayOfWeek(void);
int julianDate(void);
bool isLeapYear(void);
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;
}
string 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 = julianDate() % 7;
return day;
// Where: Monday = 0, Tues = 1, Wed = 3
}
bool FancyDateClass::isLeapYear(){
bool leapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
return leapYear;
}
/*
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;
}
Last edited by admin : 05-Oct-2008 at 01:16.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|