Professional Documents
Culture Documents
1) True/False: Object-oriented programming is centered around objects that include both data and the
functions that operate on them.
Answer: TRUE
4) True/False: A class declaration provides a pattern for creating objects, but doesn’t make any objects.
Answer: TRUE
5) An object typically hides its data, but allows outside code to access it through its
A) private member functions.
B) public member functions.
C) public data members.
D) access specifiers.
E) None of the above
Answer: B
6) In OOP terminology, an object's member variables are often called its ________, and its member
functions are sometimes referred to as its ________.
A) values, operators
B) data, activities
C) attributes, activities
D) attributes, methods
E) values, activities
Answer: D
7) When three different objects of a class are created, they are said to be separate ________ of the class.
A) members
B) ADTs
C) instances
D) children
E) None of the above
Answer: C
1
Copyright © 2017 Pearson Education, Inc.
8) When the body of a member function is defined inside a class declaration, it is called a(n) ________
function.
A) static
B) global
C) inline
D) conditional
E) constructor
Answer: C
9) True/False: A constructor is a public class function that is automatically invoked (i.e., called) whenever a
class object is created.
Answer: TRUE
12) A constructor that does not require that any arguments be passed to it is called a(n) ________
constructor.
A) empty
B) default
C) stand-alone
D) zero-element
E) useless
Answer: B
14) A(n) ________ member function may be called by a statement in a function that is outside of the class.
A) inline
B) public
C) private
D) declared
E) constructor
Answer: B
2
Copyright © 2017 Pearson Education, Inc.
15) A C++ member function that uses, but does not change, the value of a member variable is called
A) an accessor.
B) a mutator.
C) a user.
D) a constant.
E) a constructor.
Answer: A
16) Accessors are sometimes called ________ functions and mutators are sometimes called ________
functions.
A) set, get
B) get, set
C) public, private
D) private, public
E) regular, inline
Answer: B
17) If Circle is the name of a class, which of the following statements would create a Circle object
named myCircle?
A) myCircle Circle;
B) myCircle Circle();
C) Circle myCircle;
D) Circle myCircle();
E) None of the above
Answer: C
18) If setRadius is a Circle class function and myCircle is a Circle object, which of the following
statements would set myCircle's radius to 2.5?
A) setRadius(2.5);
B) myCircle.setRadius(2.5);
C) Circle.setRadius(2.5);
D) Circle(setRadius(2.5));
E) None of the above
Answer: B
19) True/False: A structure has member variables, like an object, but they are usually all public and
accessed directly with the dot operator, instead of by calling member functions.
Answer: TRUE
20) Which of the following statements correctly creates an enumerated data type and defines an object of
that type.
A) enum Season = {"Spring", "Summer", "Fall", "Winter"} favoriteSeason;
B) enum Season = {Spring, Summer, Fall, Winter}, Season favoriteSeason;
C) enum Season {Spring, Summer, Fall, Winter}, enum favoriteSeason;
D) ENUM Season {Spring, Summer, Fall, Winter} favoriteSeason;
E) None of these
Answer: E
3
Copyright © 2017 Pearson Education, Inc.
Chapter 7 Test 2 Key
1) True/False: An Abstract data type (ADT) is a programmer-defined data type that specifies the values the
type can hold, the operations that can be performed on them, and how the operations will be
implemented.
Answer: FALSE
2) True/False: In C++ and other object-oriented programming languages, ADTs are normally implemented
as classes.
Answer: TRUE
7) Public members of a class object can be accessed from outside the class by using the
A) dot operator.
B) get function.
C) extraction operator.
D) member access operator.
E) class name.
Answer: A
4
Copyright © 2017 Pearson Education, Inc.
8) A C++ member function that sets or changes the value stored in a member variable is called
A) an accessor.
B) a mutator.
C) a user.
D) a get function.
E) an updater.
Answer: B
9) True/False: A private member function may only be called from a function that is a member of the same
class.
Answer: TRUE
10) True/False: A constructor is a public class function that gets called whenever you want to re-initialize
an object's member data.
Answer: FALSE
13) A class may have ________ default constructor(s) and ________ destructor(s).
A) only one, only one
B) only one, more than one
C) more than one, only one
D) more than one, more than one
E) no, only one
Answer: A
14) 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) a tilde (~).
Answer: B
5
Copyright © 2017 Pearson Education, Inc.
Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank
15) If Square is the name of a class, which of the following statements would create a Square object
named box?
A) box Square();
B) box Square;
C) Square box();
D) Square box;
E) None of the above
Answer: D
16) If setSide is a Square class function and box is a Square object, which of the following statements
would set the length of box's side to 5?
A) setSide(5);
B) box.setSide(5);
C) Square.setSide(5);
D) Square.setSide = 5;
E) None of the above
Answer: B
17) True/False: A class can have a member variable that is an instance of another class. This is called object
nesting.
Answer: FALSE
18) A structure variable is similar to a class object in which of the following ways?
A) It has member data that is usually private and accessed through public member functions.
B) Its data can be initialized with a constructor.
C) It can be passed to a function or returned from a function.
D) All of the above.
E) B and C, but not A.
Answer: E
6
Copyright © 2017 Pearson Education, Inc.