Classes Help expanded

troubleshooting again

Page 1 of 1

5 Replies - 488 Views - Last Post: 17 July 2010 - 10:31 PM Rate Topic: -----

#1 Light02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-July 10

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.

#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;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Classes Help expanded

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Classes Help expanded

Posted 17 July 2010 - 09:19 PM

...we just did this...


what more do you want? what 10 errors? why didn't you listen to us before?
Was This Post Helpful? 0
  • +
  • -

#3 Light02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-July 10

Re: Classes Help expanded

Posted 17 July 2010 - 10:01 PM

View PostNickDMax, on 17 July 2010 - 08:19 PM, said:

...we just did this...


what more do you want? what 10 errors? why didn't you listen to us before?


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

Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Classes Help expanded

Posted 17 July 2010 - 10:12 PM

Missing name of the parameter
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)



Was This Post Helpful? 2
  • +
  • -

#5 OnlineCop  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 73
  • Joined: 16-April 10

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:
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.
Was This Post Helpful? 1
  • +
  • -

#6 Light02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-July 10

Re: Classes Help expanded

Posted 17 July 2010 - 10:31 PM

thank you for the trouble shooting Nakor
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1