-
Learning C++
Alright couple questions out there for experienced and none experience alright. How long did it take you to get comfortable with c++ and understand a majority of it. I am up too Classes and Structures Pointers and References but I am not comfortable with any of them and don't really understand Classes. So if you could answer that would be great and also anyone in college taking any programming classes tell me about the college and the classes cause next year will be college for me and I need some good advice on schools. Thanks
Ryan
-
Think of classes as a category. For example, if you have class dog, you can declare dog James, dog Herman, or dog Bourne. Each one of these dogs will have all of the properties of a dog. In c++, this is the variables and methods inside the class. To access them, you would use the instance of the class, ie James, then use the . operator, then the variable name or method name. For example, to access the public variable age of dog James, you would type James.age. Then, when you want to restrict how variables are accessed, you would declare then private. This means to access them, one has to create an additional public method inside the class that simply returns the value of the variable. To read up on this, go to the following site: http://www.stud.fim.ntnu.no/~oystesk/CPP/htm/ch06.htm and continue reading the chapters to understand references and pointers.
-
Think of classes as a VCR.....
You provide the VCR with input (a tape) or in the case of your program user input.
Now that the VCR has the input, you can access the information by pressing play on the VCR.
Now then, do you know EXACTLY what happens inside your VCR whenever you press the play button??? Of course not! and why should you??? All you care about is that the picture appears and you can watch the movie.
The same is true with classes.
You can declare a VCR class. by declaring that you automatically know that a VCR comes with a play button, rewind button, etc.
So, whenever you want to press play just call the member function of the class like so....
VCR.play();
The coolest thing about classes is that you don't have to know (unless you are writing the classes) what goes on behind the scenes.
Another cool thing about classes is inheritance.
Some VCRs are dual deck, so you can declare a class of VCR that has two tape decks. The only (ok, not technically, just humor me) thing that is different between a regular VCR and a dual deck
is the extra deck....
So, why write a whole new class?
Just declare:
public DualVCR :: VCR
and then accomidate the changes.
Hope this helps!
-
Alright I am getting classes now. You use them to break something done into its components right? Like for a computer (a really simple computer like a terminal or something) the class would be
class Computer
{
private:
int dataincomputer; //cause you don't wanna anybody accessing your data
public:
int type(); //inputing data into computer
int display(); //displaying data you input
}
int Computer::type()
{
//get keyboard input
}
so on and so forth is this right?????????
Also I have been programming hard for about 2 months would this just be considered average learning or above average???
-
one advice
I would really suggest you not to go on to another topic in C++ if you don't clearly understand the one before man. This can come back to haunt you later on, make sure you know how to do the topic FIRST and THEN move on.