I need to make my monday object print Monday as Mon to the console, but I am stuck at this point can anyone provide some insite?
This is what I have for errors:
s\week1lab_benjamin_horne1\week1lab_benjamin_horne1\dayoftheweek.cpp(46) : error C2664: 'DayOfTheWeek::setDay' : cannot convert parameter 1 from 'DayOfTheWeek' to 'std::string'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\ben\documents\visual studio 2008\projects\week1lab_benjamin_horne1\week1lab_benjamin_horne1\dayoftheweek.cpp(47) : error C2146: syntax error : missing ';' before identifier 'monday'
1>c:\users\ben\documents\visual studio 2008\projects\week1lab_benjamin_horne1\week1lab_benjamin_horne1\dayoftheweek.cpp(49) : error C2143: syntax error : missing ';' before 'return'
This function does nothing. You're just taking day and assigning it to itself. What you probably meant to do was assign the passed parameter to day. So you should give your parameter a name and then assign it appropriately.
As for your errors:
monday.setDay(monday)
2 things are wrong with this.
1) You're missing the semicolon at the end
2) 'monday' isn't a string, it's a DayOfTheWeek object. setDay needs to take a string as a parameter. So you probably meant to do something like this instead:
void DayOfTheWeek::setDay(string daystring) // <- now it's named 'daystring'
{
//...
}
Now the passed parameter is named 'daystring' so you can use it in expressions. Now if you want to assign whatever was passed to the function to your 'day' member, you can just assign 'daystring' to 'day'.
Thanks. It compiled and the parameter is being passed however I a trying to convert the sting that is bing passed into an abriviated Monday and Tuesday, but I am getting a unidentified identifiers.
1 2 3 4 5 6
void DayOfTheWeek::printDay()const
{
if (day == Monday)
cout << "The value of the " << day << " object is Mon" << endl;
if (day == Tuesday)
cout << "The value of the " << day << " object is Tues" << endl;
You are trying to compare day with a string such as "Monday" and not a variable such as Monday. You should use quotation marks (Ex. if (day == "Monday")).
Your solution is great for your specific test cases but what if you wanted to create a DayOfTheWeek by the name of "Saturday"? It would still be abbreviated to "Tue" which isn't the output you're expecting.
I assume that by now you know how to fix that (and maybe you haven't posted the complete code here) but I still felt this was worth mentioning.
It was just to test. I eventually fixed the code and it worked out great. Thanks for the heads up though. In case you were wondering here is the code with the applied fixes.