c++ 13-14
24) Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these
A
13) True/False: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.
TRUE
13.2 True/False Questions 1) True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.
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
16) True/False: The this pointer is automatically passed to non-static member functions of a class.
TRUE
2) True/False: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
TRUE
3) True/False: When you overload an operator, you can change the operator's original meaning to something entirely different.
TRUE
5) True/False: More than one constructor function may be defined for a class.
TRUE
7) True/False: A static member variable can be used when there are no objects of the class in existence.
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
13) True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.
TRUE
12) If a member variable is declared ________, all objects of that class have access to that variable. A) static B) dynamic C) inline D) default E) None of these
A
13) This type of member function may be called from a statement outside the class. A) public B) private C) undeclared D) global E) None of these
A
16) A class is a(n) ________ that is defined by the programmer. A) data type B) function C) method D) attribute E) None of these
A
19) When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these
A
23) A class may have this many default constructor(s). A) only one B) more than one C) a maximum of two D) any number E) None of these
A
17) Members of a class object are accessed with the ________. A) dot operator B) cin object C) extraction operator D) stream insertion operator E) None of these
A
25) The process of object-oriented analysis can be viewed as the following steps: A) Identify objects, then define objects' attributes, behaviors, and relationships B) Define data members and member functions, then assign a class name C) Declare private and public variables, prototype functions, then write code D) Write the main() function, then determine which classes are needed E) None of these
A
3) This operator may be used to assign one object to another. A) = B) == C) <> D) @ E) None of these
A
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 0; } A) The program runs, but with no output. B) 77 C) Hello! D) The program will not compile.
B
6) Class declarations are usually stored here. A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these
B
6) When objects contain pointers, it is a good idea to create an explicit ________ function. A) destructor B) copy constructor C) static constructor D) inline constructor E) None of these
B
12) When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________. A) empty constructor B) default constructor C) stand-alone function D) arbitrator function E) None of these
B
14) If you do not declare an access specification, the default for members of a class is ________. A) inline B) private C) public D) global E) None of these
B
18) To overload the + operator, you would write a function named ________. A) overload + B) operator + C) function + D) operator.overload(+) E) None of these
B
19) This is a special built-in pointer that is available to a class's member functions. A) overloaded -> operator B) this pointer C) &constructor pointer D) ~destructor *ptr E) None of these
B
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
B
26) When a member function is defined outside of the class declaration, the function name must be qualified with the ________. A) class name, followed by a semicolon B) class name, followed by the scope resolution operator C) name of the first object D) private access specifier E) None of these
B
5) This is used to protect important data. A) public access specifier B) private access specifier C) protect() member function D) class protection operator, @ E) None of these
B
7) A good reason for overloading an operator is to enable it to ________. A) outperform its C language counterparts B) work in its usual way, but with programmer-defined data types C) operate on more operands than in its standard definition D) operate on no operands E) None of these
B
9) A ________ is a member function that is automatically called when a class object is ________. A) destructor, created B) constructor, created C) static function, deallocated D) utility function, declared E) None of these
B
9) If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object. A) overloaded constructor function B) overloaded assignment operator C) default constructor function D) overloaded copy operator E) None of these
B
Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 13 Introduction to Classes 13.1 Multiple Choice Questions 1) Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floats E) None of these
B
Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 14 More About Classes 14.1 Multiple Choice Questions 1) Each object of a class has its own copy of the class's ________. A) member functions B) member variables C) constructor and destructor functions D) All of these E) None of these
B
11) A reason to overload the ________ is to write classes that have array-like behaviors. A) parentheses ( ) operator B) curly braces { } operator C) square brackets [ ] operator D) colon : : operator E) None of these
C
22) This is automatically called when an object is destroyed. A) constructor function B) specification deallocator C) destructor function D) coroner function E) None of these
C
27) If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used. A) variable B) ambiguity C) scope D) global E) None of these
C
30) 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; } A) The program runs, but with no output. B) 0 C) Hello! D) The program will not compile.
C
10) It is a good idea to make a copy constructor's parameters ________ by specifying the ________ key word in the parameter list. A) inline, inline B) static, static C) constant, const D) global, global E) None of these
C
13) A member function that is declared ________ may not access any non-static data members in the class. A) private B) public C) static D) inline E) None of these
C
15) This is a special function that is called whenever a new object is created and initialized with another object's data. A) destructor B) static function C) copy constructor D) assignment function E) None of these
C
17) When you redefine the way a standard operator works when it is used with class objects, you have ________ the operator. A) reassigned B) reformatted C) overloaded D) overwhelmed E) None of these
C
18) Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr; A) declares an object of class Rectangle B) assigns the value of *BoxPtr to the object Rectangle C) defines a Rectangle pointer variable called BoxPtr D) is illegal in C++ E) None of these
C
20) Object composition is useful for creating this type of relationship between classes. A) friend B) static C) has a D) conditional E) None of these
C
21) An ________ operator can work with programmer-defined data types. A) inline B) unconditional C) overloaded D) undefined E) None of these
C
21) The constructor function always has the same name as ________. A) the first private data member B) the first public data member C) the class D) the first object of the class E) None of these
C
23) A(n) ________ informs the compiler that a class will be declared later in the program. A) static function B) private data member C) forward declaration D) object conversion E) None of these
C
24) In the following function header: FeetInches FeetInches::operator++(int) the word (int) is known as a(n): A) parameterless data type B) incomplete argument C) dummy parameter D) incomplete parameter E) None of these
C
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? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();
C
4) Examples of access specifiers are the key words: A) near and far B) opened and closed C) private and public D) table and row E) None of these
C
5) C++ allows you to redefine the way ________ work when used with class objects. A) compiler errors B) preprocessor directives C) standard operators D) undefined variables E) None of these
C
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. A) #include B) #guard C) #ifndef D) #endif E) None of these
C
8) When a class contains an instance of another class, it is known as ________. A) object overloading B) operator overloading C) object composition D) dynamic composition E) None of these
C
8) When the body of a member function is defined inside a class declaration, it is said to be ________. A) static B) global C) inline D) conditional E) None of these
C
22) When you overload an operator, you cannot change the number of ________ taken by the operator. A) arguments B) parameters C) operations D) operands E) None of these
D
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 0; } A) The program runs, but with no output. B) 77 C) 0 D) The program will not compile.
D
11) The destructor function's return type is ________. A) tilde B) int C) float D) Nothing. Destructors have no return type. E) None of the above
D
14) This type of function is not a member of a class, but it has access to the private members of the class. A) static B) constructor C) destructor D) friend E) None of these
D
15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these
D
16) If you do not furnish one of these a default will be provided for you by the compiler. A) copy constructor B) constructor C) destructor D) All of these E) None of these
D
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 ________. A) values, morals B) data, activities C) attributes, activities D) attributes, methods E) None of these
D
2) This type of member variable may be accessed before any objects of the class have been created. A) private B) public C) inline D) static E) None of these
D
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.
D
3) A C++ class is similar to one of these. A) inline function B) header file C) library function D) structure E) None of these
D
4) C++ requires that a copy constructor's parameter be a(n) ________. A) integer data type B) floating point data type C) pointer variable D) reference object E) None of these
D
10) The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these
E
12) True/False: You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^.
FALSE
14) True/False: In C++, if you overload the < operator, you must also overload the > operator.
FALSE
14.2 True/False Questions 1) True/False: When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.
FALSE
15) True/False: A non-static member function may not access a static member variable.
FALSE
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
4) True/False: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded.
FALSE
5) True/False: A public data member may be declared a friend of a private function.
FALSE
6) True/False: C++ permits you to overload the sizeof operator and the this pointer.
FALSE
6) True/False: More than one destructor function may be defined for a class.
FALSE
8) True/False: When you overload the << operator, you must also overload the >> operator.
FALSE
8) True/False: You must declare all data members of a class before you declare member functions.
FALSE
9) True/False: You can overload the conditional operator to make it function as an unconditional operator.
FALSE
9) True/False: You must use the private access specification for all data members of a class.
FALSE
10) 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
10) True/False: A static member function does not need to be called by a specific object of the class.
TRUE
11) True/False: If you do not declare a destructor function, the compiler will furnish one automatically.
TRUE
11) True/False: It is possible to declare an entire class as a friend of another class.
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