c++ classes, need easy understanding?

im learning c++.(using Sams-teach yourself C++ in 10 mins(per chapter)) I have been doing well and everything seems to be coming to me pretty easy,plus I am familar with programming from many years ago. anyway, ive got methods down fine, but classes seem to ellude me a bit. My study book doesnt really give me good examples, can someone please give me a simple sample program using a class file with a main file (example), that might help kick it into better perspective. not sure why this part is giving me a hard time, I understand basically what its for, but just cant seem to get it figured out. hopefully someone else who had trouble with this part can show me what they figured out that put it into perspective.

thank you

chuck
Ok, a class can have variable and functions in them. At the end of the class you define what objects are in that class (you can actually do this in made too). So say you had a class called Rectangle. Well rectangles always have a length and a width. So those would be the variables in that class. then you could have functions for setting the length and width, and one for calculating area ex:

1
2
3
4
5
6
7
8
9
class Rectangle
{
private:
   double length;
   double width;
public:
   double getArea();
   void setLength_Width()
} rect;


the rect after the } declares an object called rect with the class Rectangle. That means it has a length and width and can use those functions.

ex rect.length = 5 would set the length of rect to 5.

Not sure if that clears anything up. I had problems with classes myself. Heres a great tutorial on them too. I found its a lot better to read like 3+ tutorials on the same subject, cause you get different viewpoints and explanations and it just clicks faster.

http://www.cplusplus.com/doc/tutorial/classes/
(theres two pages, classes(I) and classes(II)
Last edited on
ok ,I will give u a very good example but just wait for tomorrow , coz today I don't have much time ok , just tomorrow
by
What in particular are you having trouble with? It will be easier to help if you narrow down the topic.
Topic archived. No new replies allowed.