Classes Ch 13 & 14

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Select all that apply. Given the following code fragment, which of the things shown below happen when the statement on line 8 executes? 1 int square(int a) 2 { 3 return a * a; 4 } 5 int main() 6 { 7 int x = 0; 8 x = square(5); 9 cout << x << endl; 10 return 0; 11 } a. The square function is called and the value 5 is passed as an argument. b. The square function calculates 5*5 and stores the result, 25, as a temporary value. c. The temporary value is copied (assigned) to the variable x. d. The temporary value is discarded by the system. e. None of these

A,B,C,D

A good reason to overload 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

When a constructor has a member initialization list, the initializations take place a. after any statements in the body of the constructor execute b. before any statements in the body of the constructor execute c. when a member is used in the execution of the program d. None of these

B

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

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

A reason to overload the __________ is to allow you 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

A C++ class is similar to a(n) a. inline function b. header file c. library function d. structure e. None of these

D

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

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 not available to code that is written outside the class. e. All of these are true.

D

The destructor function's return type is a. int b. float c. char d. Nothing; destructors have no return type e. None of these

D

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

Which type of function is not a member of a class but has access to the private members of the class? a. static b. constructor c. destructor d. friend e. None of these

D

The constructor function's return type is a. int b. float c. char d. structure pointer e. None of these

E

A destructor function can have zero to many parameters.

F

A non-static member function may not access a static member variable.

F

It is possible to declare an entire class as a friend of another class.

T

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.

T

When you overload an operator, you can change the operator's original meaning to something entirely different.

T

Whereas object-oriented programming centers on the object, procedural programming centers on functions.

T

You can use the technique known as a member intialization list to initialize members of a class.

T

A __________ is a member function that is automatically called when a class object is __________. a. constructor, created b. destructor, created c. static function, deallocated d. utility function, declared e. None of these

A

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

A(n) __________ is a special built-in pointer that is available to a class's member functions.. a. this pointer b. &constructor pointer c. ~destructor *ptr d. overload operator, -> e. None of these

A

How many default constructors can a class have? a. only one b. two or more c. only two d. any number e. None of these

A

If a member 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

In C++11 the __________ operator swaps the members of the object being assigned with the temporary object. a. move assignment b. swap assignment c. temp assignment d. semantic assignment e. None of these

A

In C++11 you can have one constructor call another constructor in the same class by using a. constructor delegation b. in-place initialization c. a member initialization list d. None of these

A

Members of the class object are accessed with the a. dot operator b. cin object c. extraction operator d. stream insertion operator e. None of these

A

Objects in an array are accessed with __________. a. subscripts b. parentheses c. #include statements d. output format manipulators e. None of these

A

The process of object-oriented analysis can be viewed as the following steps: a. identify objects, then define each object's attributes, behaviors, and relationships b. define data members and member functions, then assign the class name c. declare public and private variables, prototype functions, and then write code d. write the main() function, then determine which classes are needed e. None of these

A

The type of member function that may be called from a statement outside the class is a. public b. private c. undeclared d. global e. None of these

A

When you dereference an object pointer, use the a. -> operator b. <> operator c. dot operator d. & operator e. None of these

A

Which of the following operators may be used to assign one object to another? a. = b. == c. <> d. @ e. None of these

A

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

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

If you do not furnish a(n) __________, 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

In C++11 values that persist beyond the statement that created them and have names that make them accessible to other statements in the program are called a. rvalues b. lvalues c. temporary values d. semantics e. None of these

B

Objects are created from abstract data types that encapsulate __________ and __________ together. a. numbers, characters b. data, functions c. addresses, pointers d. integers, floating-point numbers e. None of these

B

The following code shows an example of __________ class Point { private: double y = 5.70; double z = 3.0; public: Public member functions go here... }; a. constructor delegation b. in-place initialization c. a default constructor creation d. an illegal initialization

B

To overload the + operator, you would write a function named a. overload + b. operator + c. function + d. operator.overload(+) e. None of these

B

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 there is no output. b. 77 c. Hello! d. the program will not compile

B

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

Where are class declarations usually stored? 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

Which of the following is used to protect important data? a. the public access specifier b. the private access specifier c. the protect member function d. the class protection operator, @ e. None of these

B

Which type of member function may only be called from a function that is a member of the same class? a. public b. private c. global d. local e. None of these

B

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

A(n) __________ is a special function that is called whenever a new object is created and initialized with another object's data. a. static function b. destructor c. copy constructor d. assignment function e. None of these

C

An ___________ operator can work with programmer-defined data types. a. inline b. unconditional c. overloaded d. undefined e. None of these

C

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(); e. None of these

C

Assuming that Rectangle is a class name, what can you say is true, given the following statement? Rectangle *BoxPtr; a. The statement declares an object of the class Rectangle. b. The statement assigns the value of *BoxPtr to the object Rectangle. c. The statement defines a Rectangle pointer variable named *BoxPtr. d. The statement is illegal in C++. e. None of these

C

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

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

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

In C++11 you can use __________ to initialize a member variable in its declaration statement. a. general member initialization b. default initialization c. in-place initialization d. initialization overload e. None of these

C

In the following function header, the word int is known as a(n) __________. FeetInches FeetInches::operator++(int) a. parameterless data type b. incomplete argument c. dummy parameter d. incomplete parameter e. None of these

C

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

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

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 there is no output. b. 0 c. Hello! d. the program will not compile

C

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

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. name of the first object c. class name, followed by the scope resolution operator d. private access specifier e. None of these

C

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

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. referenced e. None of these

C

Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once? a. #include b. #guard c. #ifndef d. #endif e. None of these

C

Which of the following is automatically called when an object is destroyed? a. the constructor function b. the specification deallocator c. the destructor function d. the destruction function e. None of these

C

If you do not furnish a __________, a default one will be provided by the compiler. a. constructor b. destructor c. copy constructor d. All of these e. None of these

D

In C++11 reference variables that can refer only to temporary objects that would otherwise have no name are called __________ and are declared with a __________. a. rvalues, ampersand (&) b. lvalues, ampersand (&) c. lvalues, double ampersand (&&) d. rvalues, double ampersand (&&) e. None of these

D

In OOP terminology, an object's member variables are often called its __________ and its member functions can be referred to as its behaviors or its __________. a. values, morals b. data, activities c. attributes, activities d. attributes, methods e. None of these

D

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

The __________ 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

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 there is no output. b. 77 c. 0 d. the program will not compile

D

A public data member may be declared a friend of a private function.

F

C++ permits you to overload the sizeof operator and the this pointer.

F

Class objects can be defined prior to the class declaration.

F

If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded.

F

In C++ if you overload the < operator, you must also overload the > operator.

F

In-place member initialization no longer is available in C++11.

F

More than one destructor function may be defined for a class.

F

The constructor function may not accept arguments.

F

The overloaded = operator copies data from one object to another so it is known as the overload copy operator.

F

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.

F

When you overload the << operator you must also overload the >> operator.

F

While a class's member functions may be overloaded, the constructor cannot be overloaded.

F

You can overload the conditional operator to make it function as an unconditional operator.

F

You may overload any C++ operator and you may use the operator function to define non- standard operations, such as @ or ^.

F

You must declare all data members of a class before you declare member functions.

F

You must use the private access specification for all data members of a class.

F

A move operation transfers resources from a source object to a target object.

T

A private member function is useful for tasks that are internal to the class but it is not directly called by statements outside the class.

T

A static member function does not need to be called by a specific object of the class.

T

A static member variable can be used when there are no objects of the class in existence.

T

An aggregate class's constructor can use a member initialization list to call the constructors for each of its member objects.

T

By default, when an object is assigned to another object, each member of one object is copied to its counterpart in the other object.

T

Constructor functions are often used to allocate memory that will be needed by the object.

T

Destructor functions are often used to free memory that was allocated by the object.

T

If you do not declare a destructor function, the compiler will furnish one automatically.

T

In C++11 an rvalue reference is a reference variable that can refer only to temporary objects.

T

In object-oriented programming, the object encapsulates both the data and the functions that operate on the data.

T

More than one constructor function may be defined for a class.

T

The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.

T

When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

T


Set pelajaran terkait

HA prepU ch 17 heart and neck vessels

View Set