I just dont get it could somebody help

This is a discussion on I just dont get it could somebody help within the C++ Programming forums, part of the General Programming Boards category; I just read the turtorial on classes (OOP) and i just dont get how that works or what it does ...

  1. #1
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003
    Posts
    39

    I just dont get it could somebody help

    I just read the turtorial on classes (OOP) and i just dont get how that works or what it does could somebody please tell me in english what i need to know?

    also what is that program supposed to do?
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    C++ allows you to define your own classes, your own types. Say, for instance, you want to write a class to represent fractions. You'd write a class that has as its private data members the numerator and denominator. Then, you'd probably want to overload the insertion and extraction operators, the boolean operators, and the arithmetic operators for your fraction class. Once you do that, you can deal with your newly defined type easily.

    Hmm, maybe that was a bit much.
    Code:
    class dog
    {
    public:
    dog(){cout<<"A dog is being born."<<endl;}
    ~dog(){cout<<"All dogs go to heaven."<<endl;}
    void speak(){cout<<"Woof!";}
    string getBreed() const{return breed;}
    void setBreed(string b){breed=b;}
    private:
    string breed;
    };
    
    
    int main()
    {
      dog fido;
      fido.setBreed("Golden Retriever");
      cout<<"Fido says ";
      fido.speak();
      cout << endl << "Fido is a " << fido.getBreed() << endl;
      return 0;
    }
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Structures with functions.

    I guess it helps if you have a good grasp of structures. I think of classes/objects as structures with functions:

    You can have a structure with variables like Doug.Height and Doug.Age or Zerg.Height and Zerg.Age. If you have a class called Person and an object called Doug, you can also have a member function called Doug.IncrimentAge(), or Doug.GetHeight().

    There is a lot of C++ to learn, so I'd recommend getting a book. I don't know how many "pages" there are in the tutorial, but Teach Yourself C++ in 21 Days, by Jesse Liberty is about 750 pages! A good book will have more detailed explanations, and more examples than a short tutorial.

    [EDIT]
    The example in the tutorial doesn't do anythng. It's an incomplete "shell" class... just an outline to get you started. Here's another tutorial.
    Last edited by DougDbug; 10-20-2003 at 07:48 PM.

  4. #4
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003
    Posts
    39
    Where are these other tutorials located
    I want to use them more often
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  5. #5
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003
    Posts
    39
    I think i figured out what my problem is:

    In the link above they have functions such as set_values is that a real funticion or it that what they are making?
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by zergdeath1
    I think i figured out what my problem is:

    In the link above they have functions such as set_values is that a real funticion or it that what they are making?
    the set_values function is a user defined function. in other words, whomever wrote the class, wrote the set_values function.

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Question www.cplusplus.com

    Where are these other tutorials located
    What? When you click-on the "another tutorial" link above it should take you to www.cplusplus.com.

  8. #8
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003
    Posts
    39
    also i keep on seeing people end cout<< "text" <<end1 what does the end1 part do the turtorials just start adding it but dont explain.
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    its not end1 its endl E N D L. endl is the same as saying /n except endl is a manipulator.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  10. #10
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Not only does endl add a newline to the output, but it also flushes the output - meaning it actually sends whatever text has been added to the output. The output in your case is the console, but it can also be many other things like a file.

Popular pages Recent additions subscribe to a feed

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