Chapter 13 test 2

Ace your homework & exams now with Quizwiz!

17) Members of a class object are accessed with the ________.

dot operator

6) Class declarations are usually stored here.

in their own header files

24) Objects in an array are accessed with ________, just like any other data type in an array.

subscripts

21) The constructor function always has the same name as ________.

the class

7) This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.

#ifndef

19) When you dereference an object pointer, use the ________.

-> operator

31) 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; }

77

20) This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these

Answer: B

28) 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 available to code that is written outside the class.

Answer: D

10) The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these

Answer: E

2) True/False: Class objects can be defined prior to the class declaration.

FALSE

3) True/False: The constructor function may not accept arguments.

FALSE

4) True/False: A destructor function can have zero to many parameters.

FALSE

6) True/False: More than one destructor function may be defined for a class.

FALSE

8) True/False: You must declare all data members of a class before you declare member functions.

FALSE

9) True/False: You must use the private access specification for all data members of a class.

FALSE

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; }

Hello!

25) The process of object-oriented analysis can be viewed as the following steps:

Identify objects, then define objects' attributes, behaviors, and relationships

) True/False: A private member function is useful for tasks that are internal to the class, but is not directly called by statements outside the class.

TRUE

1) True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.

TRUE

11) True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

TRUE

12) True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

TRUE

13) True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.

TRUE

14) True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.

TRUE

15) True/False: 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.

TRUE

5) True/False: More than one constructor function may be defined for a class.

TRUE

7) True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.

TRUE

22) This is automatically called when an object is destroyed.

destructor function

32) 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; }

The program will not compile.

2) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________.

attributes, methods

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

class name, followed by the scope resolution operator

9) A ________ is a member function that is automatically called when a class object is ________.

constructor, created

16) A class is a(n) ________ that is defined by the programmer.

data type

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

data, functions

15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data.

data, functions

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

default constructor

18) Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr;

defines a Rectangle pointer variable called BoxPtr

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

inline

29) 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?

myCar.accelerate();

11) The destuctor function's return type is ________.

nothing, has no return type

23) A class may have this many default constructor(s).

only one

14) If you do not declare an access specification, the default for members of a class is ________.

private

5) This is used to protect important data.

private access specifier

4) Examples of access specifiers are the key words:

private and public

13) This type of member function may be called from a statement outside the class.

public

27) If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used.

scope

3) A C++ class is similar to one of these.

structure


Related study sets

Targeted Medical-Surgical: Endocrine

View Set

Lección 9 : Estructura: 9.1 (old)

View Set

Ch 29,30 Concept Check (Multiple Choice)

View Set

Chapter 13: Reformation & Religious Wars (16th century + first half of 17th c.)

View Set

FON CHAPTER 5 CULTURAL DIVERSITY

View Set