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
Programming Language
Q:
Q1: The line:
virtual double earnings() const = 0;
appears in a class definition. You cannot deduce that:
a. All classes that directly inherit from this class will override this method.
b. This class is an abstract class.
c. Any concrete class derived from this class will have an earnings function.
d. This class will probably be used as a base class for other classes.
Q:
Q1: Problems using switch logic to deal with many objects of different types do not include:
a. Forgetting to include an object in one of the cases.
b. Having to update the switch statement whenever a new type of object is added.
c. Having to track down every switch statement to do an update of object types.
d. Not being able to implement separate functions on different objects.
Q:
Q4[C++11]: Which of the following statements is true?a. In C++11, all classes can be used as base classes.b. In C++11, only classes that are not declared as final can be used as base classes.c. In C++11, only classes that are declared as base can be used as base classes.d. None of the above
Q:
Q3: Which of the following statements about virtual functions is false?a. They allow the program to select the correct implementation at execution time.b. They can use either static or dynamic binding, depending on the handles on which the functions are called.c. They do not remain virtual down the inheritance hierarchy.d. They can be called using the dot operator.
Q:
.4 Q2: virtual functions must:
a. Be overridden in every derived class.
b. Be declared virtualin every derived class.
c. Be declared virtual in the base class.
d. Have the same implementation in every derived class.
Q:
.4 Q1: If objects of all the classes derived from the same base class all need to draw themselves, the draw function would most likely be declared:
a. private
b. virtual
c. protected
d. friend
Q:
.3 Q1: Downcasting enables:
a. A derived-class object to be treated as a base-class object.
b. A base-class object to be treated as a derived-class object.
c. Making a base-class pointer into a derived-class pointer.
d. Making a derived-class pointer into a base -class pointer.
Q:
.2 Q1: Which of the following assignments would be a compilation error?
a. Assigning the address of a base-class object to a base-class pointer.
b. Assigning the address of a base-class object to a derived-class pointer.
c. Assigning the address of a derived-class object to a base-class pointer.
d. Assigning the address of a derived-class object to a derived-class pointer.
Q:
.1 Q1: Employee is a base class and HourlyWorker is a derived class, with a redefined non-virtual print function. Given the following statements, will the output of the two print function calls be identical?
HourlyWorker h;
Employee *ePtr = &h;
ePtr->print();
ePtr->Employee::print();
a. Yes.
b. Yes, if print is a static function.
c. No.
d. It would depend on the implementation of the print function.
Q:
Q1: Which of the following would not be a member function that derived classes Fish, Frog and Bird should inherit from base class Animal and then provide their own definitions for, so that the function call can be performed polymorphically?
a. eat
b. sleep
c. move
d. flapWings
Q:
Q1: Which of the following statements about polymorphism is false?
a. With polymorphism, you can direct a variety of objects to behave in manners appropriate to those objects without even knowing their types.
b. With polymorphism, new types of objects that can respond to existing messages can easily be incorporated into a system without modifying the base system.
c. Polymorphism enables you to deal in specifics and let the execution-time environment concern itself with the generalities.
d. To get polymorphic behavior among existing objects, those objects must be instantiated from classes in the same inheritance hierarchy.
Q:
Q1: Polymorphism is implemented via:
a. Member functions.
b. virtual functions and dynamic binding.
c. inline functions.
d. Non-virtual functions.
Q:
Q2: Which of the following is true about using inheritance in software engineering?
a. Common attributes and behaviors should be factored out of closely related classes and placed into a base class from which the original classes can now inherit.
b. It is best to create a huge class library to make it easy for a client to find the most appropriate class for his or her needs.
c. A class produced through inheritance should be as large as possible to fully encompass all of the functionality it should offer.
d. The standard C++ libraries that are shipped with C++ compilers are usually enough to accomplish anything an application might need to do.
Q:
Q1: Theoretically, clients do not need to see the _________ of classes from which they derive other classes.
a. Header files.
b. Source code.
c. Object code.
d. Interface.
Q:
Q2: When deriving a class from a protected base class, the public members of the base class become _________ and the protected members of the base class become __________?
a. protected, private
b. public, private
c. protected, protected
d. public, protected
Q:
Q1: Which forms of inheritance are is-a relationships?
a. All forms of inheritance are is-a relationships.
b. Only public and private.
c. Only public and protected.
d. Only public.
Q:
Q3[C++11]: Which of the following statements about inheriting base class constructors is false?
a. To inherit a base class's constructors, you write the following line of code in the derived class definition (BaseClass is the base class's name):
using BaseClass::BaseClass;
b. If an inherited base-class constructor has default arguments, the line of code in Part (a) causes the compiler to generate a derived-class constructor with the same default arguments.
c. By default, each inherited constructor has the same access level (public, protected or private) as its corresponding base-class constructor.
d. If the derived class does not explicitly define constructors, the compiler generates a default constructor in the derived classeven if it inherits other constructors from its base class.
Q:
Q2: Base class constructors and assignment operators:
a. Are not inherited by derived classes.
b. Should not be called by derived class constructors and assignment operators.
c. Can be inherited by derived classes, but generally are not.
d. Can call derived-class constructors and assignment operators.
Q:
Q1: When an object of a derived class is instantiated, the __________ constructor initializes the _________ members.
a. Base class, base class.
b. Derived class, base class.
c. Base class, derived class.
d. Derived class, public.
Q:
Q6: From most restrictive to least restrictive, the access modifiers are:a. protected, private, publicb. private, protected, publicc. private, public, protectedd. protected, public, private
Q:
Q5: When should base class members be declared protected?a. When all clients should be able to access these members.b. When these members are used only by member functions of this base class.c. When these members should be available only to derived classes (and friends), but not to other clients.d. The protected access specified should never be used.
Q:
Q4: protected base class members cannot be accessed by:a. Functions that are neither friends of the base class, derived-class member functions nor friends of a derived class.b. friends of the base class.c. Functions that are not derived-class member functions.d. friends of derived classes.
Q:
Q3: Which of the following is not one of the disadvantages of using the "copy-and-paste" approach to duplicating code from one class into another class?a. Errors are prone to be spread around.b. It is time consuming.c. It forces the system to store many physical copies of the code, creating a code-maintenance nightmare.d. All of the above are disadvantages of the "copy-and-paste" approach.
Q:
Q2: Assuming the following is the beginning of the constructor definition for class BasePlus-CommissionEmployee which inherits from class Point,BasePlusCommissionEmployee::BasePlusCommissionEmployee( string first,string last, string ssn, double sales, double rate, double salary ): CommissionEmployee( first, last, ssn, sales, rate )The second line:a. Invokes the CommissionEmployee constructor with arguments.b. Causes a compiler error.c. Is unnecessary because the CommissionEmployee constructor is called automatically.d. Indicates inheritance.
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.