Problem with "Information Hiding"

Why cant I compile this to get an object file for the actual class function definitions. It’s for information hiding. Here are my 3 files...

dayType.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream> //Import header files
#include <string>

using namespace std;

class dayType {
//Public member function prototypes of dayType    
public:
    void print();
    string returnDay();
    string nextDay();
    string prevDay();
    string newDay(int numOfDays);
    dayType(string day);
//Private members of dayType    
private:
    string currentDay;
    int dayNumber;
    string days[7]; 
}; 


dayTypeImp.cpp

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> //Import header files
#include <string>
#include "dayType.h"

using namespace std;

void dayType::print()//Function to print the current day
{
    cout << currentDay;
}
string dayType::returnDay()//Function to return the current day
{
    return days[dayNumber];
}
string dayType::nextDay()//Function to return the next day
{
    if (dayNumber == 6)
        return days[0];
    return days[dayNumber + 1];
} 
string dayType::prevDay()//Function to return the previous day
{
    if (dayNumber == 0)
        return days[6];
    return days[dayNumber - 1];  
}
string dayType::newDay(int numOfDays)//Function to return future day based on number of days given
{
    int x = numOfDays + dayNumber;
    numOfDays = x % 7;
    return days[numOfDays];
}
dayType::dayType(string day)//constructor that gets the current day and sets the day number and initializes days array
{
   currentDay = day;
   
   if (currentDay == "Sunday")
   {
       dayNumber = 0;
   }
   else if (currentDay == "Monday")
   {
       dayNumber = 1;
   }
   else if (currentDay == "Tuesday")
   {
       dayNumber = 2;
   }
   else if (currentDay == "Wednesday")
   {
       dayNumber = 3;
   }
   else if (currentDay == "Thursday")
   {
       dayNumber = 4;
   } 
   else if (currentDay == "Friday")
   {
       dayNumber = 5;
   } 
   else if (currentDay == "Saturday")
   {
       dayNumber = 6;
   }
   
   days[0] = "Sunday";
   days[1] = "Monday";
   days[2] = "Tuesday";
   days[3] = "Wednesday";
   days[4] = "Thursday";
   days[5] = "Friday";
   days[6] = "Saturday";                     
}


dayType.cpp

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
#include <iostream> //import header files including dayType
#include <string>
#include "dayType.h" 

using namespace std;

int main() 
{
    dayType myDay("Monday"); //Set myDay to Monday
    dayType temp("Sunday"); //Set temp to Sunday
    dayType anotherDay("Tuesday"); //Set anotherDay to Tuesday

    cout << "My day = "; //Print myDay with the print function
    myDay.print();
    cout << endl;
    
    //Print the previous day with the prevDay function
    cout << "The day before my day = " << myDay.prevDay() << endl;
    //Print the next day with the nextDay function
    cout << "The day after my day = " << myDay.nextDay() << endl;
    //Print temp day with the print function
    cout << "Temp day = ";
    temp.print();
    cout << endl;
    
    //Print the previous day with the prevDay function
    cout << "The day before temp day = " << temp.prevDay() << endl;
    //Print the next day with the nextDay function
    cout << "The day after temp day = " << temp.nextDay() << endl;
    //Print the current day of another day with the returnDay function
    cout << "The returned day of another day = " << anotherDay.returnDay() << endl;
    //Print the day that is a certain specified number of days in the future 
    //as a parameter with the newDay function
    cout << "13 days after another day is a " << anotherDay.newDay(13);
    
    system("PAUSE");
    return 0;
}   
What commands are you using?
I was trying to compile through VC++
If it compiles, then it is being made into an object file at some point.

Do you mean you want a library?
It wont compile though and I dont know why. Here is the error:

c:\program files\microsoft visual studio 9.0\vc\include\xlocnum(135) : error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file

Is it some setting within VC++?
Hey there.

I'm a UAT student studying for my bachelor's in Computer Science. I copied your files and ran them in my editor (I used NetBeans 7.0) and it ran just fine. I checked the error online and came across this page at MSDN that discussed manually configuring the compiler option in the Visual Studio development environment.

http://msdn.microsoft.com/en-us/library/7zc28563%28v=vs.80%29.aspx

Try this. Hopefully this will fix things.

Good Luck,
Damita Sexton
Damita - That link was exactly what I needed. I had to go into both .cpp files and fix the file name of the .h file which was set to the default. Kind of a weird setup but ended up being a VC++ thing. Pretty easy fix in the end. Thanks!
Topic archived. No new replies allowed.