PDA

View Full Version : Starting with classes: Your opinion



RoD
10-29-2002, 01:00 PM
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?

SilentStrike
10-29-2002, 01:26 PM
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.

RoD
10-29-2002, 01:31 PM
I think they may help in my chat bot, thanks for the input!

The Dog
10-29-2002, 02:05 PM
Practice, practice, and more practice. That's how I learnt them.

OneStiffRod
10-29-2002, 04:40 PM
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.

salvelinus
10-29-2002, 07:08 PM
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...

face_master
10-30-2002, 01:04 AM
think about it like this:

'Dog' is a class. Lassie is an instance of the class Dog. Lassie is defined like this:
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.

ammar
10-30-2002, 03:59 AM
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.

RoD
10-30-2002, 05:12 AM
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.

golfinguy4
10-30-2002, 06:15 AM
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.

Cheeze-It
10-30-2002, 11:23 AM
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...

RoD
10-30-2002, 12:45 PM
>>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.

salvelinus
10-30-2002, 02:18 PM
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.

RoD
10-30-2002, 02:38 PM
>>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!

RoD
10-30-2002, 02:51 PM
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?

TechWins
10-30-2002, 04:55 PM
Well, I lost a lot of points on my program (test grade), because my teacher is the biggest idiot in the world. He said for me to include extra "pizzaz", so I did. But when appearantly when he was grading the program he didn't understand what it was for; I would up getting docked like 15 points out of 100. I had him come look at the program with me so I could explain it to him, but he still didn't understand. He was telling me that I don't need to have that there, while I was trying to explain to him that it was my "pizzaz". I couldn't get him to understand the least bit. The program was only to display the total charges on a phone bill after getting the info of what the bill length period was and the total minutes used with already knowing the rate was $.21 per minute. My extra "pizzaz" was that I showed the average amount of minutes used per day and the average charge per day, but I still showed what the total charges were. Basically the guy is so d*mn dumb that he couldn't understand that me including the extra stuff was my pizzaz.

The main reason I think he couldn't understand is b/c he said my layout was too confusing lol...tell me if you think it is or not:



Bill Period Length Total Minutes Avg Minutes Per Day
30 300 10

Avg charge per day - $ 2.10
Total Charge - $63.00


All in all, I was pretty ........ed off that I lost points, because my teacher is a moron. It really was a sad site to see him not being able to understand. But I guess that's what you get for a high school, Pascal teacher.:rolleyes:

So R-o-D, don't feel bad about not being able to move onto learning more complex c++. I am stuck with Pascal, which is already bad enough, but we just now started getting into simple if statements. Yippy!

lightatdawn
10-30-2002, 05:45 PM
>>That kind of lost me, can u elaborate?

Theres a small section on classes on this (http://lightatdawn.cprogramming.com) page.

RoD
10-30-2002, 06:22 PM
thanks tech, nice to know i'm not the only one. Shes not going to cover classes or anything, so i plan to boggle her mind with my final program using things she didn't teach ya know.

Thnx L@D, i appreciate it.