Original Post
Quizzes and Extra Credit for Week 5.
Post your answers to the Quizzes from Week 5 here rather than in the chapter thread, so as not to spoil things for the others.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? 2. How do you make a new type in C++? 3. What is a class? 4. What is another name for variables within a class? What is another name for the member functions? 5. What are the requisite parts of a class declaration? Show an example. 6. What are the two things a class declaration tells your compiler? 7. When discussing naming conventions, what’s the most important point to remember? 8. What is an object? 9. How do you declare an object? Show an example. 10. What operator is used to access members and methods of a class for objects created on the stack. 11. What is the difference between public and private members/methods within a class? Which is the default? 12. In general, should methods or members be private? Why? 13. What is the primary way you initialize the member data of a class? 14. How can you identify a constructor for a class? 15. What is a default constructor? How is it called. 16. What does “declaring a method of a class const” mean? What is the syntax for such a declaration? 17. In the context of classes and objects, what is a client? 18. Where do class declarations go? Where do the member function definitions go? 19. When one class has a member variable which is an object of a different class they are said to form a ___ relationship? 20. What is the only difference between C++ classes and C++ structs? Chapter 11 Quiz 1. What’s the purpose of a model? 2. What is the basic philosophy of iterative design/development? 3. What’s the difference between waterfall vs. iterative development? 4. What are the 6 steps listed in your book for iterative development. 5. What happens if you lose sight of the vision of your product? 6. What is a use case? 7. What is a domain expert? 8. What is an actor? 9. What are the 6 questions you should ask yourself about the actors when determining use cases, according to your book? 10. What is a domain model? 11. What is a scenario? 12. What are the 9 items, according to your book, should you include when documenting a scenario? 13. What is systems analysis? 14. What is the simplistic technique, according to your book, for determining the classes in your project? 15. What are the three areas of concern for the Static Model of your classes? 16. What is the most important principle when deciding the responsibilities of a class? 17. What are the two types of diagrams shown in the book for determining how classes interact? 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.
// Required headers
#include <stdlib.h>
#include <time.h>
// Call this ONCE, in your main function to seed the random number generator
srand( (unsigned)time( NULL ) );
// Call this in your default constructor in order to generate a random number from 1 to 20.
int randomNum = ( rand() % 20 ) + 1;
[Edited by - jwalsh on July 13, 2006 9:01:14 PM]