RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 3166 | Replies: 15
Reply
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Help Help with Classes !!! (Homework)

  #1  
Jul 23rd, 2005
I am doing an assignment that has to use a class dayType.
The program has to set the day, print the day and return the next day.
I am receiving the error:
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
C:\Documents and Settings\Faculdade\ISM3232\Assig9\Program9\Program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)

Can somebody help me please ?
I am reading the book 100 times but can figure out what is happening.
Thanks a lot



#include <iostream>
#include <string>

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
    void printDay() const;
    
private:
    string dayofweek[7];
    int current;
    char userEntry;
};

int main();
{
	dayType myDay;
	char day;
	
	cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
	cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
	cout << endl;

	cin >> day;  

	myDay.setDay(day); // set the day
	cout << endl;
	myDay.printDay() const; // print the day
	cout << endl;
	myDay.nextDay(); // return the next day
	cout << endl;

	cout << myDay.printDay() << endl;

	return 0;
} // end of main

void dayType::setDay(char day)
{
	if (day = "m" || "M")
	{
		(dayofweek [0] == "MONDAY");
	    current = 1;
		userEntry = day;
	}

	if (day = "t" || "T")
	{
		(dayofweek [1] == "TUESDAY");
	    current = 2;
		userEntry = day;
	}

	if (day = "w" || "W")
	{
		(dayofweek [2] == "WEDNESDAY");
	    current = 3;
		userEntry = day;
	}

	if (day = "r" || "R")
	{
		(dayofweek [3] == "THURSDAY");
	    current = 4;
		userEntry = day;
	}

	if (day = "f" || "F")
	{
		(dayofweek [4] == "FRIDAY");
	    current = 5;
		userEntry = day;
	}

	if (day = "s" || "S")
	{
		(dayofweek [5] == "SATURDAY");
	    current = 6;
		userEntry = day;
	}

	if (day = "u" || "U")
	{
		(dayofweek [6] == "SUNDAY");
	    current = 7;
		userEntry = day;
	}
}

void dayType::nextDay()
{
	{
	current++;
	if (current = 7)
	current = 0;
	}

	{
	current++;
	if (current = 6)
	current = 7;
	}

	{
	current++;
	if (current = 5)
	current = 6;
	}

	{
	current++;
	if (current = 4)
	current = 5;
	}

	{
	current++;
	if (current = 3)
	current = 4;
	}

	{
	current++;
	if (current = 2)
	current = 3;
	}

	{
	current++;
	if (current = 1)
	current = 2;
	}
}

void dayType::printDay() const
{
	cout << "The day is: " << dayofweek << endl;
	printDay();
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Posts: 464
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

  #2  
Jul 23rd, 2005
Couple of problems:

if (day = "m" || "M")

must be

if ( day == 'm' || day == 'M' )
because day is a single character. (Even if it were a string you couldn't do a comparison like that, you'd need to use strcmp)

You must specify day once for each comparison. Plus, you want to do double = if you are checking for equality. A single = sets a variable...
Reply With Quote  
Join Date: Jul 2005
Posts: 26
Reputation: Rearden is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Rearden's Avatar
Rearden Rearden is offline Offline
Light Poster

Re: Help with Classes !!! (Homework)

  #3  
Jul 23rd, 2005
The setday and nextday functions may be candidates for a switch. Which would be good because you can have it do something then in the default case if the user inputs something besides a char that corresponds to a day of the week.
Reply With Quote  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

  #4  
Jul 23rd, 2005
OK. Thanks for the explanation. I fixed.
Do you see anything else wrong ?
What am I missing ?
Coulf you please give me a hint ?
Reply With Quote  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

  #5  
Jul 23rd, 2005
A switch inside a function on a class ? Is that OK ?
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,330
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 44
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Help with Classes !!! (Homework)

  #6  
Jul 24th, 2005
int main();
Reply With Quote  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

  #7  
Jul 24th, 2005
How do I get rid of this error:

Deleting intermediate files and output files for project 'Program9 - Win32 Debug'.
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
c:\documents and settings\faculdade\ism3232\assig9\program9\program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)
Reply With Quote  
Join Date: Feb 2005
Posts: 464
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

  #8  
Jul 24th, 2005
Post the offending line or full code..
Reply With Quote  
Join Date: Mar 2005
Posts: 16
Reputation: cymerman is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cymerman cymerman is offline Offline
Newbie Poster

Re: Help with Classes !!! (Homework)

  #9  
Jul 24th, 2005
ahahahahahah

#include <iostream> // library to use cin and cout
#include <string> // library to strings

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
	void printDay() const;
    
private:
    string dayofweek[7];
	int current;
	char userEntry;
};

int main();
{
	dayType myDay; // class named dayType - object named myDay
	char day;
	
	cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
	cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
	cout << endl;

	cin >> day;  

	myDay.setDay(day); // set the day
	cout << endl;
	myDay.printDay() const; // print the day
	cout << endl;
	myDay.nextDay(); // return the next day
	cout << endl;

	cout << myDay.printDay() << endl;

	return 0;
} // end of main

void dayType::setDay(char day)
{
	if ( day == 'm' || day == 'M' )
	{
		(dayofweek [0] == "MONDAY");
	    current = 1;
		userEntry = day;
	}

	if ( day == 't' || day == 'T' )
	{
		(dayofweek [1] == "TUESDAY");
	    current = 2;
		userEntry = day;
	}

	if ( day == 'w' || day == 'W' )
	{
		(dayofweek [2] == "WEDNESDAY");
	    current = 3;
		userEntry = day;
	}

	if ( day == 'r' || day == 'R' )
	{
		(dayofweek [3] == "THURSDAY");
	    current = 4;
		userEntry = day;
	}

	if ( day == 'f' || day == 'F' )
	{
		(dayofweek [4] == "FRIDAY");
	    current = 5;
		userEntry = day;
	}

	if ( day == 's' || day == 'S' )
	{
		(dayofweek [5] == "SATURDAY");
	    current = 6;
		userEntry = day;
	}

	if ( day == 'u' || day == 'U' )
	{
		(dayofweek [6] == "SUNDAY");
	    current = 7;
		userEntry = day;
	}
}

void dayType::nextDay()
{
	{
	current++;
	if (current = 7)
	current = 0;
	}

	{
	current++;
	if (current = 6)
	current = 7;
	}

	{
	current++;
	if (current = 5)
	current = 6;
	}

	{
	current++;
	if (current = 4)
	current = 5;
	}

	{
	current++;
	if (current = 3)
	current = 4;
	}

	{
	current++;
	if (current = 2)
	current = 3;
	}

	{
	current++;
	if (current = 1)
	current = 2;
	}
}

void dayType::printDay() const
{
	cout << "The day is: " << dayofweek << endl;
	printDay();
}
Reply With Quote  
Join Date: Feb 2005
Posts: 464
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Help with Classes !!! (Homework)

  #10  
Jul 24th, 2005
A couple of issues:


int main(); should be int main() (no ;)

myDay.printDay() const; should be myDay.printDay();
You can't do this:
cout << myDay.printDay() << endl;

because printDay() does not return anything (it returns void)

Also,

You'll end up with some kind of endless loop/recursion here as you are calling your self inside:
void dayType::printDay() const
{
cout << "The day is: " << dayofweek << endl;
printDay();
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:09 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC