CRC CISP 400 C++ Quiz 5
Inside a function definition for a member function of an object with data member x, which of the following is not equivalent to this->x: 1. *this.x 2. (*this).x 3. x 4. None of these are equivalent.
1. *this.x
A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by: 1. :: 2. : 3. . 4. ->
1. ::
A client changing the values of private data members is: 1. Only possible by calling private member functions. 2. Possible using public functions and references. 3. Never possible. 4. Only possible if the private variables are not declared inside the class.
2. Possible using public functions and references.
An error occurs if: 1. A non-reference, non-const, primitive data member is initialized in the member initialization list. 2. An object data member is not initialized in the member initialization list. 3. An object data member does not have a default constructor. 4. An object data member is not initialized in the member initialization list and does not have a default constructor.
4. An object data member is not initialized in the member initialization list and does not have a default constructor.
The delete operator: 1. Is called implicitly at the end of a program. 2. Must be told which destructor to call when destroying an object. 3. Can terminate the program. 4. Can delete an entire array of objects declared using new.
4. Can delete an entire array of objects declared using new.
Assuming the following constructor is provided for class Time explicit Time( int = 0, int = 0, int = 0 ); which of the following is not a valid way to initialize a Time object? 1. Time t1; 2. Time t2{ 22, 40 }; 3. Time t3( 22, 40 ); 4. Time t1; , Time t2{ 22, 40 }; and Time t3( 22, 40 ); are all valid ways to initialize a Time object.
Time t1; , Time t2{ 22, 40 }; and Time t3( 22, 40 ); are all valid ways to initialize a Time object.
Which of the following are true about an abstract data type? I. Captures a data representation. II. Defines the operations that are allowed on its data. III. Replaces structured programming. A. II and III. B. I, II and III. C. I and II. D. I and III.
C. I and II.
The code fragment: Increment::Increment( int c, int i ) : increment ( i ) { count = c; } does not cause any compilation errors. This tells you that: 1. count must be a non-const variable. 2. count must be a const variable. 3. increment must be a non-const variable. 4. increment must be a const variable.
1. count must be a non-const variable.
If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class? 1. Age. 2. The President. 3. Place of birth. 4. Favorite food.
2. The President.
A class's functions can throw exceptions, such as ________ to indicate invalid data. 1. invalid_data 2. bad_data 3. invalid_argument 4. bad_argument
3. invalid_argument
Which of the following statements about friend functions and friend classes is false? 1. A class can either grant friendship to or take friendship from another class using the friend keyword. 2. A friend declaration can appear anywhere in a class definition. 3. A friend of a class can access all of its private data member and member functions. 4. The friendship relationship is neither symmetric nor transitive.
1. A class can either grant friendship to or take friendship from another class using the friend keyword.
Utility functions: 1. Are private member functions that support operations of the class's other member functions. 2. Are part of a class's interface. 3. Are intended to be used by clients of a class. 4. Are a type of constructor.
1. Are private member functions that support operations of the class's other member functions.
Instead of including a string data type among C++'s built-in data types, C++: 1. Was designed to include mechanisms for creating and implementing string abstract data types through classes. 2. Forces the programmer to make do with char array strings. 3. None of the above. 4. Chose to ignore the need for a string data type.
1. Was designed to include mechanisms for creating and implementing string abstract data types through classes.
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; } 1. constructor called, destructor called, constructor called, destructor called, 2. constructor called, constructor called, 3. constructor called, constructor called, destructor called, destructor called, 4. Nothing.
1. constructor called, destructor called, constructor called, destructor called,
Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() returns void, which of the following statements will not produce a syntax error: 1. t.a().b().d(); 2. a().b().t; 3. t.d().c(); 4. t.a().t.d();
1. t.a().b().d();
Which of the following is not an abstract data type? 1. A used-defined class. 2. A for loop. 3. An ASCII character. 4. An int.
2. A for loop.
If a member function of a class already provides all or part of the functionality required by a constructor or another member function then: 1. Copy and paste that member function's code into this constructor or member function. 2. Call that member function from this constructor or member function. 3. That member function is unnecessary. 4. This constructor or member function is unnecessary.
2. Call that member function from this constructor or member function.
static member functions: 1. Can use the this pointer. 2. Can access only other static member functions and static data members. 3. Cannot be called until an object of their class is instantiated. 4. Can be declared const as well.
2. Can access only other static member functions and static data members.
If the line: friend class A; appears in class B, and the line: friend class B; appears in class C, then: 1. Class A is a friend of class C. 2. Class A can access private variables of class B. 3. Class C can call class A's private member functions. 4. Class B can access class A's private variables.
2. Class A can access private variables of class B.
The assignment operator (=) can be used to: 1. Test for equality. 2. Copy data from one object to another. 3. Compare two objects. 4. Copy a class.
2. Copy data from one object to another.
Every object of the same class: 1. Gets a copy of every member function and member variable. 2. Gets a copy of every member variable. 3. Gets a copy of every member function. 4. Shares pointers to all member variables and member functions.
2. Gets a copy of every member variable.
Member access specifiers (public and private) can appear: 1. In any order and multiple times, if they have brackets separating each type. 2. In any order and multiple times. 3. Outside a class definition. 4. In any order (public first or private first) but not multiple times.
2. In any order and multiple times.
Proxy classes are best described as an example of: 1. Structured programming. 2. Information hiding. 3. Object-oriented programming (as used in the text). 4. Utility functions.
2. Information hiding.
Which of the following is false about the new operator and the object for which it allocates memory? 1. It returns a pointer. 2. It automatically destroys the object after main is exited. 3. It does not require the size of the object to be explicitly specified in the new expression. 4. It calls the object's constructor.
2. It automatically destroys the object after main is exited.
Separating Implementation from Interface ,br> 9.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. 1. Source code file, source code file. 2. Source code file, object module file. 3. Object module file, object module file. 4. Object module file, source code file.
2. Source code file, object module file.
For a non-constant member function of class Test, the this pointer has type: 1. const Test * 2. Test * const 3. Test const * 4. const Test * const
2. Test * const
In addition to hiding the implementation details that the ordinary method of "separating implementation from interface" would hide, using a proxy class also hides: 1. The definition of access functions. 2. The names of private data members. 3. The definition of constructors and the destructor. 4. The definition of inline functions.
2. The names of private data members.
Which of the following statements is false? 1. You can overload a classes constructors. 2. There is no mechanism in C++ for a constructor to call another constructor in the same class. 3. Just as a constructor can call a class's other member functions to perform tasks, C++11 allows constructors to call other constructors in the same class. 4. To overload a constructor, provide in the class definition a prototype for each version of the constructor, and provide a separate constructor definition for each overloaded version.
2. There is no mechanism in C++ for a constructor to call another constructor in the same class.
Which of the following is not true about declaring references to objects of other classes inside a class definition? 1. If the class names for the other objects are used only to declare these references, a forward declaration can replace the #include statement usually used to include those classes' header files. 2. These references can be initialized inside the class definition. 3. These references can represent directional associations from a UML class diagram. 4. Each reference only requires enough memory to store the memory address of the object it references.
2. These references can be initialized inside the class definition.
Which of the following capabilities do "raw" C++ arrays not provide? 1. Dynamic size expansion to accommodate more elements. 2. Array comparison. 3. "Raw" arrays do not provide any of the above capabilities. 4. Subscript range checking.
3. "Raw" arrays do not provide any of the above capabilities.
Returning references to non-const, private data: 1. Allows private functions to be modified. 2. Is only dangerous if the binary scope resolution operator (::) is used in the function prototype. 3. Allows private member variables to be modified, thus "breaking encapsulation." 4. Results in a compiler error.
3. Allows private member variables to be modified, thus "breaking encapsulation."
The type of function a client would use to check the balance of a bank account would be: 1. A utility function. 2. A predicate function. 3. An access function. 4. A constructor.
3. An access function.
Variables defined inside a member function of a class have: 1. File scope. 2. Class scope. 3. Block scope. 4. Class or block scope, depending on whether the binary scope resolution operator (::) is used.
3. Block scope.
Which of the following is not true about separating a class's interface and implementation? 1. Inline member function definitions are included in the header file. 2. Private data members are included in the header file. 3. Changes in the class's implementation will affect the client. 4. Changes in the class's interface will affect the client.
3. Changes in the class's implementation will affect the client.
Many ___________ exist which help to develop programs from portable, carefully tested and widely available components. 1. Structured program environments. 2. Object libraries. 3. Class libraries. 4. Driver files.
3. Class libraries.
Which of the following statements will not produce a syntax error? 1. Defining a const member function that modifies a data member of the object. 2. Invoking a non-const member function on a const object. 3. Declaring an object to be const. 4. Declaring a constructor to be const.
3. Declaring an object to be const.
static data members of a certain class: 1. Cannot be changed, even by objects of the same that class. 2. Can be accessed only if an object of that class exists. 3. Have class scope. 4. Can only be changed by static member functions.
3. Have class scope.
Classes cannot: 1. Include objects from other classes as members. 2. Be used to model attributes and behaviors of objects. 3. Initialize data members in the class definition. 4. Be derived from other classes.
3. Initialize data members in the class definition.
When composition (one object having another object as a member) is used: 1. The host object is constructed first and then the member objects are placed into it. 2. Member objects are constructed first, in the order they appear in the host constructor's initializer list. 3. Member objects are constructed first, in the order they are declared in the host's class. 4. Member objects are destructed last, in the order they are declared in the host's class.
3. Member objects are constructed first, in the order they are declared in the host's class.
Member function definitions: 1. Always require the binary scope operator (::). 2. Can use the binary scope operator anywhere, but become public functions. 3. Require the binary scope operator only when being defined outside of the definition of their class. 4. Must use the binary scope operator in their function prototype.
3. Require the binary scope operator only when being defined outside of the definition of their class.
Which of the following is not true of a constructor and destructor of the same class? 1. They both have the same name aside from the tilde (~) character. 2. They are both usually called once per object created. 3. They both are able to have default arguments. 4. Both are called automatically, even if they are not explicitly defined in the class.
3. They both are able to have default arguments.
Parameterized stream manipulator setfill specifies the fill character that's 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: 1. Only to the current value being displayed. 2. Only to outputs displayed in the current statement. 3. Until explicitly set to a different setting. 4. Until the output buffer is flushed.
3. Until explicitly set to a different setting.
Which of the following preprocessor directives does not constitute part of the preprocessor wrapper? 1. #define 2. #endif 3. #ifndef 4. #include
4. #include
A default constructor: 1. Is a constructor that must receive no arguments. 2. Is the constructor generated by the compiler when no constructor is provided by the programmer. 3. Does not perform any initialization. 4. Both Is a constructor that must receive no arguments and Is the constructor generated by the compiler when no constructor is provided by the programmer..
4. Both Is a constructor that must receive no arguments and Is the constructor generated by the compiler when no constructor is provided by the programmer..
Which of the following is not true of a destructor? 1. It performs termination housekeeping. 2. It is called before the system reclaims the object's memory. 3. If the programmer does not explicitly provide a destructor, the compiler creates an "empty" destructor. 4. It releases the object's memory.
4. It releases the object's memory.
Associations in a class diagram that have no navigability arrows at all indicate: 1. That operations performed by this association do not return values. 2. That the two classes are the same. 3. Inheritance from the same base class. 4. That navigation can proceed in either direction across the association.
4. That navigation can proceed in either direction across the association.
The numbers 3, 2, 5, 7 are enqueued in a queue in that order, then three numbers are dequeued, and finally 3, 7, 9, 4 are enqueued in that order. What is the first number in the queue (the next number to be dequeued)? A. 4. B. 7. C. 9. D. 3.
B. 7.
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; } 1. constructor called, destructor called, constructor called, destructor called, 2. constructor called, destructor called, 3. constructor called, constructor called, 4. constructor called, constructor called, destructor called, destructor called,
4. constructor called, constructor called, destructor called, destructor called,
Which of the following is not a type of container (collection) class? 1. Arrays. 2. Stacks. 3. Linked lists. 4. floats.
4. floats.