Start learning about object oriented(OO) concepts like polymorphism and inheritance. You can practice both using the following exercise.
Consider a list that can store multiple types of shapes.
Using this one list, store a square, triangle and circle. Iterate over that list and print out the area and name of each shape.
Example pseudocode of populating such a list might be
PHP Code:
List<Shape> shapes = List;
shapes.add( Circle( x, y, radius ) )
shapes.add( square( x1, y1, x2, y2, x3, y3, x4, y4) )
shapes.add( triangle( x1, y1, x2, y2, x3, y3 ) )
To demonstrate an understanding of inheritance in this exercise, have both the triangle and square object extend a polygon object.
You can use this formula for the area:
Some links to get you started result from some simple google searches:
http://www.tutorialspoint.com/cplusp...nheritance.htm
http://stackoverflow.com/questions/2...l-methods-in-c
If this exercise seems a bit daunting, other nice features to look at include generics(templates) and operator overloads.
|
All of the above will confuse any new programmers.
If you're all about "learning on your own," why are you not about "learning sequential steps"?
If he didn't know how to pass parameters (a,b), there's no way he's going to learn pushing back objects with a bunch of variables not defined within the provided pseudo-code within that one reply.
He should really be taking a look at C++ tutorials online where they list steps, not going from "Hello World" straight to "Use objective programming to 'add' shapes with variables for a parameter not given the basic usage for."
-----------------------------------------------
I suggest that if you want to learn how to use C++, you should start with basic (yet fun) programming. Not console programming (borrriinnnggg...)
Lazy Foo has some great tutorials for C++ with SDL so they teach you how to make little 2D programs.
http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php
Go ahead and click the Operating System you're currently using (windows, mac, Linux) and then select your C++ compiler (Code::Blocks, Dev-C++, Microsoft Visual Studio) and learn the fun way -- One that intrigues your mind.
|
I said and gave 'rough' pseudocode for a reason... Researching libraries yourself is all part of the learning experience. Stop trying to make me look bad son.
|
If I was new, looking at your whole "List" and "add" would lead me to the wrong path.
I would *probably* literally think that was correct programming and it would confuse me.
If you want to give him a learning experience, showing him a basic "push_back" function is not giving him an entire piece of code. He probably won't know what it is right off the bat, and therefore research it a bit.
Or at least use it for future references.