Chapter 6.
1) What was the 'C' capability which allowed you to combine related variables? Did this solve the problem of connection data with behaviors?
A) That capability was a struct, which could be made available as a new data type through the use of typedef statement. It didn't solve the problem of connecting data with behaviors because struct's' and the functions that operate on them aren't cohesive wholes; functions can only be found by reading the header files for the libraries available and looking for those with the new type as parameter.
2) How do you make a new type in C++?
A) You make a new type in C++ by declaring a class.
3) What is a class?
A) A class is a collection of variables--ofter of different types--combined with a set of related functions.
4) What is another name for variables within a class? What is another name for the member functions?
A) Another name for a variable in a class is a 'data member', a member function can be called a 'method'.
5) What are the requisite parts of a class declaration? Show an example.
A) To declare the class, use the class keyword followed by the class name, an opening brace, and then list of the data member and methods of that class. End the declaration with a closing brace and a semicolon.
Example: class myClass
{
public:
int myInt;
std::string myString;
void myFunction();
};
6) What are the two things a class declaration tells your compiler?
A) It tells the compiler how big it is, without reserving any memory yet, and what data members and functions it has declared.
7) When discussing naming conventions, what's the most important point to remember?
A) That you as a programmer MUST name all your member variables, member functions and classes.
8) What is an object?
A) An object is an individual instance of a class.
9) How do you declare an object? Show an example.
A) You write the name of the class which is then followed by the name of the class object. If my class would be called myGame, then I could declare the object as follows: myGame TotalWar;
10) What operator is used to access members and methods of a class for objects created on the stack?
A) The dot ( . ) operator is used for that.
11) What is the difference between public and private members/methods within a class? Wich is default?
A) Private members can be accessed only within methods of the class itself. Public members can be accessed through any object of the class. All members of a class are private by default.
12) In general, should methods or members be private? Why?
A) Members should be kept private while in general, methods are public, the main reason is to keep your progam easy to maintain. It gives your code a longer life because design changes don't make your program obsolete.
13) What is the primary way you initialize the member data of a class.
A) By using a constructor.
14) How can you identify a constructor far a class?
A) It has the same name as the class and has no return value, not even void.
15) What is a default constructor? How is it called?
A) A default constructor is a constructor without parameters and is called by the compiler automatically if you haven't created one of your own.
16) What does "declaring a method of a class const" mean? What is the syntax for such a declaration?
A) It means that you promise not to change the member function during it's call. The syntax looks like this for example: int myFunc() const;
17) In the context of classes and objects, what is a client?
A) Clients are the parts of the program that create and use objects of your class.
18) Where do class declarations go? Wher do the member function definitions go?
A) Declarations go intoo an .h or .hpp file, member definitions go intoo a .cpp file.
19) When one class has a member variable which is an object of a different class they are said to form a _____ relationship?
A) A "has-a" relationship.
20) What is the only difference between C++ classes and C++ structs?
A) Class members and methods are by default private, with structs, they're public by default.
Chapter 11.
1) What's the purpose of a model?
A) The purpose is to create a meaningfull abstraction of the real world in a simplified manner but accuratly enough so that it can be used to predict the behaviour of things in the real world.
2) What is the basic philosophy of iterative design/development?
A) The basic philosophy is to start with a concept; an idea of what you might want to buld and develop it further step by step and iterate back to a previous step(s) to expand the design.
3) What's the difference between waterfall vs.iterative development?
A) In waterfall development, the output from one stage becomes the input to the next, problem with this is, you can't go a step back. With iterative development, you start with an idea and build upon that idea by iterating threw several stages and going back to a previous stage(s) when needed.
4) What are the 6 steps listed in your book for iterative development?
A) 1) Conceptualization.
2) Analysis.
3) Design.
4) Implementation.
5) Testing
6) Rollout.
5) What happens if you lose sight of the vision of your product?
A) Then, almost surely, your project is doomed.
6) What is a use case?
A) It is a high-level description of how the product will be used. Use cases drive not only the analysis, but they also drive the design, they help you determine the classes, and they are especially important in testing the product.
7) What is a domain expert?
A) A domain expert is someone with expertise in the domain(area) of business for which you are creating the product.
8) What is an actor?
A) Any person or system that interacts with the system you are developing.
9) What are the 6 questions you should ask yourself about the actors when determining use cases, according to your book?
A) 1. Why is the actor using this system?
2. What outcome does the actor want or expect from each request?
3. What happened to cause the actor to use this sytem now?
4. What must the actor do to use the system?
5. What information must the actor provide to the system?
6. What information does the actor hope to get from the system?
10) What is a domain model?
A) A domain model is a document that captures all you know about the domain(the field of business you are working in).
11) What is a scenario?
A) A scenario is a description of a specific set of circumstances that distinguish amoung the various elements of the use case.
12) What are the nine items, according to your book, should you include when documenting a scenario?
A) 1. Preconditions - What must be true for the scenario to begin.
2. Triggers - What even causes the scenario to begin.
3. What actions the actors take.
4. What results or changes are caused by the system.
5. What feedback the actors receive.
6. Whether repeating activities occur, and what causes them to conclude.
7. A description of the logical flow of the scenario.
8. What causes the scenario to end.
9. Postconditions - What must be true when the scenario is complete.
13) What is system analysis?
A) System analysis is the process of collecting all the details for the systems with which you will interact.
14) What is the simplistic technique, according to your book, for determining the classes in your project?
A) The simplified technique is by writing out the use-case scenarios and then creating a class for every noun.
15) What are the three areas of concern for the Static Model of your classes?
A) 1. Responsibilities - each class should be responsible for one thing.
2. Attributes .
3. Relationships.
16) What is the most important principle when deciding the responsibilities of a class?
A) That each class must have one and only one responsibility.
17) What are the two types of diagrams shown in the book for determining how classes interact?
A) 1. Sequence diagram.
2. Collaboration diagram.
// Character.h file#include <iostream>class Character{public: Character(); Character(int strength, int dexterity, int stamina, int intellect, int wisdom, int charisma); ~Character(); int GetStrength() const; int GetDexterity() const; int GetStamina() const; int GetIntellect() const; int GetWisdom() const; int GetCharisma() const; int ValidInput(int value); // method will check whether value is within it's min- and maximum range. int RandomNumGen(); // will generate a number between the min- and maximum range. void PrintValues() const; private: int m_Strength; int m_Dexterity; int m_Stamina; int m_Intellect; int m_Wisdom; int m_Charisma; const static int m_MAX = 20; const static int m_MIN = 0;};
// Character.cpp-file.#include <cstdlib>#include "Character.h"Character::Character(){ m_Strength = RandomNumGen(); m_Dexterity = RandomNumGen(); m_Stamina = RandomNumGen(); m_Intellect = RandomNumGen(); m_Wisdom = RandomNumGen(); m_Charisma = RandomNumGen();}Character::Character(int strength, int dexterity, int stamina, int intellect, int wisdom, int charisma){ m_Strength = ValidInput(strength); m_Dexterity = ValidInput(dexterity); m_Stamina = ValidInput(stamina); m_Intellect = ValidInput(intellect); m_Wisdom = ValidInput(wisdom); m_Charisma = ValidInput(charisma);}Character::~Character() {}int Character::GetStrength() const{ return m_Strength;}int Character::GetDexterity() const{ return m_Dexterity;}int Character::GetStamina() const{ return m_Stamina;}int Character::GetIntellect() const{ return m_Intellect;}int Character::GetWisdom() const{ return m_Wisdom;}int Character::GetCharisma() const{ return m_Charisma;}int Character::ValidInput(int value){ if(value > m_MIN && value < m_MAX) return value; else return (0);}int Character::RandomNumGen(){ int randomNum = ( rand() % m_MAX ) + 1; return randomNum;}void Character::PrintValues() const{ std::cout << "Strength:\t " << m_Strength << " Points." << std::endl << "Dexterity:\t " << m_Dexterity << " Points." << std::endl << "Stamina:\t " << m_Stamina << " Points." << std::endl << "Intellect:\t " << m_Intellect << " Points." << std::endl << "Wisdom:\t\t " << m_Wisdom << " Points." << std::endl << "Charisma:\t " << m_Charisma << " Points." << std::endl;}
// Exampl()e(s) and exercise(s) from the book: Sams Teach Yourself// Authors: Jesse Liberty and Bradley Jones// Combination with the online tutorial classes from Jeromy Walsh on Gamedev.// Required headers#include <ctime>#include "Character.h"int main(){ // Call this ONCE, in your main function to seed the random number generator srand( (unsigned)time( NULL ) ); Character Tom(15, 13, 14, 13, 34, 5); Character Johan; std::cout << "The values for Tom are: \n"; Tom.PrintValues(); std::cout << "\n\nThe values for Johan are:\n" << "Strength:\t " << Johan.GetStrength() << " Points." << std::endl << "Dexterity:\t " << Johan.GetDexterity() << " Points." << std::endl << "Stamina:\t " << Johan.GetStamina() << " Points." << std::endl << "Intellect:\t " << Johan.GetIntellect() << " Points." << std::endl << "Wisdom:\t\t " << Johan.GetWisdom() << " Points." << std::endl << "Charisma:\t " << Johan.GetCharisma() << " Points." << std::endl; return 0;}