I really did enjoy working on this week's project. I would love any feedback anyone might have regarding sloppiness on my part or any other comments in general:) Thank you again!
Chapter 6 Quiz
1. What was the ‘C’ capability which allowed you to combine related variables? Did this solve the problem of connecting data
with behaviors?
The C capability was called structures and no it did not.
2. How do you make a new type in C++?
You declare a class.
3. What is a class?
A composition of of related variables and functions.
4. What is another name for variables within a class? What is another name for the member functions?
Variables within a class are called members variables or data members. Functions within a class are called member functions
or methods.
5. What are the requisite parts of a class declaration? Show an example.
class Cat
{
int itsAge;
void meow();
};The word 'class', the class name and brackets (with an ending semi-colon) are all required parts of the class declaration.
6. What are the two things a class declaration tells your compiler?
It tells the compiler what the class exactly is, and how much memory it needs to allocate for each object it creates of that
class.
7. When discussing naming conventions, what’s the most important point to remember?
Choose a naming convention and be consistent with it.
8. What is an object?
AN individual instance of a class.
9. How do you declare an object? Show an example.
Cat cupcake;The above statement creates a cat object called cupcake.
10. What operator is used to access members and methods of a class for objects created on the stack.
The dot (.) operator.
11. What is the difference between public and private members/methods within a class? Which is the default?
Private members can only be accessed when processing is inside the actual object. Public members can be accessed from
anywhere in your program. Class members are private by default.
12. In general, should methods or members be private? Why?
Yes, because if anything has the ability to access your members or methods, it makes your program much more difficult to
debug. It also allows you to distinguis between how your data is stored and how it is used.
13. What is the primary way you initialize the member data of a class?
With a constructor.
14. How can you identify a constructor for a class?
By defining a member function of the same name of the class, IE
Cat::Cat (int itsAge)
{
itsAge=initialage;
}
15. What is a default constructor? How is it called.
If you don't specify your own constructor, the default constructor is automatically called. The default constructor has no
actual code in it, it simply initializes your object.
16. What does “declaring a method of a class const” mean? What is the syntax for such a declaration?
This means that the method being declared const will not manipulate member variables at all. An example would be:
void someFunction () const;17. In the context of classes and objects, what is a client?
Anyone or anything that actually interfaces with those objects.
18. Where do class declarations go? Where do the member function definitions go?
Class declarations should go into .hpp files and be included into your program using
#include. Member function
definitions. Member function definitions can go into any .cpp file that is also included in your program.
19. When one class has a member variable which is an object of a different class they are said to form a ___ relationship?
a has-a relationship.
20. What is the only difference between C++ classes and C++ structs?
Members in classes are private by default. In structs, they are public by default.
Chapter 11 Quiz
1. What’s the purpose of a model?
To create a meaningful abstraction of the real world.
2. What is the basic philosophy of iterative design/development?
You begin with an idea you want to build on, and as you investigate it, the idea evolves. You may end up going back to
previous stages of design/development based on what you find in later stages.
3. What’s the difference between waterfall vs. iterative development?
In waterfall development, you are incapable of going 'backward' to previous stages, in iterative development you can.
4. What are the 6 steps listed in your book for iterative development.
Conceptulaization, analysis, design, implementation, testing and rollout.
`
5. What happens if you lose sight of the vision of your product?
Chances are your product is doomed!
6. What is a use case?
A description of how the software will be used.
7. What is a domain expert?
An expert in the area of business in which you are designing the product.
8. What is an actor?
Any person or system that interacts with the product you are developing.
9. What are the 6 questions you should ask yourself about the actors when determining use cases, according to your book?
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 system 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 document that captures everything you know about the domain.
11. What is a scenario?
A specific set of circumsances within an individual use case.
12. What are the 9 items, according to your book, should you include when documenting a scenario?
1. Preconditions
2. Triggers
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 activites 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
13. What is systems analysis?
The process of collecting information from all the other systems you plan on interacting with in your product.
14. What is the simplistic technique, according to your book, for determining the classes in your project?
Pulling out all the nouns in your use case scenarios.
15. What are the three areas of concern for the Static Model of your classes?
Responsibilities, attributes and relationships.
16. What is the most important principle when deciding the responsibilities of a class?
Each class should be responsible for one thing.
17. What are the two types of diagrams shown in the book for determining how classes interact?
Sequence disgrams and collaboration diagrams.
Exercise 1 – The random character generator
In the game “Dungeons & Dragons” by WoTC, each player controls a character. The character has a number of attributes, specifically, they have Strength, Dexterity, Stamina, Intellect, Wisdom, and Charisma – each which can have a score in the range of 1 to 20. These “ability” scores are used to determine the success and/or failure of skills used, as well as how your character performs in combat. We’ll explore more of that later. For this week, I want you to write a program which contains a “Character” class. The character should have attributes representing the 6 ability scores, with accesses for each score. As well, the class should contain two constructors, 1 which takes as input 6 ability scores, and the second which is the default. The default constructor should randomly assign each ability score a value in the range of 1 to 20. To make it easier, I’ve posted the code below to help generate random numbers. Your main function should create two “characters”….one by using the default constructor, and one by passing in values between 1-20…might want to check in your constructor to make sure the input is valid (1-20). After both characters are created, use your accessors to print the attributes of each character to the screen with appropriate labels.
#include <iostream>#include <stdlib.h>#include <time.h>using namespace std;class character //defining the character class{ public: //public accessor and modifier functions int GetStrength() const; void SetStrength (int strength); int GetDexterity() const; void SetDexterity (int dexterity); int GetStamina() const; void SetStamina (int stamina); int GetIntellect() const; void SetIntellect (int intellect); int GetWisdom() const; void SetWisdom (int wisdom); int GetCharisma() const; void SetCharisma (int charisma); //construction and destructor declarations character (int strength, int dexterity, int stamina, int intellect, int wisdom, int charisma); character(); ~character(); private: //private data members int itsStrength; int itsDexterity; int itsStamina; int itsIntellect; int itsWisdom; int itsCharisma;};//constructor definitionscharacter::character(int strength, int dexterity, int stamina, int intellect, int wisdom, int charisma){ //check input values to make sure they are valid. If not, we will print an error message. if ((0 >= strength) || (strength > 20)) cout << "Error! Input value for strength was invalid!" << endl << endl; if ((0 >= dexterity) || (dexterity > 20)) cout << "Error! Input value for dexterity was invalid!" << endl << endl; if ((0 >= stamina) || (stamina > 20)) cout << "Error! Input value for stamina was invalid!" << endl << endl; if ((0 >= intellect) || (intellect > 20)) cout << "Error! Input value for intellect was invalid!" << endl << endl; if ((0 >= wisdom) || (wisdom > 20)) cout << "Error! Input value for wisdom was invalid!" << endl << endl; if ((0 >= charisma) || (charisma > 20)) cout << "Error! Input value for charisma was invalid!" << endl << endl; itsStrength = strength; itsDexterity = dexterity; itsStamina = stamina; itsIntellect = intellect; itsWisdom = wisdom; itsCharisma = charisma;}character::character() //default constructor that takes in no values and assigns random values to all six attributes{ int rdmStrength = ( rand() % 20 ) + 1; int rdmDexterity = ( rand() % 20 ) + 1; int rdmStamina = ( rand() % 20 ) + 1; int rdmIntellect = ( rand() % 20 ) + 1; int rdmWisdom = ( rand() % 20 ) + 1; int rdmCharisma = ( rand() % 20 ) + 1; itsStrength = rdmStrength; itsDexterity = rdmDexterity; itsStamina = rdmStamina; itsIntellect = rdmIntellect; itsWisdom = rdmWisdom; itsCharisma = rdmCharisma;}character::~character() //destructor, takes no action.{}//The following six member functions are the accessor functions for characterint character::GetStrength() const { return itsStrength;}int character::GetDexterity() const{ return itsDexterity;}int character::GetStamina() const{ return itsStamina;}int character::GetIntellect() const{ return itsIntellect;}int character::GetWisdom() const{ return itsWisdom;}int character::GetCharisma() const{ return itsCharisma;}//The following six member definitons define the modifier functions for character classesvoid character::SetStrength(int strength){ itsStrength = strength;}void character::SetDexterity(int dexterity){ itsDexterity = dexterity;}void character::SetStamina(int stamina){ itsStamina = stamina;}void character::SetIntellect(int intellect){ itsIntellect = intellect;}void character::SetWisdom(int wisdom){ itsWisdom = wisdom;}void character::SetCharisma(int charisma){ itsCharisma = charisma;}int main(){ srand( (unsigned)time( NULL ) ); int inputStrength, inputDexterity, inputStamina, inputIntellect, inputWisdom, inputCharisma; cout << "Creating Palejo..." << endl; character Palejo; cout << "Palejo has been created with random stats!" << endl; cout << "You will now enter Reshad's stats. Please enter values between 1 and 20." << endl; cout << "Enter Reshad's strength:" << endl; cin >> inputStrength; cout << "Enter Reshad's dexterity:" << endl; cin >> inputDexterity; cout << "Enter Reshad's stamina:" << endl; cin >> inputStamina; cout << "Enter Reshad's intellect:" << endl; cin >> inputIntellect; cout << "Enter Reshad's wisdom:" << endl; cin >> inputWisdom; cout << "Enter Reshad's charisma:" << endl; cin >> inputCharisma; cout << "Creating Reshad..." << endl << endl << endl; character Reshad (inputStrength, inputDexterity, inputStamina, inputIntellect, inputWisdom, inputCharisma); cout << "Here are Palejo's stats:" << endl; cout << "strength:" << Palejo.GetStrength() << endl; cout << "dexterity:" << Palejo.GetDexterity() << endl; cout << "stamina:" << Palejo.GetStamina() << endl; cout << "intellect:" << Palejo.GetIntellect() << endl; cout << "wisdom:" << Palejo.GetWisdom() << endl; cout << "charisma:" << Palejo.GetCharisma() << endl << endl << endl; cout << "Here are Reshad's stats:" << endl; cout << "strength:" << Reshad.GetStrength() << endl; cout << "dexterity:" << Reshad.GetDexterity() << endl; cout << "stamina:" << Reshad.GetStamina() << endl; cout << "intellect:" << Reshad.GetIntellect() << endl; cout << "wisdom:" << Reshad.GetWisdom() << endl; cout << "charisma:" << Reshad.GetCharisma() << endl << endl << endl; return 0;}
[Edited by - Palejo on July 16, 2006 1:50:36 PM]