Starting with classes: Your opinion

This is a discussion on Starting with classes: Your opinion within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Scince i am asking for opinions i decided to post in GD. I am looking to actually learn something valuable ...

  1. #1
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Starting with classes: Your opinion

    Scince i am asking for opinions i decided to post in GD.

    I am looking to actually learn something valuable in C++ scince my cs2 teacher seems to be stuck on switch statements, and it seems imo that classes is a very good thing to learn.

    I looked at the tutorial here, but before i go into any more search, i wanted your opinion as the best way to start with classes, i know this sounds odd but the whole thing has me a little confused to be honest.

    Like, how did you first learn them and what advice might you have?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I really started to understand the concept of a class when I tried to use them in a non-trivial (for me, at the time at least) program that I was interested in. In my physics class, I couldn't justify why 2 objects in a system would orbit the center of mass of the system in an ellipse, so I wrote a program that simulated and displayed their motion according to Newtonian mechanics.

    I had a vector class (the 3d arrow things, not resizable arrays) to perform the low level mathematical operations. From them, I composed a particle (which had a mass, vector position, velocity, acceleration, etc). From the particles, I then composed a System (collection of particles and their interaction).

    Trying to write System without first using the vector and particle classes would have been more difficult. I would need still need to deal with the problems vector and particle solved, except their solution would have likely been scattered and repeated throughout System, rather than isolated and solved in a more clear, reusable manner.

    It was cool in a few ways.

    It won me some money in a programming contest.
    I learned a lot about the fundamentals of object oriented programming.
    From the physics standpoint, it was cool to see how changes to the input of the system would effect the output. Trying to predict the effects of changes in the input to the output was definetely an interesting thing.

    Basically, find an interesting problem. Try to break the problem down into sub problems. Once you find a reasonable sized subproblem, implement the solution in a class, then use that class to solve the larger problem. In the end, it works out nicely I think.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I think they may help in my chat bot, thanks for the input!

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Practice, practice, and more practice. That's how I learnt them.

  5. #5
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    Simplify it...

    Think of a CLASS as a grouping b/c that's what it is. When you create a CLASS you are creating a grouping of Variables and Functions.

    You are just adding an extra Name to a fxn or var in order to organize it...

    like void myFxn(){} would be called like this if it were in a CLASS.

    MyClass.myFxn();

    You could just for your own though-process ignore the 'MyClass.' from the 'MyClass.myFxn()' so you are just calling the function 'myFxn()'. That's what I do, I just look at the stuff after the last '.', and I ignore the complicated naming before that.


    I don't wanna give you a long explanation of things so I've kept it short and there is, of course, more to classes than I have told you but the other concepts are just as simple and if you want I will try to explain them easily to you, just ask.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    People seem to have more problems understanding the idea of classes than structs. Structs seem ok to many people, since they're usually introduced as record structures.
    Classes are the same thing (basically!), except that they usually have functions (verbs) to do things, and public/private is reversed.
    A friend recently asked me what was the best way to think about classes (I'm not being pedagalogical, that's literally what he asked).
    The best answer I came up with was think of classes as lego blocks. There are basic lego blocks that you start out with, and you can build different lego blocks out of them. You then use those lego blocks to build stuff. The blocks have certain characteristics, and do certain things.
    My other idea was to think of classes after a few glasses of wine. He wouldn't understand them any better, but they wouldn't be as intimidating...
    Truth is a malleable commodity - Dick Cheney

  7. #7
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    think about it like this:

    'Dog' is a class. Lassie is an instance of the class Dog. Lassie is defined like this:
    Code:
    Dog Lassie; // Lassie is born!
    Lassie would have all of the dog related qualities like char * name, int weight, etc. and would have its own set of 'Dog' member functions (or "methods") for, jump(int distance), eat(), etc.

  8. #8
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I am looking to actually learn something valuable in C++ scince my cs2 teacher seems to be stuck on switch statements, and it seems imo that classes is a very good thing to learn.
    By the way:
    I learned OOP in a couse named CS2( Into. to Computer Sciences II), and I was lucky that the teacher was not stuck on switch statements.

    I think the best way is to first understand the concept of OOP, then the concept of classes and objects, then start with the coding.

  9. #9
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    See my CS2 teacher goes slow because we have three kids in the class, myself, a buddy, and some kid i jus met, who actually GET what shes doing. Then we have 7 juniors, the rest of the ten person class, who stare at her like DERRRRRR *insert drool here*.

    Instance:

    kid/teacher/me

    k - My program won't compile
    t - *looks at it* See you didn't declare any variables.
    k - Whats a variable?
    m - Ok thats it. You don't know what a variable is, u goof off during class, and i'm sick of it because i am trying to actually learn something and shes stuck on if's and switches for a month because u don't get it! If you dunno what a ****ing variable is go back to visual basic and quit holding me back!


    ...i got detention, but you see my point.

  10. #10
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    People move at different speeds. You have to accept this. If you don't and continue to whine about it, you only appear arrogant and idiotic.

  11. #11
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    m - Ok thats it. You don't know what a variable is, u goof off during class, and i'm sick of it because i am trying to actually learn something and shes stuck on if's and switches for a month because u don't get it! If you dunno what a ****ing variable is go back to visual basic and quit holding me back!


    ...i got detention, but you see my point.
    And that's why nerds get shoved in lockers...
    Staying away from General.

  12. #12
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>People move at different speeds. You have to accept this. If you don't and continue to whine about it, you only appear arrogant and idiotic.

    I do agree, but u gotta admit at the level of c++, being their second year of programming, the class should not be halted for like 20 minutes(we only have 40) to explain to slackers what a f'n variable is and why they need it.

    It would be different if they payed attention but they shoot spitballs and fart all damn period, joy to have in class.

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    I've substitute taught at high schools. A lot of classes were like that.
    If it's second year, maybe slackers who can't hack it shouldn't be allowed to take the course until they can.
    Truth is a malleable commodity - Dick Cheney

  14. #14
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>If it's second year, maybe slackers who can't hack it shouldn't be allowed to take the course until they can.


    exactly, they are holding the class back from what i need to know for college!

  15. #15
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Lassie would have all of the dog related qualities like char * name, int weight, etc. and would have its own set of 'Dog' member functions (or "methods") for, jump(int distance), eat(), etc.
    That kind of lost me, can u elaborate?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining multiple classes in the same header file
    By Stonehambey in forum C++ Programming
    Replies: 2
    Last Post: 08-14-2008, 11:36 AM
  2. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 11:47 AM
  3. Questions on Classes
    By Weng in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2003, 06:49 AM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 08:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04:49 AM

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