Need Help With Function Errors

Time Class with Event Function

Page 1 of 1

5 Replies - 892 Views - Last Post: 19 November 2008 - 06:10 AM Rate Topic: -----

#1 izm94303  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 01-August 08

Need Help With Function Errors

Posted 18 November 2008 - 08:33 PM

																	

#include <iostream>
include <string>	 
using namespace std;

class Time
{

public:
	void setTime(int hour, int minute);
	void getTime(int&hr, int&min);
	void printTime() const;
	void incrementMin ();
	void incrementHrs ();
	Time(int hour, int minute);	 // constructor with parameters
	Time();					  // default constructor
private:
	int hour;
	int minute;
};

class Date
{
public: 
	Date(int month, int day, int year);
	Date();
	void getDate(int&mm, int&dd, int&yy);
	void setDate(int month = 1, int day = 1, int year = 1900);
	void printDate();
private:
	int month;
	int day;
	int year;
};

class Event
{
public:
	void setEventData(string eventName, int hour, int minute, int month, int day);
	void printEventData() const;
	Event (string eventName = "", int hour = 0, int minute = 0, int month = 1, int day = 1, int year = 1900); //Constructor		

private:
	
	Time eventTime;  // the event object is composed of a time object
	Date eventDate;  // date object
	string eventName;
};

Time::Time(){hour= minute = 0;} 
Time::Time (int hr, int min) {hour = hr; minute = min;}
void Time::getTime( int &hr, int &min) { hr = hour; min = minute;}
void Time::setTime( int hr, int min) { hour = hr; minute = min;}
void Time::printTime()
{

	int hr, int min;
	getTime (hr, min);
	if (hr < 20) cout << "0";
	cout << hr << ":";
	if (min < 20) cout << "0";
}
Date::Date() {month = day = 1; year = 1900;}
Date::Date(int m, int d, int y) : month(m), day(d), year(y) { }; 
void Date::getDate(int &mm, int &dd, int &yy) { mm = month;  dd = day;  yy = year; }
void Date::setDate(int mm, int dd, int yy) { month = mm; day = dd; year = yy; }
void Date::printDate() 
{ 
	int mm, dd, yy;
	getDate(mm, dd, yy);
	if (mm < 20) cout << "0";
	cout << mm << "/";
	if (dd < 20) cout << "0";
	cout << dd << "/";
	if (yy < 100) cout << "20";
	cout << year;

}

Event::Event(string name, int hour, int minute, int month, int day, int year)
	: eventTime(hour,minute), eventDate(month,day,year)
{
	eventName = name;
}

void Event::setEventData()
{
	eventName = name;
	eventTime.setTime(hr, min);
	eventDate.setDate(mon, day, yr);
}

void Event::printEventData()
{
	cout << eventName << " occurs ";
	eventDate.printDate();
	cout << " at ";
	eventTime.printTime();
}

int main()

{

	Event event("New Year's Day", 0, 1, 1, 1, 2008);
	event.printEventData();
	cout << endl;
	event.setEventData("Mother's Day");
	event.printEventData();
	cout << endl;
	
	return 0;
} 


_____________________________________________________________________________________________________________

I'm getting the following error messages;

Error 3 error C2511: 'void Event::printEventData(void)' : overloaded member function not found in 'Event'
Error 2 error C2511: 'void Event::setEventData(void)' : overloaded member function not found in 'Event'
Error 1 error C2511: 'void Time::printTime(void)' : overloaded member function not found in 'Time'
Error 4 error C2660: 'Event::setEventData' : function does not take 1 arguments

This post has been edited by izm94303: 18 November 2008 - 08:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need Help With Function Errors

#2 Gilthanis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 20-September 08

Re: Need Help With Function Errors

Posted 18 November 2008 - 08:44 PM

First off, don't forget to add the # to the

Quote

include <string>

So that it's

Quote

#include <string>


And your printTime() prototype and header are not the same...
void printTime() const;
...
void Time::printTime()



I'm not really sure why you put the const there, but you might just need to take that off.

Also in your printTime() function, you double declared an int.
void Time::printTime()
{
int hr, int min;


It should be...
void Time::printTime()
{
int hr, min;


In your setEventData prototype and header are not the same either... Your prototype has 5 or 6 arguments, but when when you declare the function, you don't list any. - And you also need to add int year to both declarations.

You have essentially the same problem with your printEventData() function. You need to make sure that the prototype and header match up.

- Gilly
Was This Post Helpful? 0
  • +
  • -

#3 izm94303  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 01-August 08

Re: Need Help With Function Errors

Posted 18 November 2008 - 08:46 PM

View PostGilthanis, on 18 Nov, 2008 - 07:44 PM, said:

First off, don't forget to add the # to the

Quote

include <string>

So that it's

Quote

#include <string>


And your printTime() prototype and header are not the same...
void printTime() const;
...
void Time::printTime()



I'm not really sure why you put the const there, but you might just need to take that off.

Also in your printTime() function, you double declared an int.
void Time::printTime()
{
int hr, int min;


It should be...
void Time::printTime()
{
int hr, min;


In your setEventData prototype and header are not the same either... Your prototype has 5 or 6 arguments, but when when you declare the function, you don't list any. - And you also need to add int year to both declarations.

You have essentially the same problem with your printEventData() function. You need to make sure that the prototype and header match up.

- Gilly



Thanks Gilly. I'll try your suggestions :)
Was This Post Helpful? 0
  • +
  • -

#4 Gilthanis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 20-September 08

Re: Need Help With Function Errors

Posted 18 November 2008 - 08:46 PM

No problem!

Good luck and God bless. =)

- Gilly


And P.S. - When you call setEvent for Mother's Day - you need to have all of the arguments filled (i.e. every variable in the function declaration). =)

This post has been edited by Gilthanis: 18 November 2008 - 08:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 izm94303  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 01-August 08

Re: Need Help With Function Errors

Posted 18 November 2008 - 09:16 PM

View PostGilthanis, on 18 Nov, 2008 - 07:46 PM, said:

No problem!

Good luck and God bless. =)

- Gilly


And P.S. - When you call setEvent for Mother's Day - you need to have all of the arguments filled (i.e. every variable in the function declaration). =)



#include <string>
#include <iostream>

using namespace std;



class Time
{

public:
	void setTime(int hour, int minute);
	void getTime(int&, int&);
	void printTime();
	void incrementMin ();
	void incrementHrs ();
	Time(int hour, int minute); // constructor with parameters
	Time();						// default constructor
private:
	int hour;
	int minute;
};

class Date
{
public: 
	Date(int month, int day, int year);
	Date();
	void getDate(int&mm, int&dd, int&yy);
	void setDate(int month = 1, int day = 1, int year = 1900);
	void printDate();
private:
	int month;
	int day;
	int year;
};

class Event
{
public:
	void setEventData(string eventName, int hour, int minute, int month, int year, int day);
	void printEventData();
	Event (string eventName = "", int hour = 0, int minute = 0, int month = 1, int day = 1, int year = 1900); //Constructor		

private:
	
	Time eventTime;  // the event object is composed of a time object
	Date eventDate;  // date object
	string eventName;

};

Time::Time(){hour= minute = 0;} 
Time::Time (int hr, int min) {hour = hr; minute = min;}
void Time::getTime( int &hr, int &min) { hr = hour; min = minute;}
void Time::setTime( int hr, int min) { hour = hr; minute = min;}
void Time::printTime()
{

	int hr, min;
	getTime (hr, min);
	if (hr < 20) cout << "0";
	cout << hr << ":";
	if (min < 20) cout << "0";
}
Date::Date() {month = day = 1; year = 1900;}
Date::Date(int m, int d, int y) : month(m), day(d), year(y) { }; 
void Date::getDate(int &mm, int &dd, int &yy) { mm = month;  dd = day;  yy = year; }
void Date::setDate(int mm, int dd, int yy) { month = mm; day = dd; year = yy; }
void Date::printDate() 
{ 
	int mm, dd, yy;
	getDate(mm, dd, yy);
	if (mm < 20) cout << "0";
	cout << mm << "/";
	if (dd < 20) cout << "0";
	cout << dd << "/";
	if (yy < 100) cout << "20";
	cout << year;

}

Event::Event(string name, int hour, int minute, int month, int day, int year)
	: eventTime(hour,minute), eventDate(month,day,year)
{
	eventName = name;
}

void Event::setEventData()
{
	eventName = name();
	eventTime.setTime();
	eventDate.setDate();
}

void Event::printEventData();
{
	cout << eventName << " occurs ";
	eventDate.printDate();
	cout << " at ";
	eventTime.printTime();
}

int main()

{

	Event event("New Year's Day", 0, 1, 1, 1, 2008);
	event.printEventData();
	cout << endl;
	event.setEventData("Mother's Day");
	event.printEventData();
	cout << endl;
	
	return 0;
} 



Now I'm getting the following errors, I'm not getting it so far.

Error 3 error C2447: '{' : missing function header (old-style formal list?)
Error 1 error C2511: 'void Event::setEventData(void)' : overloaded member function not found in 'Event'
Error 4 error C2660: 'Event::setEventData' : function does not take 1 arguments
Error 2 error C2761: 'void Event::printEventData(void)' : member function redeclaration not allowed
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,667
  • Joined: 23-August 08

Re: Need Help With Function Errors

Posted 19 November 2008 - 06:10 AM

Errors:
Error 2 error C2761: 'void Event::printEventData(void)' : member function redeclaration not allowed 
Error 3 error C2447: '{' : missing function header (old-style formal list?)

Solution: Get rid of the semicolon after the method definition here:
void Event::printEventData();
{
    ...
}

Errors:
Error 1 error C2511: 'void Event::setEventData(void)' : overloaded member function not found in 'Event'
Error 4 error C2660: 'Event::setEventData' : function does not take 1 arguments 

Solution: The setEventData method that you've prototyped takes 6 arguments, but the one you've defined takes none, and you're trying to use a non-existent method that takes one argument.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1