CSIS 112 - Final Exam v2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is false? 1. A string can be defined to store any data type. 2. Class string provides bounds checking in its member function at. 3. Class string's overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context. 4. An exception is thrown if the argument to string's at member function is an invalid subscript.

1. A string can be defined to store any data type.

Which statement about operator overloading is false? 1. New operators can never be created. 2. Certain overloaded operators can change the number of arguments they take. 3. The precedence of an operator cannot be changed by overloading. 4. Overloading cannot change how an operator works on built-in types.

2. Certain overloaded operators can change the number of arguments they take.

To prevent class objects from being copied: 1. Make the overloaded assignment operator private. 2. Make the copy constructor private. 3. Both Make the overloaded assignment operator private and Make the copy constructor private. 4. None of these.

3. Both Make the overloaded assignment operator private and Make the copy constructor private.

Which of the following is false? 1. 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. 2. 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. 3. It's not possible to pass a list initializer to a constructor. 4. Both 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 and It's not possible to pass a list initializer to a constructor.

3. It's not possible to pass a list initializer to a constructor.

Which of the following is false about the new operator and the object for which it allocates memory? 1. It calls the object's constructor. 2. It returns a pointer. 3. It does not require the size of the object to be explicitly specified in the new expression. 4. It automatically destroys the object after main is exited.

4. It automatically destroys the object after main is exited.

Which of the following is not a disadvantage of default memberwise copy with objects containing pointers? 1. Having the possibility of leaving a dangling pointer. 2. Allowing both objects to point to the same dynamically allocated storage. 3. Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact. 4. Requiring the explicit overloading of the assignment operator.

4. Requiring the explicit overloading of the assignment operator.

To implicitly overload the += operator: 1. Only the + operator needs to be overloaded. 2. Only the = operator needs to be overloaded. 3. Both the + and = operators need to be overloaded. 4. The += operator cannot be overloaded implicitly.

4. The += operator cannot be overloaded implicitly.

#

A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member.

+

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member.

UML

A class and its members can be described graphically using a notation known as the ____ notation.

static

A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates.

automatic

A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block.

~

A destructor has the character ____, followed by the name of the class.

accessor

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.

T

A memory leak is an unused memory space that cannot be allocated.

T

A pointer variable is a variable whose content is a memory address.

client

A program or software that uses and manipulates the objects of a class is called a(n) ____________________ of that class.

implementation file

A(n) ____________________ contains the definitions of the functions to implement the operations of an object.

mutator

A(n) ____________________ function of a class changes the values of the member variable(s) of the class.

precondition

A(n) ____________________ is a statement specifying the condition(s) that must be true before the function is called.

F

An object that is being thrown cannot be an anonymous object.

T

Both parameters of the function to overload the operator << are reference parameters.

private

By default, all members of a class are ____________________.

8

Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s).

one

How many destructors can a class have?

value

If a class object is passed by ____________________, the contents of the member variables of the actual parameter are copied into the corresponding member variables of the formal parameter.

heading

If a function of a class is static, it is declared in the class definition using the keyword static in its ____.

private

If a member of a class is ____, you cannot access it outside the class.

T

If no exception is thrown in a try block, all catch blocks associated with that try block are ignored.

.

In C++, the ____ is called the member access operator.

::

In C++, the scope resolution operator is ____.

const

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration.

deep

In a ____ copy, two or more pointers have their own data.

instance

Non-static member variables of a class are called the ____________________ variables of the class.

T

Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user-defined type and objects of the built-in type.

A) Terminate the program.

Suppose you have written a program that inputs data from a file. If the input file does not exist when the program executes, then you should choose which option? A) Terminate the program. B) Include code in the program to recover from the exception. C) Log the error and continue. D) Include code in the header file.

True

T/F? A class is an example of a structured data type.

False

T/F? As parameters to a function, class objects can be passed by reference only.

False

T/F? Given the declaration class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.x = 10;

False

T/F? If an object is created in a user program, then the object can access both the public and private members of the class.

True

T/F? If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class.

False

T/F? If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables.

True

T/F? In C++ terminology, a class object is the same as a class instance.

True

T/F? In C++, class is a reserved word and it defines only a data type.

False

T/F? The public members of a class must be declared before the private members.

False

T/F? You can use arithmetic operators to perform arithmetic operations on class objects.

address of

The ____ operator can be used to return the address of a private data member of a class.

members

The components of a class are called the ____ of the class.

assert

The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program.

friend istream& operator>>(istream&, className&);

The general syntax to overload the stream extraction operator >> for a class is ____.

interface file

The header file is also known as the ____________________.

F

The heading of a try block can contain ellipses in place of a parameter.

constructors

To guarantee that the member variables of a class are initialized, you use ____.

friend

To include the operator function operator+ as a nonmember function of the class rectangleType, its prototype in the definition of rectangleType is: ____ rectangleType operator+(const rectangleType&, const rectangleType&);

no

To overload the pre-increment (++) operator for a class, if the operator function is a member of that class, it must have ____ parameter(s).

F

Variables that are created during program execution are called static variables.

abstract data type

What does ADT stand for?

46

What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46;

F

When writing the definition of a friend function, the name of the class and the scope resolution operator precede the name of the friend function in the function heading.

nullptr

Which of the following can be used to initialize a pointer variable?

class studentType { public: void setData(string, double, int); private: string name; };

Which of the following class definitions is correct in C++? a. studentType class { public: void setData(string, double, int); private: string name; }; b. class studentType { public: void setData(string, double, int); void print() const; private: string name; double gpa; } c. class studentType { public void setData(string, double, int); private string name; }; d. class studentType { public: void setData(string, double, int); private: string name; };

C) overflow_error

Which of the following classes is derived from the class runtime_error? A) bad_alloc B) out_of_range C) overflow_error D) length_error

B) assert(divisor != 0);

Which of the following is a valid C++ statement? A) assert(0 = divisor); B) assert(divisor != 0); C) assert(divisor 0); D) assert(divisor is 0);

D) friend className operator++(className&);

Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function? A) className operator++(); B) friend className operator++(); C) className operator++(int); D) friend className operator++(className&);

C) Type& operator[](int index);

Which of the following is the syntax to declare the operator function operator[] as a member function of a class for nonconstant arrays? A) Type& []operator(int index); B) Type operator[](int index); C) Type& operator[](int index); D) Type [](int index);

By default, all members of a struct are public and all members of a class are private.

Which of the following is true about classes and structs? a. An assignment operator is allowed on class variables, but not on struct variables. b.By default, all members of a struct are public and all members of a class are private. c.A struct variable is passed by value only, and a class variable is passed by reference only. d. You cannot use the member access specifier private in a struct.

C) Log the error and continue.

Which of the following options should you choose when an exception occurs in the program that analyzes an airline's ticketing transactions? A) Terminate the program. B) Include code in the program to recover from the exception. C) Log the error and continue. D) Include code in the header file.

C) rulerType(const rulerType& myRuler)

Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType? A) rulerType(int inches, int centimeters) B) rulerType() C) rulerType(const rulerType& myRuler) D) copy rulerType(int inches, int centimeters)

In C++, you declare a pointer variable by using the ____ symbol. a. * b. @ c. # d. &

a. *

Which of the following operations is allowed on pointer variables? a. == b. % c. exp d. /

a. ==

The ____ constructor is executed when an object is declared and initialized by using the value of another object. a. copy b. class c. struct d. default

a. copy

A class ____ automatically executes whenever a class object goes out of scope. a. destructor b. constructor c. exception d. pointer

a. destructor

Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType? a. rulerType(const rulerType& myRuler) b. copy rulerType(int inches, int centimeters) c. rulerType() d. rulerType(int inches, int centimeters)

a. rulerType(const rulerType& myRuler)

n C++, ____ is called the address of operator. a. # b. & c. -> d. *

b. &

What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl; a. 81, 12 b. 12, 81 c. 81, 81 d. 12, 12

b. 12, 81 Answers:

What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46; a. 25 b. 46 c. nullptr d. 0

b. 46

The ____ operator can be used to return the address of a private data member of a class. a. dereferencing b. address of c. destructor d. member access

b. address of

An array created during the execution of a program is called a(n) ____ array. a. list b. dynamic c. execution d. static

b. dynamic

The C++ operator ____ is used to create dynamic variables. a. dynamic b. new c. virtual d. dereferencing

b. new

In a ____ copy, two or more pointers of the same type point to the same memory. Selected Answer: Incorrect Answers: a. deep b. shallow c. static d. dynamic

b. shallow

In C++, virtual functions are declared using the reserved word ____. a. struct b. virtual c. private d. public

b. virtual

What is the output of the following statements? int x = 33; int *q; q = &x; cout << *q << endl; a. nullptr b. 0 c. 33 d. 3

c. 33

What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl; a. 76, 76 b. 76, 43 c. 43, 43 d. 43, 76

c. 43, 43

Run-time binding is also known as ____ binding. a. static b. deep c. dynamic d. shallow

c. dynamic

Consider the following statement: ptrMemberVarType objectThree(objectOne); The values of the member variables of objectOne are being copied into the corresponding member variables of objectThree. This initialization is called the ____. a. member-wise assignment b. default initialization c. member-wise initialization d. default assignment

c. member-wise initialization

In ____ binding, the necessary code to call a specific function is generated by the compiler. a. dynamic b. shallow c. static d. deep

c. static

bigRect.print();

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? a. rectangleType.print(); b. rectangleType::print(); c. bigRect.print(); d. bigRect::print();

bigRect.setLengthWidth(3.0, 2.0);

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition, and the object declaration: rectangleType bigRect(14,10); Which of the following statements is correct? a. bigRect.setLengthWidth(3.0, 2.0); b. bigRect.setLengthWidth(); c. bigRect.length = 2.0; d. bigRect.length = bigRect.width;

rectangleType rectangle;

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition. Which of the following variable declarations is correct? a. class rectangleType rectangle; b. rectangle rectangleType; c. rectangle rectangleType.area; d. rectangleType rectangle;

two

class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } Consider the accompanying class and member functions definitions. How many constructors are present in the class definition?

three

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class?

clockType

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class?

const

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object.

Which of the following arithmetic operations is allowed on pointer variables? a. Division b. Modulus c. Multiplication d. Increment

d. Increment

In a ____ copy, two or more pointers have their own data. a. shallow b. dynamic c. static d. deep

d. deep

The C++ operator ____ is used to destroy dynamic variables. a. destroy b. ~ c. * d. delete

d. delete

Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s). a. one b. two c. four d. eight

d. eight

Given the declaration int *a;, the statement a = new int[50]; dynamically allocates an array of 50 components of the type ____. a. int* b. pointer c. address d. int

d. int

Which of the following can be used to initialize a pointer variable? a. '0' b. "0" c. 1 d. nullptr

d. nullptr

The code int *p; declares p to be a(n) ____ variable. a. new b. num c. address d. pointer

d. pointer


Kaugnay na mga set ng pag-aaral

Chemistry Chapter 9 Semester Study

View Set

Dental Hygiene Board Review 2018

View Set

Ch.8 - Business Markets and Buying Behaviors

View Set

Chapter 19: International Diversification

View Set