May 12, 2011 at 4:42am UTC
I have tried to use both utility functions but have had no luck.
dayoftheweek.cpp(66) : error C2660: 'DayOfTheWeek::toNumber' : function does not take 0 arguments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#include <iostream>
#include <string>
using namespace std;
class DayOfTheWeek
{
public :
void setDay(string);
void printDay();
string getDay()const ;
string plusOneDay();
string minusOneDay();
string addDays(int incr);
private :
int day;
int toNumber(string);
string toName(int );
};
void DayOfTheWeek::printDay()
{
cout << "The value of the " << day << " object is " ;
if (getDay() == "Monday" )
cout << "Mon" << endl;
if (getDay() == "Tuesday" )
cout << "Tues" << endl;
if (getDay() == "Wednesday" )
cout << "Wed" << endl;
if (getDay() == "Thursday" )
cout << "Thur" << endl;
if (getDay() == "Friday" )
cout << "Fri" << endl;
if (getDay() == "Saturday" )
cout << "Sat" << endl;
if (getDay() == "Sunday" )
cout << "Sun" << endl;
}
void DayOfTheWeek::setDay(string d)
{
day = toNumber(d);
}
string DayOfTheWeek::getDay()const
{
return toNumber();
}
string DayOfTheWeek::plusOneDay()
{
int add = day + 1;
return toName(add);
}
string DayOfTheWeek::minusOneDay()
{
int minus = day - 1;
return toName(minus);
}
string DayOfTheWeek::addDays(int incr)
{
int idx = day + incr;
if (idx < 0) idx += 7;
return toName(idx);
}
int DayOfTheWeek::toNumber(string name)
{
if (toName(day)== "Monday" ) return 0;
if (toName(day)== "Tuesday" ) return 1;
if (toName(day) == "Wedensday" ) return 2;
if (toName(day) == "Thursday" ) return 3;
if (toName(day) == "Friday" ) return 4;
if (toName(day) == "Saturday" ) return 5;
if (toName(day) == "Sunday" ) return 6;
}
string DayOfTheWeek::toName(int idx)
{
idx = idx % 7;
switch (idx)
{
case 0: return "Monday" ; break ;
case 1: return "Tuesday" ; break ;
case 2: return "Wednesday" ; break ;
case 3: return "Thursday" ; break ;
case 4: return "Friday" ; break ;
case 5: return "Saturday" ; break ;
case 6: return "Sunday" ; break ;
}
}
int main()
{
DayOfTheWeek monday;
monday.setDay("Monday" );
monday.printDay();
return 0;
}
Last edited on May 12, 2011 at 4:43am UTC
May 12, 2011 at 4:49am UTC
Its the line 65 of the code you pasted the function toNumber is called with 0 arguments and you have only one definition of the function that takes 1 string argument.
Either provide another function (a type of default one) that takes no argument; or declare the only parameter as default parameter; or pass some string value in function call at line 65...
May 12, 2011 at 12:44pm UTC
think about the purpose of getDay function.
what is supposed to be returned? a number? a string? think about that and you will realize the right code for that function. remeber what toNumber and toName are for. and remember what is the type of the variable day.
hope this will do, if not, ask again an ill try to be more clear about what i meant.