#include <iostream>
#include <string>
using namespace std;
enum DAYS
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
class DayOfTheWeek
{
public:
void setDay(DAYS sday);
void printDay() const;
DAYS getDay();
int loopDay(int);
int DAYSToNum(string);
string numToDAYS(int);
private:
DAYS day;
};
void DayOfTheWeek::setDay(DAYS sday)
{
day = sday;
}
void DayOfTheWeek::printDay() const
{
cout << day;
}
DAYS DayOfTheWeek::getDay()
{
return day;
}
int DayOfTheWeek::loopDay(int nday)
{
if(nday > 7)
nday=1;
else
nday++;
}
int DayOfTheWeek::DAYSToNum(std::string)
{
int nday = 0;
if (days == "Sunday")
{
nday=1;
}
else if (days == "Monday")
{
nday=2;
}
else if (days == "Tuesday")
{
nday=3;
}
else if (days == "Wednesday")
{
nday=4;
}
else if (days == "Thursday")
{
nday=5;
}
else if (days == "Friday")
{
nday=6;
}
else if (days == "Saturday")
{
nday=7;
}
return nday;
}
string DayOfTheWeek::numToDAYS(int numDay)
{
string theDay = "";
int numDay;
if (numDay = 1)
{
theDay = "Sunday";
}
else if (numDay = 2)
{
theDay = "Monday";
}
else if (numDay = 3)
{
theDay = "Tuesday";
}
else if (numDay = 4)
{
theDay = "Wednesday";
}
else if (numDay = 5)
{
theDay = "Thursday";
}
else if (numDay = 6)
{
theDay = "Friday";
}
else if (numDay = 7)
{
theDay = "Saturday";
}
return theDay;
}
int main ()
{
DayOfTheWeek today;
DayOfTheWeek yesterday;
DayOfTheWeek tomarrow;
today.setDay(Monday);
yesterday.setDay(Sunday);
tomarrow.setDay(Tuesday);
std::string days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Satday" };
cout << "Today is " << days[today.getDay()] << endl;
cout << "Yesterday was " << days[yesterday.getDay()] << endl;
cout << "Tomarrow will be " << days[tomarrow.getDay()] << endl;
today.loopDay(10);
cout << "Ten days from now will be " << days[today.numToDAYS(nday)] << endl;
}
Classes Help expandedtroubleshooting again
Page 1 of 1
5 Replies - 392 Views - Last Post: 17 July 2010 - 10:31 PM
#1
Classes Help expanded
Posted 17 July 2010 - 08:55 PM
ok this is an expanded program for this lab I have this week I'm getting 9 errors 8 C2065 and 1 c2082 any pointers as to how I can correct these I've been going over them for 3 days now and can't get past them.
Replies To: Classes Help expanded
#2
Re: Classes Help expanded
Posted 17 July 2010 - 09:19 PM
#3
Re: Classes Help expanded
Posted 17 July 2010 - 10:01 PM
NickDMax, on 17 July 2010 - 08:19 PM, said:
reason I didn't listen to you guys before is because I didn't see the extra posts (I don't frequent this forum much), also by the time I did check I had already dropped the user input for more direct statements. Was with some mangling I was able to get it to do what I needed for it to do. and it is 9 errors 8 instances of Error Code C2065 undeclared identifier on lines 56, 60, 64, 68, 72, 76, 80, 147 and 1 instance of Error Code C2082 redefinition of formal parameter on line 90
This post has been edited by Light02: 17 July 2010 - 10:03 PM
#4
Re: Classes Help expanded
Posted 17 July 2010 - 10:12 PM
Missing name of the parameter
and you have int numDay defined as the parameter and then attempt to redefine it inside the method
int DayOfTheWeek::DAYSToNum(std::string) // should be int DayOfTheWeek::DAYSToNum(std::string days)
{
int nday = 0;
if (days == "Sunday")
{
nday=1;
}
else if (days == "Monday")
{
nday=2;
}
else if (days == "Tuesday")
{
nday=3;
}
else if (days == "Wednesday")
{
nday=4;
}
else if (days == "Thursday")
{
nday=5;
}
else if (days == "Friday")
{
nday=6;
}
else if (days == "Saturday")
{
nday=7;
}
return nday;
}
and you have int numDay defined as the parameter and then attempt to redefine it inside the method
string DayOfTheWeek::numToDAYS(int numDay)
{
string theDay = "";
int numDay;
if (numDay = 1)
#5
Re: Classes Help expanded
Posted 17 July 2010 - 10:31 PM
From line 087 on, within numToDAYS, you are assigning a value instead of evaluating the equality:
Then, what do you expect loopDay() to be doing? You are passing in a value of 10, but your code says that any value > 7 will be automatically set to equal 1. It will ALWAYS return MONDAY for any value 8..9999:
It will also not return anything. So you increment the (copy of) the value you passed in (in this case, a value of 10). Then what? You haven't returned anything. You need to add a return nday; to the end of that.
Finally, on line 142, you have:
You haven't defined "nday" in this context. It has not been defined in your main() function.
string DayOfTheWeek::numToDAYS(int numDay)
{
string theDay = "";
int numDay; // <-- get rid of this, like Nakor said
if (numDay = 1) // <-- should be "numDay == 1"
{
theDay = "Sunday";
}
else if (numDay = 2) // <-- should be "numDay == 2"
{
theDay = "Monday";
}
else if (numDay = 3) // <-- and here
{
theDay = "Tuesday";
}
else if (numDay = 4) // <-- and here
{
theDay = "Wednesday";
}
else if (numDay = 5) // <-- and here
{
theDay = "Thursday";
}
else if (numDay = 6) // <-- and here
{
theDay = "Friday";
}
else if (numDay = 7) // <-- and here
{
theDay = "Saturday";
}
return theDay;
}
Then, what do you expect loopDay() to be doing? You are passing in a value of 10, but your code says that any value > 7 will be automatically set to equal 1. It will ALWAYS return MONDAY for any value 8..9999:
int DayOfTheWeek::loopDay(int nday)
{
if(nday > 7)
nday=1;
else
nday++;
}
It will also not return anything. So you increment the (copy of) the value you passed in (in this case, a value of 10). Then what? You haven't returned anything. You need to add a return nday; to the end of that.
Finally, on line 142, you have:
cout << "Ten days from now will be " << days[today.numToDAYS(nday)] << endl;
You haven't defined "nday" in this context. It has not been defined in your main() function.
#6
Re: Classes Help expanded
Posted 17 July 2010 - 10:31 PM
thank you for the trouble shooting Nakor
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|