Undeclared indentifier error

Hello, all.

I am having some problem with this program when I break it up into a multi-file format. It runs okay when it is in one whole cpp file,

Here's how I break it down. My header file is called DayOfTheWeek.
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
#include <iostream>
#include <string>
using namespace std;

class DayOfTheWeek
{
    enum daysEnum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, total};
  
public:
  
    void setDay(string );
        // setDay(string) takes a string parameter
        // and stores the value in the day attribute.
    void printDay() const;
        // printDay() prints day's value to the console
    string getDay() const;
        // returns the value of the day attribute.
    void plusOneDay();
    void minusOneDay();
    int toNumber(string );
    void toName(int );


private:
    string day; // This is where the value of the day attribute is stored.
};


A cpp file also called DayOfTheWeek that breaks everything down.
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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>
#include "DayOfTheWeek.h"//We have to include the header file in both cpp files.
using namespace std;


string DayOfTheWeek::getDay() const 
{ 
	return day; 
}

void DayOfTheWeek::setDay(string dayObject) 
{ 
	day = dayObject; 
}
void DayOfTheWeek::printDay() const 
{ 
	cout << day << "." ; 
}
int DayOfTheWeek::toNumber(string d)
{
    if (d == "Sunday")
        return 1;
    else if (d == "Monday")
        return 2;
    else if (d == "Tuesday")
        return 3;
    else if (d == "Wednesday")
        return 4;
    else if (d == "Thursday")
        return 5;
    else if (d == "Friday")
        return 6;
    else if (d == "Saturday")
        return 7;
    else if (d == "Sunday")
        return 8;
    else return 0;
}


void DayOfTheWeek::toName(int e)
{
   
     if (e < 0)
        e = 7 - abs(e);
    if (e == 1)
        cout << "Sunday";
    else if (e == 2)
         cout << "Monday";
    else if (e == 3)
     cout << "Tuesday";
    else if (e == 4)
      cout << "Wednesday";
    else if (e == 5)
       cout << "Thursday";
    else if (e == 6)
        cout << "Friday";
    else if (e == 7)
        cout << "Saturday";
}


And my main program

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
#include "DayOfTheWeek.h"
using namespace std;

int main()
{
    enum daysEnum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, total};

    DayOfTheWeek monday;
    DayOfTheWeek tuesday;
    DayOfTheWeek wednesday;
    DayOfTheWeek thursday;
    DayOfTheWeek friday;
    DayOfTheWeek saturday;
    DayOfTheWeek sunday;



    // Set the values of the objects
    monday.setDay("Monday");
    tuesday.setDay("Tuesday");
    wednesday.setDay("Wednesday");
    thursday.setDay("Thursday");
	friday.setDay("Friday");
	saturday.setDay("Saturday");
    sunday.setDay("Sunday");

  

    // Get the value of the monday object and print it out
    string currentDay = monday.getDay();
    cout << "The value of the monday object is " << currentDay << "." << endl;

    DayOfTheWeek::daysEnum;




    int today;
    int tomorrow;
    int yesterday;

    today = toNumber("Monday");

    cout << today << endl;
    tomorrow = today + 1;
    yesterday = today - 1;

    cout << "The day before was: ";
    toName(yesterday);
    cout << endl;
   
       
    cout << "The day after is: " ;
        toName(tomorrow) ;
        cout << endl;

   

    int currentDay2 = today + 3;
    int currentDay3 = today - 3;
    currentDay3 = today % 7;

    cout << "Monday + 3 = " ;
        toName(currentDay2);
    cout << endl << "The value for the monday object is still monday" << endl;
    cout << "Monday - 3 = ";
        toName(currentDay3);

    

return 0;
}


Here are the errors I'm recieving
1>------ Build started: Project: Week_2_I-Labs, Configuration: Debug Win32 ------
1>Compiling...
1>DayOfTheWeek.cpp
1>Week_2_Homework_.cpp
1>e:\week 2 i-lab\week_2_homework_.cpp(55) : error C3861: 'toNumber': identifier not found
1>e:\week 2 i-lab\week_2_homework_.cpp(62) : error C3861: 'toName': identifier not found
1>e:\week 2 i-lab\week_2_homework_.cpp(67) : error C3861: 'toName': identifier not found
1>e:\week 2 i-lab\week_2_homework_.cpp(77) : error C3861: 'toName': identifier not found
1>e:\week 2 i-lab\week_2_homework_.cpp(80) : error C3861: 'toName': identifier not found
1>Generating Code...
1>Build log was saved at "file://c:\Users\Documents\Visual Studio 2008\Projects\Week_2_I-Labs\Week_2_I-Labs\Debug\BuildLog.htm"
1>Week_2_I-Labs - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Can someone help me out with this?
Last edited on
Use the object to call a fucntion inside a class. i.e. monday.toNumber( "Monday" );
Thank you for your response.

However, it doesn't seem to affect the toName function. I still receive identifier not found errors.
I just tried this and it works fine.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
int main()
{
    //enum daysEnum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, total};
    //DayOfTheWeek::daysEnum;
    //_____You don't actually use these

    DayOfTheWeek day;

    // Set the values of the objects
    day.setDay("Monday");		//_____Do you really need an object for each day?

  

    // Get the value of the monday object and print it out
    //string currentDay = day.getDay();
    //cout << "The value of the monday object is " << currentDay << "." << endl;
    cout << "The value of the monday object is " << day.getDay() << "." << endl;
					//_____You could just use the get function within the cout


    int today;
    int tomorrow;
    int yesterday;

    today = day.toNumber("Monday");

    cout << today << endl;
    tomorrow = today + 1;
    yesterday = today - 1;

    cout << "The day before was: ";
    day.toName(yesterday);		//_____Use the object to call the function in the class ( day. )
    cout << endl;
   
       
    cout << "The day after is: " ;
        day.toName(tomorrow) ;
        cout << endl;

   

    int currentDay2 = today + 3;
    int currentDay3 = today - 3;
    currentDay3 = today % 7;

    cout << "Monday + 3 = " ;
        day.toName(currentDay2);
    cout << endl << "The value for the monday object is still monday" << endl;
    cout << "Monday - 3 = ";
        day.toName(currentDay3);    //_____You need to code a loop around.
					//_____
					//_____enum daysEnum {
					//_____Sunday = 0,
					//_____Monday = 1,
					//_____Tuesday = 2,
					//_____Wednesday = 3,
					//_____Thursday = 4,
					//_____Friday = 5,
					//_____Saturday = 6,
					//_____total = 7};
					//_____
					//_____1 - 3 = -2
					//_____You need to code it so that 1 - 3 = 5

return 0;
}

The comments I made are by //_____
Topic archived. No new replies allowed.