You are on page 1of 8

Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank

Starting Out with C++ Early Objects 9th Edition


Gaddis Test Bank

To download the complete and accurate content document, go to:


https://testbankbell.com/download/starting-out-with-c-early-objects-9th-edition-gaddis-
test-bank/

Visit TestBankBell.com to get complete for all chapters


Starting Out with C++: Early Objects, 9th ed. (Gaddis, Walters & Muganda)
Chapter 7 Introduction to Classes and Objects

Chapter 7 Test 1 Key

1) True/False: Object-oriented programming is centered around objects that include both data and the
functions that operate on them.
Answer: TRUE

2) True/False: ADT stands for Algorithmic Data Type.


Answer: FALSE

3) Which of the following statements about ADTs are true.


A) They specify the values the data type can hold.
B) They specify the operations the data type can perform.
C) They hide the details of how the data type is implemented.
D) They do all of the above.
E) They do A and B, but not C.
Answer: D

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

10) True/False: A class must have exactly one constructor.


Answer: FALSE

11) A constructor may have a return type of


A) int
B) bool
C) void
D) any of the above.
E) none of the above.
Answer: E

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

13) A destructor is a member function that


A) is used to remove old unneeded objects.
B) causes the program to end.
C) is automatically called when an object is destroyed.
D) can only be called by the main function of a program.
E) None of the above.
Answer: C

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

3) An object is a(n) ________ of a class.


A) example
B) copy
C) instance
D) attribute
E) member
Answer: C

4) True/False: A class declaration creates an object.


Answer: FALSE

5) The bundling of an object's data and functions together is called


A) OOP.
B) encapsulation.
C) data hiding.
D) structuring.
E) private access.
Answer: B

6) The ________ is used to protect important data.


A) default constructor
B) class protection operator
C) protect() member function
D) public access specifier
E) private access specifier
Answer: E

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

11) A constructor must have the same name as the


A) first private data member.
B) first public data member.
C) class.
D) first object of the class.
E) function return type.
Answer: C

12) 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 the above.
Answer: B

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

19) When an object or structure variable is passed to a function as a constant reference


A) the function accesses the original object, rather than a copy of it.
B) the function cannot make any changes to the member variables.
C) it is more efficient than passing it by value.
D) all of the above are true.
E) A and B are true, but not C.
Answer: D

20) What will the following code segment display?


enum Season {Spring, Summer, Fall, Winter} favoriteSeason;
favoriteSeason = Summer;
cout << favoriteSeason;
A) 1
B) 2
C) Summer
D) "Summer"
E) None of these.
Answer: A

6
Copyright © 2017 Pearson Education, Inc.

Visit TestBankBell.com to get complete for all chapters

You might also like