123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|541|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> C++ class, week 5

Sun, 25 Oct 2009, 00:30
Afr0
Post your answers for this week!
This week was an introduction to classes.

Questions

1. Create a class that can be used to represent a character in a role-playing game. Store the character's name, class and race.
2. Explain the three main principles of OOP.
3. What's the difference between a class and an object?
4. If you have a choice between declaring something public, private, global or local without loss of functionality, which scope should you pick?
5. What attributes present in constructors and destructors are not present in other functions?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 25 Oct 2009, 07:49
Afr0
1.



Sorry about using enums. I could have used strings, but I thought enums seemed like the most logical way to implement it.

2. Data abstraction, Data Encapsulation and Polymorphism.

4. Private, because it minimizes the risk of manipulating the data in a way that wasn't intended.

5. Constructors are called automatically during the creation of an object, and are expected to handle the object's required initialization.
Conversely, destructors are called automatically when an object is detroyed, and are expected to handle an object's destruction routine(s).

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 25 Oct 2009, 09:06
Phoenix
In your example, enums are better to use than strings. What if you assigned a character class to be 'undaed'? That's a potential source of annoyance. With enums, the error would be caught by the compiler.
Sun, 25 Oct 2009, 09:34
Afr0
Well technically the book hasn't covered enums yet.
But whatever

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!