a c++ #include problem

Hi all, I'm looking for some help and I am way way new. As in school and not able to do my stupid homework.

I'm trying to #include "TimeOfDay.h" and using code::blocks.

I have the TimeOfDay.h file in place, as well as the TimeOfDay.cpp, and main.cpp
It's telling me on line 6 of main.cpp that there is no file or directory TimeOfDay.h

I've tried them in the same dir as main, and in the directories code blocks decided to stick them on creation.

I've also copied this program straight out of my textbook, as well as hunted down a version on the web at http://www.santarosa.edu/~ssarkar/CompletePrograms/Chapter12/TimeOfDayADT/TimeOfDay1/
This is the santarosa version, which is identical to what is in my book.


TimeOfDay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class TimeOfDay
{
public:
  TimeOfDay();
  TimeOfDay(int hours, int minutes, int seconds);
  TimeOfDay Increment() const;
  void Write() const;
  bool Equal(TimeOfDay otherTime) const;
  bool LessThan(TimeOfDay otherTime) const;
private:
  int hours;
  int minutes;
  int seconds;
};


TimeOfDay.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
75
76
77
78
79
80
81
82
83
//******************************************************************
// IMPLEMENTATION FILE (TimeOfDay.cpp)
// This file implements the TimeOfDay member functions
//******************************************************************
#include "TimeOfDay.h"
#include <iostream>

using namespace std;

TimeOfDay::TimeOfDay()
{
  hours = 0;
  minutes = 0;
  seconds = 0;
}

//******************************************************************

TimeOfDay::TimeOfDay(int initHours, int initMinutes, int initSeconds)
{
  hours = initHours;
  minutes = initMinutes;
  seconds = initSeconds;
}

//******************************************************************

TimeOfDay TimeOfDay::Increment() const
{
  // Create a duplicate of instance and increment duplicate
  TimeOfDay result(hours, minutes, seconds);
  result.seconds = result.seconds++;  // Increment seconds
  if (result.seconds > 59)            // Adjust if seconds carry
  {
    result.seconds = 0;
    result.minutes = result.minutes++;
    if (result.minutes > 59)          // Adjust if minutes carry
    {
      result.minutes = 0;
      result.hours = result.hours++;
      if (result.hours > 23)          // Adjust if hours carry
        result.hours = 0;
    }
  }

  return result;
}

//******************************************************************

void TimeOfDay::Write() const
{
  // Insert extra 0 if there is only one digit in a place
  if (hours < 10)
    cout << '0';
  cout << hours << ':';
  if (minutes < 10)
    cout << '0';
  cout << minutes << ':';
  if (seconds < 10)
    cout << '0';
  cout << seconds;
}

//******************************************************************

bool TimeOfDay::Equal(TimeOfDay otherTime) const
{
  return (hours == otherTime.hours
          && minutes == otherTime.minutes
          && seconds == otherTime.seconds);
}

//******************************************************************

bool TimeOfDay::LessThan(TimeOfDay otherTime) const
{
  return (hours < otherTime.hours || hours == otherTime.hours
          && minutes < otherTime.minutes || hours == otherTime.hours
          && minutes == otherTime.minutes
          && seconds < otherTime.seconds);
}


and main.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
//******************************************
// A program to create two time objects
// and manipulate them.
//******************************************
#include <iostream>
#include "TimeOfDay.h"        // For TimeOfDay class
using namespace std;

int main()
{
  TimeOfDay time1(5, 30, 0);  // Instantiate two TimeOfDay objects
  TimeOfDay time2;
  int  loopCount;

  cout << "time1: ";          // Print them and compare them
  time1.Write();
  cout << "  time2: ";
  time2.Write();
  cout << endl;
  if (time1.Equal(time2))
    cout << "Times are equal" << endl;
  else
    cout << "Times are NOT equal" << endl;

  time2 = time1;              // Set them equal

  cout << "time1: ";          // Print them and compare them
  time1.Write();
  cout << "  time2: ";
  time2.Write();
  cout << endl;

  if (time1.Equal(time2))
    cout << "Times are equal" << endl;
  else
    cout << "Times are NOT equal" << endl;

  time2.Increment();          // Increment one, print and compare
  cout << "New time2: ";
  time2.Write();
  cout << endl;
  if (time1.LessThan(time2))
    cout << "time1 is less than time2" << endl;
  else
    cout << "time1 is NOT less than time2" << endl;

  if (time2.LessThan(time1))
    cout << "time2 is less than time1" << endl;
  else
    cout << "time2 is NOT less than time1" << endl;

  TimeOfDay time4(23, 59, 55);   // Instantiate one near the maximum
  cout << "Incrementing time1 from 23:59:55:" << endl;
  for (loopCount = 1; loopCount <= 10; loopCount++)
  {
    time4.Write();
    cout << ' ';
    time4 = time4.Increment();   // Check that it overflows properly
  }
  cout << endl;
  return 0;
}


Actually, I just solved my problem. I had tried moving the .h to the same directory as main before, but I was copying. When I deleted the .h file from the include directory it worked.

Only took a week to try that one.

Topic archived. No new replies allowed.