Exam Questions Introduction To Classes Chapter 13 9e - Test Bank | C++ Control Structures 9e by Tony Gaddis. DOCX document preview.

Exam Questions Introduction To Classes Chapter 13 9e

Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)

Chapter 13 Introduction to Classes

TRUE/FALSE

1. Whereas object-oriented programming centers on the object, procedural programming centers on functions.

2. Class objects can be defined prior to the class declaration.

3. The constructor function may not accept arguments.

4. A destructor function can have zero to many parameters.

5. More than one constructor function may be defined for a class.

6. More than one destructor function may be defined for a class.

7. You can use the technique known as a member intialization list to initialize members of a class.

8. In-place member initialization no longer is available in C++11.

9. In object-oriented programming, the object encapsulates both the data and the functions that operate on the data.

10. You must declare all data members of a class before you declare member functions.

11. You must use the private access specification for all data members of a class.

12. A private member function is useful for tasks that are internal to the class but it is not directly called by statements outside the class.

13. If you do not declare a destructor function, the compiler will furnish one automatically.

14. When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

15. Constructor functions are often used to allocate memory that will be needed by the object.

16. Destructor functions are often used to free memory that was allocated by the object.

17. While a class's member functions may be overloaded, the constructor cannot be overloaded.

18. When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.

MULTIPLE CHOICE

1. Objects are created from abstract data types that encapsulate __________ and __________ together.

a.

numbers, characters

b.

data, functions

c.

addresses, pointers

d.

integers, floating-point numbers

e.

None of these

2. In OOP terminology, an object's member variables are often called its __________ and its member functions can be referred to as its behaviors or its __________.

a.

values, morals

b.

data, activities

c.

attributes, activities

d.

attributes, methods

e.

None of these

3. A C++ class is similar to a(n)

a.

inline function

b.

header file

c.

library function

d.

structure

e.

None of these

4. Where are class declarations usually stored?

a.

on separate disk volumes

b.

in their own header files

c.

in .cpp files, along with function definitions

d.

under pseudonyms

e.

None of these

5. In a procedural program you typically have __________ stored in a collection of variables and a set of __________ that perform operations on the data.

a.

numbers, arguments

b.

parameters, arguments

c.

strings, operators

d.

data, functions

e.

None of these

6. A class is a(n) __________ that is defined by the programmer.

a.

data type

b.

function

c.

method

d.

attribute

e.

None of these

7. Examples of access specifiers are the key words

a.

near and far

b.

opened and closed

c.

private and public

d.

table and row

e.

None of these

8. Which of the following is used to protect important data?

a.

the public access specifier

b.

the private access specifier

c.

the protect member function

d.

the class protection operator, @

e.

None of these

9. Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once?

a.

#include

b.

#guard

c.

#ifndef

d.

#endif

e.

None of these

10. When the body of a member function is defined inside a class declaration, it is said to be

a.

static

b.

global

c.

inline

d.

conditional

e.

None of these

11. A __________ is a member function that is automatically called when a class object is __________.

a.

constructor, created

b.

destructor, created

c.

static function, deallocated

d.

utility function, declared

e.

None of these

12. The constructor function's return type is

a.

int

b.

float

c.

char

d.

structure pointer

e.

None of these

13. The destructor function's return type is

a.

int

b.

float

c.

char

d.

Nothing; destructors have no return type

e.

None of these

14. When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n)

a.

empty constructor

b.

default constructor

c.

stand-alone function

d.

arbitrator function

e.

None of these

15. When a constructor has a member initialization list, the initializations take place

a.

after any statements in the body of the constructor execute

b.

before any statements in the body of the constructor execute

c.

when a member is used in the execution of the program

d.

None of these

16. In C++11 you can use __________ to initialize a member variable in its declaration statement.

a.

general member initialization

b.

default initialization

c.

in-place initialization

d.

initialization overload

e.

None of these

17. The type of member function that may be called from a statement outside the class is

a.

public

b.

private

c.

undeclared

d.

global

e.

None of these

18. 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

19. Members of the class object are accessed with the

a.

dot operator

b.

cin object

c.

extraction operator

d.

stream insertion operator

e.

None of these

20. Assuming that Rectangle is a class name, what can you say is true, given the following statement?

Rectangle *BoxPtr;

a.

The statement declares an object of the class Rectangle.

b.

The statement assigns the value of *BoxPtr to the object Rectangle.

c.

The statement defines a Rectangle pointer variable named *BoxPtr.

d.

The statement is illegal in C++.

e.

None of these

21. When you dereference an object pointer, use the

a.

-> operator

b.

<> operator

c.

dot operator

d.

& operator

e.

None of these

22. Which type of member function may only be called from a function that is a member of the same class?

a.

public

b.

private

c.

global

d.

local

e.

None of these

23. The constructor function always has 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

24. Which of the following is automatically called when an object is destroyed?

a.

the constructor function

b.

the specification deallocator

c.

the destructor function

d.

the destruction function

e.

None of these

25. How many default constructors can a class have?

a.

only one

b.

two or more

c.

only two

d.

any number

e.

None of these

26. Objects in an array are accessed with __________.

a.

subscripts

b.

parentheses

c.

#include statements

d.

output format manipulators

e.

None of these

27. The process of object-oriented analysis can be viewed as the following steps:

a.

identify objects, then define each object's attributes, behaviors, and relationships

b.

define data members and member functions, then assign the class name

c.

declare public and private variables, prototype functions, and then write code

d.

write the main() function, then determine which classes are needed

e.

None of these

28. When a member function is defined outside of the class declaration, the function name must be qualified with the

a.

class name, followed by a semicolon

b.

name of the first object

c.

class name, followed by the scope resolution operator

d.

private access specifier

e.

None of these

29. If a local variable and a global variable have the same name within the same program, the __________ resolution operator must be used.

a.

variable

b.

ambiguity

c.

scope

d.

global

e.

None of these

30. For the following code, which statement is not true?

class Point

{

private:

double y;

double z;

public:

double x;

};

a.

x is available to code that is written outside the class.

b.

The name of the class is Point.

c.

x, y, and z are called members of the class.

d.

z is not available to code that is written outside the class.

e.

All of these are true.

31. The following code shows an example of __________

class Point

{

private:

double y = 5.70;

double z = 3.0;

public:

Public member functions go here...

};

a.

constructor delegation

b.

in-place initialization

c.

a default constructor creation

d.

an illegal initialization

32. In C++11 you can have one constructor call another constructor in the same class by using

a.

constructor delegation

b.

in-place initialization

c.

a member initialization list

d.

None of these

33. Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?

a.

Car -> accelerate();

b.

myCar::accelerate();

c.

myCar.accelerate();

d.

myCar:accelerate();

e.

None of these

34. What is the output of the following program?

#include <iostream>

using namespace std;

class TestClass

{

public:

TestClass(int x)

{ cout << x << endl; }

TestClass()

{ cout << "Hello!" << endl; }

};

int main()

{

TestClass test;

return 0;

}

a.

the program runs but there is no output.

b.

0

c.

Hello!

d.

the program will not compile

35. What is the output of the following program?

#include <iostream>

using namespace std;

class TestClass

{

public:

TestClass(int x)

{ cout << x << endl; }

TestClass()

{ cout << "Hello!" << endl; }

};

int main()

{

TestClass test(77);

return 0;

}

a.

the program runs but there is no output.

b.

77

c.

Hello!

d.

the program will not compile

36. What is the output of the following program?

#include <iostream>

using namespace std;

class TestClass

{

private:

int val;

void showVal()

{ cout << val << endl; }

public:

TestClass(int x)

{ val = x; }

};

int main()

{

TestClass test(77);

test.showVal();

return 0;

}

a.

the program runs but there is no output.

b.

77

c.

0

d.

the program will not compile

Document Information

Document Type:
DOCX
Chapter Number:
13
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 13 Introduction To Classes
Author:
Tony Gaddis

Connected Book

Test Bank | C++ Control Structures 9e

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party