A little help please

I am not asking for answers, just a little guidance as to why I am receiving the errors that I'm getting after debugging. I need help with my homework assignment. My code is written below. Here is the assignment from the text book:

Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sunday for Sunday. The program should be able to perform the following operations on an object of type dayType:

a. Set the day
b. Print the day
c. Return the day
d. Return the next day
e. Return the previous day
f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g. Add the appropriate constructors


Write the definitions of the functions to implement the operations for the class dayType.

Here is my debugging errors:

Line 23 error: prototype for 'void dayType::setDay(int)' does not match any in class 'dayType'

Line 11 error: candidate is: void dayType::setDay()

Line 36 error: prototype for 'void dayType::getDay(int) const' does not match any in class 'dayType'

Line 13 error: candidate is: void dayType::getDay()

I know this is probably a really easy mistake but I am new to Programming and I have changed this code for days to no avail. Any help would be greatly appreciated. Thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include <iostream>
#include <algorithm>
#include <string>

using namespace std;
string my_Day[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

class dayType
{
public:
void setDay();
void printDay() const;
void getDay();
void incrementDay();
dayType();


private:
int myDay;
int day;
};

void dayType::setDay(int day)
{
if (0 <= day && day < 8)
myDay = day;
else
myDay = 0;
}

void dayType::incrementDay()
{
day++;
}

void dayType::getDay(int day) const
{
day = myDay;
}

void dayType::printDay() const
{
}

int main ()
{
return 0;
}
closed account (3qX21hU5)
Wells lets start with the errors you have right now.

Line 23 error: prototype for 'void dayType::setDay(int)' does not match any in class 'dayType'


What this error means is your declaration and definition for your dayType::setDay member function don't match.

Take a look at line 11 and line 23. What is different about them?

Line 36 error: prototype for 'void dayType::getDay(int) const' does not match any in class 'dayType'


Same as the one above.


Now when debugging errors remember you always want to start at the top of the list. Because a lot of the times one error in the code will cause a huge list of error messages to appear.

Also another friendly tip for handling error codes is this. Take a few hours and sit down at your computer and open up a program you have written that you know has no bugs in it and runs just like you want it to.

Now start tweaking minor things to produce errors and keep track of what you changed. Build it and look at what error messages it gives you. Try and remember them error messages and their corresponding errors. Since you created the errors on purpose it should be easy to map each error you created with the error message it produced.

Keep doing this for a while till you feel comfortable with the error messages. I guarantee you that if you take a few hours (Or even less) to do this and create a whole bunch of different errors and error messages it will say you so much more time in the long run while debugging programs.

Also if you want to take it a step farther you can look into using a debugger (There is plenty of good tutorials out there). Learning to use a debugger will save you hundreds of hours of hair pulling and is one of the most important skills a programmer can know.

Anyways just some friendly tips, let me know if you need help with anything else.
Last edited on
You should read error messages. They are clear enough. For example you declared function setDay without parameters in the class definition

void setDay();


while in its definition you pointed out a parameter.

void dayType::setDay(int day)
1
2
void printDay() const;
void getDay();


Its also a good habit to make your Accessor functions a constant member function seeing that they do not modify the member variables of tthe class and instead just return them. However not need but a safe and good habit to keep.
Topic archived. No new replies allowed.