header files

This is a discussion on header files within the C++ Programming forums, part of the General Programming Boards category; I have a program that was given to us from our teacher. I am having trouble compiling it. I keep ...

  1. #1
    jjg
    jjg is offline
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    header files

    I have a program that was given to us from our teacher. I am having trouble compiling it. I keep getting an error during the compile. The error message says: The compiler could not find the named file. It stops on unable to open include file 'DATE.H'.

    I am Using Borland C++ 5.02. I pasted the code below, hopefully it helps.

    Code:
    /**Date.cc implements Date class**/
    #include <iostream>
    #include "Date.h"
    using namespace std;
    
    Date::Date(unsigned m, unsigned d, unsigned y)
    {
     month = m;
     day = d;
     year = y;
    }
    
    void Date::Display(ostream & out) const
    {
     out <<month<<'-'<<day<<'-'<<year;
    }
    
    bool Date::operator<(const Date & dt) const
    {
     if (year < dt.year)
      return true;
     else if (year == dt.year)
      {
       if (month < dt.month)
        return true;
       else if (month == dt.month)
        {
         if (day < dt.day)
          return true;
        }
      }
     return false;
    }
    /** Date.h -------------------------------------**/
    
    #include <iostream>
    using namespace std;
    
    class Date
    {
    /******** Member functions ********/
    public:
    
    Date();
    Date(unsigned initMonth, unsigned initDay, unsigned initYear);
    void Display(ostream & out) const; 
    unsigned getMonth() {return month;}
    unsigned getDay() {return day;}
    unsigned getYear() {return year;}
    void setMonth(unsigned m) {month = m;}
    void setDay(unsigned d) {day = d;}
    void setYear(unsigned y) {year = y;}
    bool operator<(const Date & dt) const;
    
     
    
    /********** Data Members **********/
    private:
     unsigned month, day, year;
    
    }; // end of class declaration
    
    //----- Definition of default constructor
    inline Date::Date()
    {
     month = 1;
     day = 1;
     year = 2000;
    }
    
    
    /**Test Date.cc, Date.h**/
    #include <iostream>
    #include "Date.h"
    
    void main()
    {
     Date now, then;
     now.setMonth(9);
     now.setDay(1);
     now.setYear(2002);
     then.setMonth(11);
     then.setDay(15);
     then.setYear(1988);
     cout<<"\nIt is now ";
     now.Display(cout);
     cout<<endl;
     if (now < then)
      cout<<"\nNow is before then\n";
     else
      cout<<"\nNow is not before then\n";
    }
    [code tags added by ygfperson]
    Thanks.....

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You have this split into 3 separate files right?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    This doesn't answer your question, but have a read of this one.

    Also, void main is wrong, use int main and return 0; at the end.

    >You have this split into 3 separate files right?
    ... in the same directory as each other....?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21