Accounting
Anthropology
Archaeology
Art History
Banking
Biology & Life Science
Business
Business Communication
Business Development
Business Ethics
Business Law
Chemistry
Communication
Computer Science
Counseling
Criminal Law
Curriculum & Instruction
Design
Earth Science
Economic
Education
Engineering
Finance
History & Theory
Humanities
Human Resource
International Business
Investments & Securities
Journalism
Law
Management
Marketing
Medicine
Medicine & Health Science
Nursing
Philosophy
Physic
Psychology
Real Estate
Science
Social Science
Sociology
Special Education
Speech
Visual Arts
Computer Science
Q:
Q1: Assuming the definition,
class BasePlusCommissionEmployee : public CommissionEmployee
which of the following is false?
a. The colon ( : ) in the header of the class definition indicates inheritance.
b. The keyword public indicates the type of inheritance.
c. All the public and protected members of class BasePlusCommissionEmployee are inherited as public and protected members, respectively, into class CommissionEmployee.
d. CommissionEmployee is the base class and BasePlusCommissionEmployee is the derived class.
Q:
Q3: To declare class subClass a privately derived class of superClass one would write:a. class subclass : private superClassb. class subclass :: private superClassc. class subclass < private superClass >d. class subclass inherits private superClass
Q:
Q2: Which of the following is not a good example of a hierarchy likely to be modeled by inheritance?a. Airplanes.b. Geometric shapes.c. Animals.d. Prime numbers.
Q:
Q1: Which of the following is most likely a base class of the other three?a. automobile.b. convertible.c. miniVan.d. sedan.
Q:
Q3: The is-a relationship represents.a. Composition.b. Inheritance.c. Information Hiding.d. A friend.
Q:
Q2: Which of the following is not a kind of inheritance in C++?a. public.b. private.c. static.d. protected.
Q:
Q1: Select the false statement regarding inheritance.a. A derived class can contain more attributes and behaviors than its base class.b. A derived class can be the base class for other derived classes.c. Some derived classes can have multiple base classes.d. Base classes are usually more specific than derived classes.
Q:
Q3: Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string "ABCDEFGHI", what string does string1( 4 , 2 ) return?
a. "EF"
b. "EFGHI"
c. "CDEF"
d. "CD"
Q:
Q1: An explicit constructor:a. Cannot be called outside of the class it is declared in.b. Can be implicitly called by the compiler to perform a data type conversion.c. Does not initialize its class's data members.d. Must take exactly one argument.
Q:
Q3: Which of the following lines would be the prototype for an overloaded cast operator function that converts an object of user-defined type Time into a double?
a. Time::operator double() const;
b. Time::static_cast double() const;
c. Time::operator_cast(double) const;
d. Time::double() const;
Q:
Q2: The prototypes of overloaded cast operator functions do not:
a. Specify the type they convert to.
b. Specify the type that is being converted.
c. Specify a return type.
d. Need to be defined inside the class whose objects are being converted.
Q:
Q1: Conversion constructors:
a. Can have multiple arguments.
b. Can convert between user-defined types.
c. Are implicitly defined by the compiler if not explicitly written by the programmer.
d. Cannot convert built-in types to user defined types.
Q:
Q1: Which statement is false?
a. Based on whether an operator is implemented as a member function or as a non-member function, the operator is used differently in expressions.
b. When an operator function is implemented as a member function, the leftmost (or only) operand must be an object (or a reference to an object) of the operator's class.
c. Operator member functions of a specific class are called (implicitly by the compiler) only when the left operand of a binary operator is specifically an object of that class, or when the single operand of a unary operator is an object of that class.
d. Another reason why you might choose a non-member function to overload an operator is to enable the operator to be commutative.
Q:
Q8[C++11]: Which of the following is false?
a. To receive a list initializer as an argument to a constructor, you can declare the constructor's parameter as type list_initialier<T> where T represents the type of the values in the list initializer.
b. To receive a list initializer as an argument to a constructor, you can declare the constructor's parameter as type initializer_list<T> where T represents the type of the values in the list initializer.
c. It's not possible to pass a list initializer to a constructor.
d. (a) and (c).
Q:
Q7[C++11]: To prevent class objects from being copied or assigned, you can:
a. Declare as private the class's copy constructor and overloaded assignment operator.
b. Declare the class's copy constructor and overloaded assignment operator with with = delete after the parameter list.
c. Simply do not declare a copy constructor or assignment operator in the class.
d. (a) or (b).
Q:
Q6: Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?
a. Having the possibility of leaving a dangling pointer.
b. Allowing both objects to point to the same dynamically allocated storage.
c. Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact.
d. Requiring the explicit overloading of the assignment operator.
Q:
Q5: To prevent class objects from being copied:
a. Make the overloaded assignment operator private.
b. Make the copy constructor private.
c. Both (a) and (b).
d. None of the above.
Q:
Q4: A copy constructor must receive its argument by reference because:
a. Otherwise the constructor will only make a copy of a pointer to an object.
b. Otherwise infinite recursion occurs.
c. The copy of the argument passed by value has function scope.
d. The pointer needs to know the address of the original data, not a temporary copy of it.
Q:
Q3: A copy constructor:
a. Is a constructor with only default arguments.
b. Is a constructor that initializes a newly declared object to the value of an existing object of the same class.
c. Is a constructor that takes no arguments.
d. None of the above.
Q:
Q2: The array subscript operator [], when overloaded, cannot:
a. Be used with linked list classes.
b. Take a float as an operand.
c. Take multiple values inside (e.g., [4,8]).
d. Take user-defined objects as operands.
Q:
Q1: Which of the following is false?
a. An entire non-char array cannot be input or output at once.
b. Two arrays cannot be meaningfully compared with equality or relational operators.
c. Arrays cannot be assigned to one another (i.e., array1 = array2;).
d. C++ ensures that you cannot "walk off" either end of an array.
Q:
Q3[C++11]: Which of the following statements about a unique_ptr object is true?
a. A unique_ptr is a "smart pointer" for managing dynamically allocated memory.
b. When a unique_ptr goes out of scope, its destructor automatically returns the managed memory to the free store.
c. You must explicitly delete the memory that's managed by a unique_ptr before the object goes out of scope.
d. All of the above.
Q:
Q2: The delete [] operator:
a. Can terminate the program.
b. Must be told which destructor to call when destroying an object.
c. Can delete an entire array of objects declared using new.
d. Is called implicitly at the end of a program.
Q:
Q1: Which of the following is false about the new operator and the object for which it allocates memory?
a. It calls the object's constructor.
b. It returns a pointer.
c. It does not require the size of the object to be explicitly specified in the new expression.
d. It automatically destroys the object after mainis exited.
Q:
Q1: There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is being overloaded to postincrement an object of type Date. Select the correct implementation:
a. Date Date::operator++( int )
{
Date temp = *this;
Increment();
return *temp;
}
b. Date Date::operator++( int )
{
Increment();
Date temp = *this;
return temp;
}
c. Date Date::operator++( int )
{
Date temp = *this;
return this;
temp.Increment();
}
d. Date Date::operator++( int )
{
Date temp = *this;
Increment();
return temp;
}
Q:
Q2: Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:
a. Prefix increment has slightly more overhead than postfix increment.
b. The postfix increment operator returns the actual incremented object with its new value.
c. Objects returned by postfix increment cannot be used in larger expressions.
d. The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.
Q:
Q1: The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:
a. To assign a dummy value to preincrement.
b. To make the argument list of postincrement include an int.
c. To have the postincrement operator call the preincrement operator.
d. Implicitly done by the compiler.
Q:
Q1: Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression !s?
a. s.operator!()
b. s.operator!( default_value1, default_value2,)
c. operator!( s )
d. A compiler error results because no arguments are given.
Q:
Q1: Suppose you have a programmer-defined data type Data and want to overload the << operator to output your data type to the screen in the form cout << dataToPrint; and allow cascaded function calls. The first line of the function definition would be:
a. ostream &operator<<( ostream &output, const Data &dataToPrint )
b. ostream operator<<( ostream &output, const Data &dataToPrint )
c. ostream &operator<<( const Data &dataToPrint, ostream &output )
d. ostream operator<<( const Data &dataToPrint, ostream &output )
Q:
Q5: For operators overloaded as non-static member functions:
a. Binary operators can have two arguments and unary operators can have one.
b. Both binary and unary operators take one argument.
c. Binary operators can have one argument, and unary operators cannot have any.
d. Neither binary nor unary operators can have arguments.
Q:
Q4: y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?a. y = y operator+= zb. y.operator+=(z)c. y = y + zd. y operator+=(y + z)
Q:
Q3: An overloaded + operator takes a class object and a double as operands. For it to be commutative (i.e., a + b and b + a both work):a. operator+ must be a member function of the class from which the objects are instantiated.b. operator+ must be a non-member function.c. It must be overloaded twice; the operator+ function that takes the object as the left operand must be a member function, and the other operator+ function must be a global function.d. The + operator cannot be overloaded to be commutative.
Q:
Q2: Which situation would require the operator to be overloaded as a non-member function?a. The overloaded operator is =.b. The left most operand must be a class object (or a reference to a class object).c. The left operand is an int.d. The operator returns a reference.
Q:
Q1: Which of the following operators can be overloaded as a non-member function?
a. ()
b. []
c. +=
d. ==
Q:
Q4: To implicitly overload the += operator:a. Only the + operator needs to be overloaded.b. Only the = operator needs to be overloaded.c. Both the + and = operators need to be overloaded.
Q:
Q3: Which statement about operator overloading is false?a. New operators can never be created.b. Certain overloaded operators can change the number of arguments they take.c. The precedence of an operator cannot be changed by overloading.d. Overloading cannot change how an operator works on built-in types.
Q:
Q2: Which of the following operators cannot be overloaded?a. The . operator.b. The -> operator.c. The & operator.d. The [ ] operator.
Q:
Q1: The correct function name for overloading the addition (+) operator is:a. operator+b. operator(+)c. operator:+d. operator_+
Q:
Q1: Which of the following is false?
a. A string can be defined to store any data type.
b. Class string provides bounds checking in its member function at.
c. Class string's overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context.
d. An exception is thrown if the argument to string's at member function is an invalid subscript.
Q:
Q1: Which statement about operator overloading is false?
a. Operator overloading is the process of enabling C++'s operators to work with class objects.
b. C++ overloads the addition operator (+) and the subtraction operator (-) to perform differently, depending on their context in integer, floating-point and pointer arithmetic with data of fundamental types.
c. You can overload all C++ operators to be used with class objects.
d. When you overload operators to be used with class objects, the compiler generates the appropriate code based on the types of the operands.
Q:
Q3: static member functions:
a. Can use the this pointer.
b. Can access only other static member functions and static data members.
c. Cannot be called until an object of their class is instantiated.
d. Can be declared const as well.
Q:
Q2: static data members of a certain class:
a. Can be accessed only if an object of that class exists.
b. Cannot be changed, even by objects of the same that class.
c. Have class scope.
d. Can only be changed by static member functions.
Q:
Q1: If Americans are objects of the same class, which of the following attributes would most likely be represented by a staticvariable of that class?
a. Age.
b. The President.
c. Place of birth.
d. Favorite food.
Q:
Q3: 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:
a. t.a().b().d();
b. a().b().t;
c. t.d().c();
d. t.a().t.d();
Q:
Q2: 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:
a. *this.x
b. (*this).x
c. x
d. None of the above are equivalent.
Q:
Q1: For a non-constant member function of class Test, the this pointer has type:
a. const Test *
b. Test * const
c. Test const *
d. const Test * const
Q:
Q2: Which of the following statements about friend functions and friend classes is false?a. A class can either grant friendship to or take friendship from another class using the friend keyword.b. A friend declaration can appear anywhere in a class definition.c. A friend of a class can access all of its private data member and member functions.d. The friendship relationship is neither symmetric nor transitive.
Q:
Q1: If the line:friend class A;appears in class B, and the line:friend class B;appears in class C, then:a. Class A is a friend of class C.b. Class A can access private variables of class B.c. Class C can call class A's private member functions.d. Class B can access class A's private variables.
Q:
Q2: An error occurs if:a. A non-reference, non-const, primitive data member is initialized in the member initialization list.b. An object data member is not initialized in the member initialization list.c. An object data member does not have a default constructor.d. An object data member is not initialized in the member initialization list and does not have a default constructor.
Q:
Q1: When composition (one object having another object as a member) is used:a. The host object is constructed first and then the member objects are placed into it.b. Member objects are constructed first, in the order they appear in the host constructor's initializer list.c. Member objects are constructed first, in the order they are declared in the host's class.d. Member objects are destructed last, in the order they are declared in the host's class.
Q:
Q2: The code fragment:Increment::Increment( int c, int i ): increment ( i ){count = c;}does not cause any compilation errors. This tells you that:a. count must be a non-const variable.b. count must be a const variable.c. increment must be a non-const variable.d. increment must be a const variable.
Q:
Q1: Which of the following statements will not produce a syntax error?a. Defining a const member function that modifies a data member of the object.b. Invoking a non-const member function on a const object.c. Declaring an object to be const.d. Declaring a constructor to be const.
Q:
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.
Q:
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.
Q:
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.
Q:
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.
Q:
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,
Q:
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.
Q:
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.
Q:
Q3[C++11]: Which of the following statements is false?
a. You can overload a classes constructors.
b. There is no mechanism in C++ for a constructor to call another constructor in the same class.
c. 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.
d. 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.
Q:
Q3[C++11]: 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?
a. Time t1;
b. Time t2{ 22, 40 };
c. Time t3( 22, 40 );
d. (a), (b) and (c) are all valid ways to initialize a Time object.
Q:
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.
Q:
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).
Q:
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.
Q:
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.
Q:
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. ->
Q:
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.
Q:
Q6: 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
Q:
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.
Q:
Q4: 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:
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.
Q:
Q3: Member function definitions:
a. Always require the scope resolution operator (::).
b. Require the scope resolution operator only when being defined outside of the definition of their class.
c. Can use the scope resolution operator anywhere, but become public functions.
d. Must use the scope resolution operator in their function prototype.
Q:
Q2: Which of the following preprocessor directives does not constitute part of the preprocessor wrapper?
a. #define
b. #endif
c. #ifndef
d. #include
Q:
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.
Q:
Q2: Assuming that the string object text contains the string "Hello!!! ", the "expression text.substr( 2 , 5 ) would return a string object containing the string:
a. "llo!! ".
b. "llo! ".
c. "ello! ".
d. "ello".
Q:
Q1: To execute multiple statements when an if statement's condition is true, enclose those statements in a pair of:
a. Parentheses, ( ).
b. Square Brackets, [ ].
c. Braces, { }.
d. Angle brackets, < >.
Q:
Q3: When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client's code during the:
a. Programming phase.
b. Compiling phase.
c. Linking phase.
d. Executing phase.
Q:
Q2: When compiling a class's source code file (which does not contain a main function), the information in the class's header file is used for all of the following, except:
a. Ensuring that the header of each member function matches its prototype.
b. Ensuring that each member function knows about the class's data members and other member functions.
c. Determining the correct amount of memory to allocate for each object of the class.
d. All of the above are uses that the compiler has for the header file information.
Q:
Q1: In the source-code file containing a class's member function definitions, each member function definition must be tied to the class definition by preceding the member function name with the class name and ::, which is known as the:
a. Member definition linker.
b. Class implementation connector.
c. Source code resolver.
d. Scope resolution operator.
Q:
Q2: Assuming that GradeBook.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file?
a. #include <iostream>
b. #include "iostream"
c. #include <GradeBook.h>
d. #include "GradeBook.h"
Q:
Q1: A header file is typically given the filename extension:
a. .h
b. .hdr
c. .header
d. .cpp