COSC 1320 C++ PROGRAMMING
Homework 5
Part I
True/False
1. Whereas object-oriented programming centers around objects, procedural
programming centers around functions.
a. True b. False
2. More than one destructor may be defined for a class.
a. True b. False
3. A destructor can have only zero or one parameters.
a. True b. False
4. Object-oriented programming is centered around the object, whichpackages
together both the data and the functions that operate on the data.
a. True b. False
5. A primary purpose of a constructor is to initialize membervariables and
perform other setup operations.
a. True b. False
6. A primary purpose of a destructor is to perform shutdownprocedures when the
object goes out of existence.
a. True b. False
7. You must declare all data members of a class before you declare member
functions.
a. True b. False
8. When an object is defined without an argument list for its constructor, the
compiler automatically calls the object's default constructor, if there is
one.
a. True b. False
Part II
Multiple Choice
9. Objects are created from abstract data types that encapsulate data and
______together.
a.constants
b.functions
c.memory addresses
d.variables
e.None of these
10. In OOP terminology, an object's member variables are often called its
______, and its member functions are sometimes referred to as its
behaviors, or ______.
a.values, morals
b.data, activities
c.attributes, activities
d.attributes, methods
e.None of these
11. The ______is used to protect important data.
a.public access specifier
b.private access specifier
c.protect() member function
d.class protection operator, @
e.None of these
12. A constructor
a. must be public
b. must be private
c. can be either public or private
d. must be defined in an inline function
e. cannot be defined in an inline function
13. Class declarations are usually stored
a.on diskettes
b.in their own header files
c.in .cpp files, along with function definitions
d.under pseudonyms
e.None of these
14. When the body of a member function is defined inside a class declaration, it
is called a(an) ______function.
a.static b.global
c.inline d.conditional
e.None of these
15. A ______is a member function that is automatically called when a class
object is ______.
a.destructor, created
b.constructor, created
c.naming function, renamed
d.utility function, declared
e.None of these
16. A constructor’s return type is
a. int b. bool
c. void d. structure
e. None of these
17. When a constructor does not have to accept parameters, it is called a(n)
a.empty constructor
b.default constructor
c.stand-alone function
d.destructor
e.None of these
18. A(n)______member function may be called from a statement outside the class.
a.public b.private
c.undeclared d.unspecified
e.None of these
19. If you do not declare an access specification, the default for members of a
class is:
a.inline b.private
c.public d.global
e.None of these
20. Members of a class object are accessed with the
a.dot operator
b.cin object
c.extraction operator
d.stream insertion operator
e.None of these
21. A constructor must have the same name as
a.the first private data member
b.the first public data member
c.the class
d.the first object of the class
e.None of these
22. The name of a destructor must begin with
a. the name of the class
b. a tilde (~)
c. a capital letter
d. an underscore
e. None of these
23. The ______directive prevents a header file from being included more than
once.
a.#include b.#define
c.#ifndef d.#endif
e.None of these
24. A class may have ______default constructor(s).
a.only one b.more than one
c.a maximum of two d.any number of
e.None of these
25. When a member function is defined outside of the class declaration, the
function name must be qualified with the class name, followed by
a.a semicolon
b.the scope resolution operator
c.the public access specifier
d.the private access specifier
e.None of these