          Answers to Review Questions and Exercises
                            From
        Object Oriented Programming From Square One,
                       By Ed Mitchell
                Que Corp., (C) Copyright 1993


Introduction
------------
This document contains answers to the chapter Review
Questions presented in Object Oriented Programming From
Square One.  An additional set of suggested program solutions
are presented on the companion disk.  The program solutions
provide examples of potential solutions to the Chapter
Exercises.  Not all Exercise programs are implemented.

Teachers
--------
The book and the separately sold source code diskette are (C)
Copyright 1993 by Ed Mitchell and/or Que Corporation.  This
text is copyright (C) 1993 by Ed Mitchell but I give you
permission to make any number of copies subject to the
restriction that you give credit to  Object-Oriented
Programming From Square One, by Ed Mitchell, (C) Copyright
1993 by Que Corporation.

Students and Teachers
---------------------
These answers and supplemental source code are provided to
help you in your efforts at learning C++.

Disclaimer
----------
This collection of answers are being given away by the author
or the publisher and are provided "as is".  The author does
not warranty that the answers are complete nor accurate;
these are intended solely to provide assistance in your
learning effort s.

Errata for First Printing Editions
----------------------------------
Publishers and authors go through a great deal of effort to
ensure the accuracy of the material that is published in a
book.  Despite this effort and the best of intentions, most
first printings contain a number of author, typographical,
editing and layout errors.  Object Oriented Programmng From
Square One is, unfortunately, not immune from these types of
errors.  The last section of this document identifies a few
minor problems that you may discover when reading the first
printing of the book.

----------------------------------------------------------
Answers to Review Questions

Chapter 1 Review Questions
1.  The IDE is the Integrated Development Environment.  To
compile, link and run your program, select the Run | Run
command.  To save your program to disk, use the File |Save or
File |Save as... commands.  To load an existing program from
disk, use F ile | Open....

2.  Within a dialog box, to move from one control to another,
press the Tab key (or press Shift-Tab to move in the reverse
direction).

3,  Press the space bar to select or deselect a radio button
or check box item.

4.  The basic editing keystrokes that you will use the mose
are the arrow keys, PgUp, PgDn, Ctrl-Home and Ctrl-End, plus
the Del key to delete the character where the cursor is
located, and the <-- or Backspace key to delete the character
that was ju st typed.

5.  .CPP

6.      x=x+1;  // This is a single line comment
        /* This is a multiline comment
        that ends on this line */

7.  Every program must contain a main() function.  This
functions serves as your program's entry point.  When DOS (or
the IDE) executes your program, program execution always
begins at the first line of the main() function.

8.  For integer variables, use the int type.  For floating
point variables, use the float type.

9.  The increment operator is ++ and it may appear before or
after the operand, as in ++x or x++.  The decrement operator
is -- and it may appear before or after the operand, as in -
x or x--.  In some situations the position of the operator-
as a p refix or as a postfix operator is important.  For
example, in the expression,
        x = ++y;
y is incremented and the result is assigned to x.
In the expression,
        x = y++;
the value of y is assigned to x, and then y is incremented.

10. Use cin for input as in,
        cin >> a >> b;
You use the >> extractor operator to obtain input from the
input stream.

11.  Use the cout for output as in,
        cout << "The total=" << total << endl << endl <<
endl;

12.  To display your program's output, select the Window |
User option.  This switches the display from the Turbo C++
IDE to your program's output.

13.  Symbolic constants make it easy to the change the value
of a constant without the need to search through your source
code to locate each occurence of the constant.  Symbolic
constants can also be descriptive, which a numeric constant
is not (exc ept for some well known values such as 3.14159...
or 2.718...).

14. Use + for addition, - for subtraction, * for
multiplication and / for division.

15.  To test for exactly equal, use the equality operator ==.
Use < for less than, <= for less than or equal to, > for
greater than, >= for greater than or equal to, and != for not
equal.

16.  The >> operator is the extraction operator and is used
with the cin stream for obtaining input.

17.  The << operator is the insertion operator and is used
with the cout stream for producing output.

18. for (initial_value; ending_value; increment)
For example,
        for (i = 1; i<100; i = i + 2 )

19.  if (expression) statement;

20.     1.   By placing common code into one or more
functions, you can reuse the code several times, without
duplicating the reused section.
        2.  By practicing a divide-and-conquer approach, you
        divide a large problem into smaller, more maneagable
        pieces.
        3.  You can test individual pieces of your program
        more easily when the program is split into several
        subfunctions.  You can get the pieces working before
        integrating them into the entire program.
        4.  Once functions have been written and tested, you
        can use them again in other programs, saving yourself
        much time.

21.  The semicolon is used to terminate each C++ statement.



----------------------------------------------------------
Chapter 2 Review Questions
1.  The identifier 11-Holes is invalid because it begins with
a numeric character.  #potatoes does not begin with an
alphabetic character or an underscore.

2.  In some editions of the book, a layout error incorrectly
lists the possible answer choices.  The possible choices are
unsigned int, long, unsigned long, float and double.  Both
long and unsigned long are the best choices for the range of
values o f 0 to 100,000.  unsigned int cannot represent a
number as large as 100,000.  While float and double will
work, they are not as efficient as the long data type.
Computations involving floating point values always take
longer than arithmetic using th e simpler int and long types.
If you have no need for fractional values or exponential
notation, then you will be wise to choose the int or long
type as appropriate for the range of data values that your
program must represent.

3.The char or signed char type represents values from -128 to
+127 and occupies just one byte of memory.

4.  If figure there are 880,000 markers (computed as 5280
feet per mile divided a marker every six feet, multiplied by
1,000 miles).  This range of values may be represented by the
long or unsigned long types.

5.  The variables named,
        Number_of_households_in_Los_Angeles_with_kids
is treated identically to,
        Number_of_households_in_Los_Angeles_without_kids
because only the first 32 characters of an identifier are
stored by the Turbo C++ compiler.

6.  -885

7.  Escape sequences are a special sequence of characters
that are translated into other characters.  Escape sequences
are used to enter characters such as the newline character,
that cannot be entered directly your program source.  For
example, '\n' is used to represent the carriage return
 character.

8.  A char, by default, stores values in the range of -128 to
+127, which is suitable for storing standard ASCII characters
having values from 0 to +127.  To store the entire IBM
character set, which includes extended characters having
values from 12 8 to 255, you need to use the unsigned char
type.

9. The worst case order may contain 100 different part types
with up to 5,000 parts of each type.  5,000 multiplied by 100
is 500,000 units.  For this type you must use the long data
type.

10.  A local variable is one that exists and is used solely
inside a function. Storage for the local variable is normally
created (except for the static variable case) upon entry to a
function and disappears upon exit from the function.  You can
even reuse a local variable name within some other function.
 A global variable is declared outside a function and is
thereby made available to any of the functions.

11.  You can define a symbolic constant by using #define, the
const keyword or the enum declaration.

12.  Symbolic constants make it easy to the change the value
of a constant without the need to search through your source
code to locate each occurence of the constant.  Symbolic
constants can also be descriptive, which a numeric constant
is not (exc ept for some well known values such as 3.14159...
or 2.718...).

13.  height is set equal to 10 because the value of
building_size is incremented using the postfix increment
operator.  This means that the value of building_size is used
in the expression (or assignment) prior to executing the
increment operator.

14.  You should use the logical or && operator.  Do not
confuse && with the binary and operator that uses a single &
symbol!  This is a simple and common coding error.

15. ch = (char) f;

16.  enum ( january, february, march, april, may, june, july,
august, september, october, november, december );



----------------------------------------------------------
Chapter 3 Review Questions
1.   An aggregate is a collection of items.  Each of the data
types arrays, structures and unions is a collection of many
data elements, hence the name "aggregate data types".

2.  The indices 0, 15 and 25 are valid but [30] is not.
Remember that the array declaration defines the number of
elements of the array.  Since each array begins from 0, an
array declared to have 30 elements, extends from 0 to 29
elements.  Therefor e, the array element [30] is not part of
the array declared as int values[30].

3.  The array element numbers[2] refers to the third element
of the array.  If this is confusing, write down each of the
array elements like this:
        numbers[0]      numbers[1]      numbers[2] numbers[3]
...
From this you can see that numbers[2] is the third element of
the array.

4.
char alphabet1[26]={"abcdefghijklmnopqrstuvwxyz"};
char alphabet2[26]={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                    'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
                    'y', 'z'};

5.  The null character is a character whose value is an ASCII
zero, represented using the escape sequence '\0'.  You are
not required to use a null--byte for character arrays;
however, any string that is to be processed as a null-
terminated string mu st contain a terminating null byte.

6.  You can simulate the strlen() function in C++ by using a
loop to scan across the character string until finding the
terminating null character.

7.  To place double quote marks within a string you should
use the '\"' escape sequence, as shown in this code example:
        char s[70] = {"This is a \"quoted string\"."};

8.   You should use cin.getline() to read entire lines of
text from the keyboard.  This is the only reliable way to
read multiword text from the keyboard.  Further, getline()
automatically discards the trailing Enter keystroke.

9.
char Days_of_Week[7][10]= {"Monday", "Tuesday", "Wednesday",
                           "Thursday", "Friday", "Saturday",
                           "Sunday"};
for(int i=0; i<7; i++) cout << Days_of_Week[i] << endl;

10.
struct TInfo {
  char Name[30];
  char TelNum[14]
  int Age;
  int Height;
  int Weight;
};

TInfo me, you;

11. 100 * sizeof(TInfo) bytes.  This computes to 5,000 bytes
of memory.

12.
struct TInfo {
  char Name[30];
  char TelNum[14]
  int Age;
  int Height;
  int Weight;
};

TInfo me, you;

cout << sizeof(TInfo) * 100 << endl;

13.  Structure members are accessed and assigned values like
any other variables.  You must use the member-of (.) operator
to reference the individual members of the structure.

14.  You must use cin.ignore() to skip over the trailing
enter key that is entered to terminate the keystroke.

15.
struct  abitfield {
  unsigned int f1 : 2;
  unsigned int f2 : 2;
  unsigned int f3 : 2;
  unsigned int f4 : 2;
  unsigned int f5 : 2;
  unsigned int f6 : 2;
  unsigned int f7 : 2;
  unsigned int f8 : 2;
};

16.  The members of a structure are independent of one
another.  Each is given its own memory allocation.  In a
union, the members overlap each other.

17.  An object encapsulates both program instructions and
data into a single entity.

18.  You need to use the :: scope resolution operator to link
the function's declaration inside a structure to the
function's implementation when the implementation is located
outside the structure.


----------------------------------------------------------
Chapter 4 Review Questions
1.  To select between just two items, use the if() statement.

2.  When you need to execute a group of statements, place the
group of statements within matching { left brackets and right
brackets }.

3.  No, you do not need to use a relational operator in a
conditional statement.  C++ treats all non-zero values as a
true condition and 0 as a false condition.  Consequently, you
can place an expression that evaluates to an integer value as
your con ditional test.

4.  Zero.

5.  All non-zero values.

6.  Yes because any statement may follow the conditional test
and if() is itself a valid statement.  For example,
if (condition)
  if (condition) statement;

7.  When you need to test among several possibilities, the
switch statement is usually your best bet.  The switch
statement can make the decision faster and more efficiently
than a long list of if-else statements.

8.  A break; statement should normally be placed after the
code for each case in a switch statement.

9.    Use a for loop.  The for loop is ideal for repeated a
section of code a specific number of times.

10.  Since you want the loop to execute at least once to
prompt for an initial value, you might wish to use the do-
while() loop because this places the conditional test at the
end.

11.  Reduce the amount of code that must execute within a
loop.  Move subexpressions that are not changed during the
loop execution to outside the loop; assign the value of the
subexpression to a temporary variable.  Also look for
duplicated expressi on code - any expression that is
calculated more than once should be stored in a temporary
variable.

12.  The goto statement is beneficial for error processing.
When an error is detected, you can use the goto to
immediately jump to the end of a function where you have
located common error handling code.  You do not need to use
the goto very often i n C++ programming because of the
versatile if(), if()-else, if()-elseif, while, and for loops.



----------------------------------------------------------
Chapter 5 Review Questions
1.  Use the & address-of operator.

2.  (b) is the most efficient.  Because p1 and p2 point
directly to the source and destination characters, you
eliminate the array indexing operation used in (a).  Array
indexing requires that the index be multiplied by the size of
the array element, and then added to the base address of the
 array.  The indexing calculations are more time consuming
than direct access to the array elements via pointers.

3. pS->mpg is the preferred format but you can also use
*(pS).mpg.

4.  When two pointers point to the same dynamic memory
allocation, it is an easy mistake to free up the memory
allocation but continue to use the other pointer, even though
the memory that it points at is no longer valid.

5.  A self-referential data structure is one that has one or
more pointers that point to other instances of the same kind
of structure.

6.  A recursive function is a function that calls itself.
Such functions must be written carefully to ensure that they
do not call themselves forever!

7.   near, far and huge pointers.

8.  All of the methods shown work to access elements of the
array.



----------------------------------------------------------
Chapter 6 Review Questions
1.  You use the #include compiler directive to read
information about the library functions.

2.  Here is a function with no return result:
        void A_function(int parameter_1)

3.
struct TPerson {
  char name[30];
  int age;
};

// The following function returns a structure type
TPerson get_name(void);
// You may optionally include the struct keyword before the
structure typename, like this:
// struct TPerson get_name(void);

4.  void print_to_screen(void) { ... }

5.  This function should use pass-by-reference.  If the
integer parameter is passed to the function as pass-by-value,
and assignment of zero to the parameter variable will not be
seen by the caller.

6.  In C++ you can use the & reference symbol to declare a
parameter as pass-by-reference, like this:
        void f(int &x)
You may also pass the address to a function that expects to
see a pointer type.  For example,
        void f(int *x) {
          *x = 0;
           ...
        }
To call this function, you must pass the address of the
argument variable.  For example,
        int sum;
        f( &sum );
Note that while both methods use the & symbol, the & operator
performs slightly differently in each situation.  The
compiler determines what & actually means by observing the
context in which the symbol is used.

7.  You do not need to use the & address-of operator when
passing an array to a function.  The compiler automatically
passes the address of an array to a function.  However, you
may wish to pass the address of an individual element of the
array.  To pass an array element's address you must use the &
address-of operator, like this:
        f( &an_array[9]);

8.  Place the const keyword before each of the pass-by-
reference parameters.

9.  When a function header contains default values for its
parameters, you can omit values for those parameters when
calling the function.

10.  Whether you use a function or a macro depends upon your
goals.  Because the expression x*x + 2*x + x  involves
several arithmetic operations, the use of this expression in
many places could cause the compiler to generate a lot of
code.  To reduc e the total size of the generated code, a
function might be your best solution.  On the other hand,
there is a certain overhead associated with making a function
call.  Hence, the use of function calls will be somewhat
slower but reduce memory versus use this expression directly
 in your program.
        If you choose instead to use a macro substitution,
you will achieve the fastest execution (because the overhead
of calling a function is eliminated) but the code size will
be somewhat larger.

11.   Variables defined inside a function exist only during
the execution of the function.  Hence, duration applies to
the time frame during the which the local variable is valid.
By default, variables defined inside functions have local
scope and a utomatic duration (meaning their memory space is
created automatically upon entry to the function and disposed
of upon exit).  By placing the keyword 'static' in front of
the variable definition, the variable's memory allocation is
made permanent for the duration of the program.

12.  A function prototype is just the function header,
providing a definition of the function and its parameters
without defining the body of the function.

13.   See the section titled "Why Use Function Prototypes?"

14.  Function overloading lets you use the same function name
for multiple function definitions, provided that at least one
parameter in each definition is of a different type than any
of the other functions.

15.  By examing the types of the parameters.

16.   Function templates create a "cookie cutter" for quickly
creating a large number of similar functions.

17.  A macro is not a true function at all.  A macro causes a
text substitution to occur.  The resulting text is inserted
into your program at the point of the macro's reference - so
no function call ever occurs.



----------------------------------------------------------
Chapter 7 Review Questions
1.  It is quicker to load and save small source files.  It is
quicker to compile small files and then link the previously
compiled, unchanged object files into your program.  By
grouping related functions together you improve modularity
and reusabili ty of your code.

2.  A good approach is to group related functions together
into one or more source files and to create a header file
describing the routines that are exported from these files.
You may also choose to split your program according to
functional areas- or by claases (described in Chapter 8).

3.  A header file contains function prototypes, type
definitions and other symbol definitions.  The header file
describes the content of the source module - and provides the
minimum information needed by the compiler to call and link
to functions def ined in the module.  The header file does
not contain code - just definitions.

4.  To eliminate duplicate symbol definitions in header files
you should use the #define compiler directive to declare a
unique symbol.  The same header file should test for the
existence of this symbol using the #if conditional directive
- if the sy mbol already exists then this header file has
been previously included in the current compilation
(typically by the inclusion of another header file that in
turn includes the current header file).  See the section
titled "Using Conditional Compilatio n to Avoid Duplicate
Symbols."

5.  The only difference between #include "file" and #include
<file> is the directory search order that the compiler checs
to locate the desired file.  When the compiler sees angle
brackets, it looks for a standard header file by checking the
list of directories specified in the Include field of
Directories dialog box (see Options | Directories ).  When
the compiler sees quotation marks around the file name, it
first checks the current directory.  If the inculde file is
not located in the current directory, the directory search
 proceeds as if angles brackets were used around the
filename.

6.  Use the Project } Open menu option and enter the name of
your new project.

7.  To add files to the project, select Project | Add Item
and enter the names of the files to be added to the project.

8.  The key to efficient project development is to use the
Compile | Make command.  The Make command compiles only those
files that have changed since early compilations.  By using
Make you can greatly reduce the amount of time spent
compiling since only the mininum number of files are
recompiled.

9.  Scope refers to over what part of your program a variable
or function or symbol is visible.  For example, local
variables are visible only within a function and are said to
have "function scope".    A variable defined outside a
function is visibl e to all functions within the file and is
said to have "file scope".  Variables defined in a function
prototype are local to the function and have function scope.

10.  See answer #9.

11.  To eliminate external linkage, you should define file
scope variables by using the static keyword, like this:
        static int Compute_Total(int n) { ... }

12.  The extern keyword is applied before a variable or
function prototype to tell the compiler that the declaration
for this symbol exists in another module.

13.  Tiny, Small, Compact, Medium, Large and Huge.  See Table
7.2 "Memory models supported in Turbo C++."

14.  Your choice of memory models affects the speed of your
program, the amount of code your program can contain and the
amount of data space to which your program has access.  While
you can write small programs using any of the memory models,
progra ms should select an appropriate memory model based
upon the programs code and data space requirements.



----------------------------------------------------------
Chapter 8 Review Questions
1.  Combining functions and data into a single object helps
you to keep track of which functions operate upon which
pieces of data because the functions that manipulate the data
are now bound together into a single object.  By
encapsulating data and functions, you improve the functions'
information hiding capabilities.  By keeping internal
information hidden, you help to eliminate the temptation to
make inappropriate changes to an object's internal
information.  Objects also make possible the po wer of
inheritance.  Through inheritance, you create new objects by
telling the compiler you want a new object to be like some
existing object but with a few twists or modifications.

2.  In a struct structure, all structure members are public.
In a class, all class members are private unless your
specifically mark them as public using the public: keyword.
Classes also support "virtual functions" (which you learn
about in a foll owing table); the use of virtual functions
requires the use of constructor functions which you read
about in this chapter in the section titled "Constructor
Functions".

3.  Member functions.

4.  By default, all members of a class are private.  You
create a public definition section by inserting the keyword
"public:" into the member definitions list.  Once you
reference the public: keyword, all subsequent members are
also declared as publ ic.  Use the keyword private: to mark
definitions as private to the class.  You can use public and
private more than once, if you need to have several public or
private sections in a class.

5.  Inlines functions are not "called" in the traditionial
sense of calling a function.  Instead of inserting a
subroutine call in the generated code, the compiler inserts
the code of the function directly into the statement that
calls the function.  If you call the function more than once,
 then the code is replicated each time that the function is
used.  You will normally reserve the use of inline functions
to code sections that are very short and which do not need to
be called many times.

6.  You use constructor functions to initialize class data
members.  If your class contains virtual functions (see
Chapter 10), then the constructor sets up internal tables
needed to call virtual functions.

7.  A class may have multiple constructor functions by taking
advantage of C++'s overloaded function definitions.  As long
as each constructor for a given class has a differing set of
parameter values, then the compiler can distinguish each of
the fu nctions from one another.

8.  Destructor functions are not permitted to have
parameters.  Therefore, without parameters, it is not
possible to overload a destructor function because the
compiler has not way to distinguish multiple destructor
functions.

9. Use delete[] p_object_name to delete discard a array
pointed to by the pointer p_object_name.

10.  You use the static keyword on class member data when the
class data should be shared across multiple instances of the
class.  A static member exists only once and is shared by
each instance of the class.

11.  *this points to the current object instance.  When you
call a member function, the called function might wish to
reference the data of the instance that called it.  See "The
*this Pointer" section.

12.  A friend function exists outside the definition of a
class but is given access to the private data of a class that
declares the function as a friend (of the class).  You define
a friend function using the friend keyword. The friend
function must have as one of its parameters, an instance of
 the class to which it is a friend.  This parameter is used
by the friend function to gain access to the private member
data of the class to which it is a friend.

13.  Overload operator functions enable you to provide
additional definitions for the *, +, /, - and other operators
in the C++ language.  You may not have given it much thought,
but your normal use of the * (multiplication) operator makes
use of ove rloading.  Multiplication works on several types
of data, such as int, char, float and so forth.  When you
write an expression using the * operator, C++ determines
which type of multiplication to perform.  In effect, there
are overloaded definitions for *.  For example, suppose you
have a class named TDataType containing a member value x.
You can implement multiplication (assuming that * is already
implemented for the type of x) by  writing something like
this:
        TDataType operator * (TDataType SomeValue)
        {
           TDataType TempValue;
          TempValue.x = this->x * SomeValue.x;
          return TempValue;
        }



----------------------------------------------------------
Chapter 9 Review Questions
1.  The power of OOP lies in inheritance and the ability to
derive a new class from the declarations of an existing base
class.  Through derivation, your application can use and
enhance existing code.  By using existing code you speed your
programmin g and improve program quality by reusing pre-
tested routines.

2.  You will remember that a class has both public and
private members.  When you derive a new class from an
existing class, the compiler enforces the public and private
attributes of the ancestors class.  Sometimes when you create
a class, you will want the derived classes to have access to
the ancestor's private data.  The solution is to use the
protected keyword.  Members marked as protected are availble
to derived classes yet remain private to all other users of
the class.

3.  When public, private or protected appear on the first
line of a class definition, they are known as access
specifiers.  The access specifier tells future derived
classes which parts of the ancestor class they can access.
What this means is that when you derive class B from class A,
the inherited members of class A become private to B unless
you use the public (or protected) keyword.  See "Derived
Classes and Access Specifiers" in this chapter for more
information.

4.  You can derive a class from more than one class at the
same time.  When you do this the derived class inherits
member data and member functions from all the classes from
which it is derived.

5.  When a class is derived from another class, you can
choose to inherit all of member functions, you can add new
functions, or you can provide new definitions of the existing
inherited functions.  When you provide a new definition for
an existing f unction, you are overriding the existing
functionality.



----------------------------------------------------------
Chapter 10 Review Questions
1.   Static linkage can cause problems when a derived class
overrides one of the parent's members - and the parent's
member functions mistakenly call the parent function and not
the overridden version in the child.

2.  A virtual function is one that becomes linked during
program execution, rather than when the program is compiled
and linked prior to execution.  Virtual functions eliminate
the problem caused by static linkage (as described in the
answer for #1 a bove).

3.  This one is left as an exercise for you!

4.  A pure function is unimplemented member function in an
ancestor class.  The pure function serves as a place holder
for the derived classes.  A class containing a pure function
is known as an abstract function; you cannot directly use an
abstract class - such classes exist solely for you to derive
new classes.  You mark a function as pure by appending =0; to
the function prototype.

5.  An abstract class is a class that contains one or more
pure functions.  You may not use an abstract class - you must
derive new classes from the abstract class and provide
definitions for the pure functions defined in the abstract
class.

6.  The virtual table provides the mechanism by which dynamic
linking is performed.  Each class has a virtual table.
Virtual functions are linked by placing the address of the
correct function in the virtual function table.

7.  A static function is linked before program execution; a
virtual function is dynamically linked function is linked
during program execution.  Any class that contains one or
more virtual functions contains a virtual table (if the class
contains onl y static functions then a virtual table is not
needed). Calling a virtual function takes slightly longer
than calling a static member function.  An ancestor class
cannot call a descendant class's overridden statically linked
member function.

8.  Polymorphism allows related classes to have a member
function having the same name but which produces different
results depending upon the class definition.  As long as each
descendant class implements the appropriate function, the
ancestor class is able to call the descendant's virtual
 member function.  Through this mechanism, the ancestor can
call descendant class types that are not invented until much
after the original class definition is produced.  For further
details, reread the sectio n titled "Polymorphism".



----------------------------------------------------------
Chapter 11 Review Questions
1.  The term stream is used to convey the idea of a flow of
data from one point to another.

2.  cout

3.  cin

4.  Use the constream class to declare your own stream
identifier.  Then use the setxy( x_coordinate, y_coordinate)
stream manipulator to position text to desired location on
the screen.

5.  To select floating-point output to display in scientific
notation, use the setiosflag() stream manipulator with the
parameter ios::scientific.  See the example on page 427.

6.  To reset or clear a stream error condition, call the
stream's clear() member function; no parameters are needed.
For example,
        cin.clear();

7.  ends

8.  Call seekp(0) to reset the internal position pointer back
to the first character in the buffer.

9.  The basic file stream class is the fstream class.

10.  Use istrstream to extract data from a text buffer into
individual variables.

11.  You should always call the close() member function when
you have finished processing a file.  This is especially
important if your program has written data to the file.
Because the computer may store some of the output in an
internal buffer bef ore writing the data to disk, you must
call close to ensure that the last buffer has been written
out.  Failure to call close() can result in a loss of data.

12.  You can use the eof() member function to test for an end
of file condition on the input file.

13. You check for a possible stream error condition by using
the stream identifier in a conditional statement.  For
example, if (!input_file) ... handle error condition.

14.  outfile.write( (char *) &Volts, sizeof( Volts ));



----------------------------------------------------------
Chapter 12 Review Questions
1. #include <graphics.h>

2. initgraph() function

3.  The graphics driver acts as the interface between the
graphics program and the computer hardware.  An appropriate
graphics driver must be selected to match the computer
hardware on which the graphics program is running.

4.  closegraph()

5.  outtext() and outtextxy()

6.  settextjustify() and settextstyl()

7.  A viewport is a region within the display screen to which
all graphics drawing commands will be mapped.  You can use a
viewport to restrict your drawing to appear only within a
certain part of the screen.

8.  You can use the viewport to establish a clipping region.
By setting the clip parameter of setviewport(), to CLIP_ON,
any portion of a graphics element that falls outside the
viewport boundary is clipped at the boundary line.

9.  The setcolor() function selects the color for all
subsequent drawing commands.

10.  Charting is concerned with displaying line, bar, pie and
other types of statistical graphs. A single bar or pie slice
is a graphics element.  Pretty pictures drawn on the screen
are graphics.  Text charts are another graph type -displaying
text ual information in bullet lists and other forms for use
during presentations.

11.  See figure 12.1.


----------------------------------------------------------
Chapter 13 Review Questions
1.  Not applicable.

2.  hashValue() converts each key to a numeric
representation.  The key can be based on one or more values
in the object being stored.  Ideally, each hash value is
independent of the others that are generated by the
hashValue() function.

3.  You should put in the isEqual() function the class
members that you wish to have compared for equality.  You can
compare one or more members depending upon the requirements
of your application.

4. The Display() function used in the example programs
produces output to the screen.  If you use the sample
programs as the basis for your own applications, you need to
modify Display() so that it outputs the data members that you
wish to have writt en to the display.

5.  A container can being given ownership of the objects that
are placed into the container.  In this, the default setting
for containers, a container is just like a shopping bag full
of items.  If you throw away the shopping bag, you also throw
away the contents of the shopping bag. However, you can
 optionally tell the container that it does not have
ownership over the objects that it contains.  In the latter
case, you can empty the container but the objects within
still remain allocated in mem ory - they are not disposed of
automatically.

6.  You could use either the SortedArray or Dictionary
container types.



----------------------------------------------------------
Errata Section

Chapter 1
Listing 1.2 (METRIC1.CPP) and the subsequent programs,
METRIC2.CPP and METRIC3.CPP contain an embarrassing error.
Rather than convert mile to kilometers, these programs
perform the opposite calculation:  kilometers to miles!  The
problem is easily fixed by changing the division operations
to multiplications.  New copies of METRIC1, METRIC2 and
METRIC3 are contained in the Exercise source code on this
disk.

Chapter 2
Table 2.9 is layed out incorrectly.  At bit position 7, the
decimal equivalent is shown as 256.  The correct value is
128.  All subsequent entries in the table are off by one line
so that Bit position 8 should show 256, Bit position 9 should
show 512 and so forth.

On page 85, beneath the heading "The Comma Operator", the
following code fragment is shown:
int i,j, result;
int i;
result = j = 10, i=j; i++;

The second line containing 'int i;' should be deleted.

Chapter 4
On page 152, at the bottom of the page, the following
statement is shown:
for (i=1; i<100; i*2)
  cout << i << " ";
The statement should actually read:
for (i=1; i<100; i*=2)
  cout << i << " ";

Chapter 5
On page 185, in the middle of the page, the example
declaration,
      int *fp
should actually be,
      float *fp


