# Starting with classes: Your opinion

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-29-2002
RoD
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?
• 10-29-2002
SilentStrike
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.
• 10-29-2002
RoD
I think they may help in my chat bot, thanks for the input!
• 10-29-2002
The Dog
Practice, practice, and more practice. That's how I learnt them.
• 10-29-2002
OneStiffRod
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.
• 10-29-2002
salvelinus
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...
• 10-30-2002
face_master

'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.
• 10-30-2002
ammar
Quote:

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.
• 10-30-2002
RoD
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-30-2002
golfinguy4
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.
• 10-30-2002
Cheeze-It
Quote:

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...
• 10-30-2002
RoD
>>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.
• 10-30-2002
salvelinus
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.
• 10-30-2002
RoD
>>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!
• 10-30-2002
RoD
Quote:

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?
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last