Thread: OO Basics

  1. #1
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499

    OO Basics

    Finally Made it!!!
    I just started taking my first OO class and I just want to be sure I have some of the basics down before moving on.

    Code:
    Class Time 
    { 
    Private: 
              int  hour,  
                    min, 
                    sec;  
    Public:  
    Time ( ) { hour = 0, min = 0, sec = 0} 
    Void load ( ) 
    {
        cout << “\n Enter Hour: “; cin >> hour;    
        cout << “\n Enter Minutes : “; cin >> min ; 
        cout << “\n Enter Seconds: “; cin >> seconds; 
    } 
    void showitem ( ) 
    {
       cout << hour << min << seconds; 
    }
    }; 
    int main ( ) 
    { 
         time t1; 
         t1.load ( );
         t1.showitem ( ); 
         return 0; 
    }
    Ok so based on this simple class that I believe I have coded correctly? Is the following correct as well.

    1. hour, min, sec = Data members?
    2. load, showitem = Function members?
    3. load, showitem = Members of t1?
    4. t1 is the owner of these Function Members?
    5. The object in this program is the entire Time class? Or are there more than one objects?

    This basically just looks like some weird structure to me.
    Any help is as always greatly appreciated. If there is anything else you can expand on thanks in advance.
    Last edited by DISGUISED; 01-04-2002 at 03:36 AM.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    7
    Well, it's all a matter of terminology I guess.
    1. Yes hour, min, sec are Data Members.
    2. I've always heard functions refered to as "Member Functions" and not "Function Members", but I don't see a real distinction.
    3. I've always thought of Members as being the data members and not the functions. That's just my interpretation, I'm not sure, but that would make hour, min and sec your members.
    4. I'm not really sure about the term "owner" and what it means.
    5. Time is a class not an object. The object is t1 which is an instance of the Time class.

    Incidentally, as you have it coded, it will not compile. In your main, you have the line:
    time t1;
    but the constructor for the Time class is Time not time -- watch your case.

    Dana

  3. #3
    Unregistered
    Guest
    for that matter Private, Public, and Void should be lower case, too, but your initial understanding of class structure seems appropriate.

    Indeed, IMO, classes are nothing more than elaborate structs, although in C++dom it is put this way: structs are classes where all members are public by default whereas all members in classes are private by default. Other than this difference, in C++, a struct is the same thing as a class.

    Class members may be data members or member functions. Some people refer to member functions as class methods.

    If you separate member declarations from member function definitions then the declarations (data member declarations and member function declaration/prototypes) is called an interface. The interface is usually placed in a header file, and the function definitions in a cpp file. This approach will become more important as the classes you use and the programs you create become more sophisticated. Doing it this way from the start is not a bad idea however.

  4. #4
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    Thanks. I understand about the capitalization. I didn't try to compile so I din't catch those typos. Sorry about that.

    If you separate member declarations from member function definitions then the declarations (data member declarations and member function declaration/prototypes) is called an interface.
    what exactly do you mean by separate them? Declare/prototype them in the header file and then code them in cpp file? I think that's what you meant. What are the advantages of doing this?

    4. I'm not really sure about the term "owner" and what it means.
    5. Time is a class not an object. The object is t1 which is an instance of the Time class.
    4. Owner is a term that is used repeatedly throughout the book I am using for the course. I will have to look more into that. We haven't had our first lecture yet. I am really just trying to get ahead, but the professor should be able to clear that one up for me.
    5. THANK YOU!! this was the one that was really confusing me. That makes complete sense the way you have explained it. This book doesn't really word things that well. It's really confusing sometimes.

    I just have to get out of my procedural way of thinking

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array bounds overflow
    By BendingUnit in forum C Programming
    Replies: 3
    Last Post: 06-18-2006, 10:45 PM
  2. "Modern C++ and Basics of OO Programming" (e-learning course)
    By Erhard Henkes in forum C++ Programming
    Replies: 5
    Last Post: 09-16-2004, 03:01 PM
  3. Desire & Fear: Two Basics of Human..
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-16-2002, 11:11 PM
  4. The Basics
    By Granger9 in forum Windows Programming
    Replies: 5
    Last Post: 09-13-2002, 05:12 PM
  5. OO in C
    By Shiro in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-05-2002, 11:02 PM