Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 17 – C How to Program 6e Multiple Choice Test Bank


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


Chapter 17: Classes: A Deeper Look, Part 1

Section 17.2 Time Class Case Study

17.2 Q1: Member access specifiers (public and private) can appear:
a. In any order and multiple times.
b. In any order (public first or private first) but not multiple times.
c. In any order and multiple times, if they have brackets separating each type.
d. Outside a class definition.

17.2 Q2: Which of the following preprocessor directives does not constitute part of the preprocessor wrapper?
a. #define
b. #endif
c. #ifndef
d. #include

17.2 Q3: Member function definitions:
a. Always require the binary scope operator (::).
b. Require the binary scope operator only when being defined outside of the definition of their class.
c. Can use the binary scope operator anywhere, but become public functions.
d. Must use the binary scope operator in their function prototype.

17.2 Q4: Parameterized stream manipulator setfill specifies the fill character that is displayed when an output is displayed in a field wider than the number of characters or digits in the output. The effect of setfill applies:
a. Only to the current value being displayed.
b. Only to outputs displayed in the current statement.
c. Until explicitly set to a different setting.
d. Until the output buffer is flushed.

17.2 Q5: Every object of the same class:
a. Gets a copy of every member function and member variable.
b. Gets a copy of every member variable.
c. Gets a copy of every member function.
d. Shares pointers to all member variables and member functions.

17.2 Q6: Classes cannot:
a. Be derived from other classes.
b. Initialize data members in the class definition.
c. Be used to model attributes and behaviors of objects.
d. Include objects from other classes as members.

17.2 Q7: A class’s functions can throw exceptions, such as __________to indicate invalid data.
a. invalid_data
b. bad_data
c. invalid_argument
d. bad_argument

Section 17.3 Class Scope and Accessing Class Members

17.3 Q1: Variables defined inside a member function of a class have:
a. File scope.
b. Class scope.
c. Block scope.
d. Class or block scope, depending on whether the binary scope resolution operator (::) is used.

17.3 Q2: A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by:
a. ::
b. :
c. .
d. ->

Section 17.4 Separating Interface from Implementation

17.4 Q1: When independent software vendors provide class libraries to clients, they typically give the __________ for the class’s interface and the __________ for the class’s implementation.
a. Source code file, source code file.
b. Source code file, object file.
c. Object file, source code file.
d. Object file, object file.

17.4 Q2: Which of the following is not true about separating a class’s interface and implementation?
a. Inline member function definitions are included in the header file.
b. Changes in the class’s interface will affect the client.
c. Private data members are included in the header file.
d. Changes in the class’s implementation will affect the client.
ANS: d. Changes in the class’s implementation will affect the client.

Section 17.5 Access Functions and Utility Functions

17.5 Q1: The type of function a client would use to check the balance of a bank account would be:
a. A utility function.
b. A predicate function.
c. An access function.
d. A constructor.

17.5 Q2: Utility functions:
a. Are private member functions that support operations of the class’s other member functions.
b. Are part of a class’s interface.
c. Are intended to be used by clients of a class.
d. Are a type of constructor.

Section 17.6 Time Class Case Study: Constructors with Default Arguments

17.6 Q1: A default constructor:
a. Is a constructor that must receive no arguments.
b. Is the constructor generated by the compiler when no constructor is provided by the programmer.
c. Does not perform any initialization.
d. Both (a) and (b).

17.6 Q2: If a member function of a class already provides all or part of the functionality required by a constructor or another member function then:
a. Copy and paste that member function’s code into this constructor or member function.
b. Call that member function from this constructor or member function.
c. That member function is unnecessary.
d. This constructor or member function is unnecessary.

Section 17.7 Destructors

17.7 Q1: Which of the following is not true of a constructor and destructor of the same class?
a. They both have the same name aside from the tilde (~) character.
b. They are both usually called once per object created.
c. They both are able to have default arguments.
d. Both are called automatically, even if they are not explicitly defined in the class.

17.7 Q2: Which of the following is not true of a destructor?
a. It performs termination housekeeping.
b. It is called before the system reclaims the object’s memory.
c. If the programmer does not explicitly provide a destructor, the compiler creates an “empty” destructor.
d. It releases the object’s memory.

Section 17.8 When Constructors and Destructors Are Called

17.8 Q1: Given the class definition:

class CreateDestroy
{
public:
CreateDestroy() { cout << “constructor called, “; }
~CreateDestroy() { cout << “destructor called, “; }
};

What will the following program output?

int main()
{
CreateDestroy c1;
CreateDestroy c2;
return 0;
}

a. constructor called, destructor called, constructor called, destructor called,
b. constructor called, destructor called,
c. constructor called, constructor called,
d. constructor called, constructor called, destructor called, destructor called,

17.8 Q2: Given the class definition:

class CreateDestroy
{
public:
CreateDestroy() { cout << “constructor called, “; }
~CreateDestroy() { cout << “destructor called, “; }
};

What will the following program output?

int main()
{
for ( int i = 1; i <= 2; i++ )
CreateDestroy cd;
return 0;
}

a. constructor called, destructor called, constructor called, destructor called,
b. constructor called, constructor called,
c. constructor called, constructor called, destructor called, destructor called,
d. Nothing.

Section 17.9 Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member

17.9 Q1: Returning references to non-const, private data:
a. Allows private functions to be modified.
b. Is only dangerous if the binary scope resolution operator (::) is used in the function prototype.
c. Allows private member variables to be modified, thus “breaking encapsulation.”
d. Results in a compiler error.

17.9 Q2: A client changing the values of private data members is:
a. Only possible by calling private member functions.
b. Possible using public functions and references.
c. Never possible.
d. Only possible if the private variables are not declared inside the class.

Section 17.10 Default Memberwise Assignment

17.10 Q1: The assignment operator (=) can be used to:
a. Test for equality.
b. Copy data from one object to another.
c. Compare two objects.
d. Copy a class.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!