C++ Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

==

Which of the following is true about a derived class? Select one: a. A derived class can redefine any member function of the base class. b. A derived class can directly access any member variable of the base class. c. A derived class can have at most one base class. d. A derived class can redefine any public member function of the base class.

A derived class can redefine any public member function of the base class.

____ is the ability to combine data, and operations on that data, in a single unit. Select one: a. Encapsulation b. Polymorphism c. Inheritance d. Composition

Encapsulation

A derived class cannot directly access public members of a base class. Select one: True False

False

If inheritance is private, all members of the base class, including private members, become private members of the derived class. Select one: True False

False

The class io is the base class of the C++ stream classes istream and ostream. Select one: True False

False

The private members of a base class can be directly accessed by a derived class. Select one: True False

False

OOP implements ____. Select one: a. UML b. EIP c. IPE d. OOD

OOD

A call to the base class's constructor is specified in the heading of the definition of a derived class constructor. Select one: True False

True

A derived class can directly access the protected members of the base class. Select one: True False

True

In multiple inheritance, the derived class has more than one base class. Select one: True False

True

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. Select one: a. automatic b. static c. public d. local

automatic

Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? Select one: a. rectangleType::print(); b. bigRect::print(); c. rectangleType.print(); d. bigRect.print();

bigRect.print();

The statement that declares board to be an array of six pointers wherein each pointer is of type int is: int ______

board[6]

Which of the following is a valid definition of the derived class bClass? Select one: a. class bClass: public aClass { //... }; b. class bClass::aClass { //... } c. class aClass::bClass { //... }; d. class aClass: public bClass { //... };

class bClass: public aClass { //... };

Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass? Select one: a. class dClass:: protected bClass { //classMembersList }; b. class dClass: private bClass { //classMembersList }; c. class bClass: public dClass { //classMembersList }; d. class dClass:: public bClass { //classMembersList };

class dClass: private bClass { //classMembersList };

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

copy

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

destructor

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

eight

Classes can create new classes from existing classes. This important feature ____. Select one: a. provides public access to the internal state of an object b. results in more software complexity c. encourages code reuse d. aids the separation of data and operations

encourages code reuse

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

increment

The header file is also known as the______

interface fine

Inheritance is an example of a(n) ____ relationship. Select one: a.has-a b.handshaking c.is-a d.had-a

is-a

The components of a class are called the ____ of the class. Select one: a. properties b. objects c. members d. elements

members

How many destructors can a class have? Select one: a. any number b. no explicit destructors c. two d. one

one

If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class. Select one: a. overloaded b. reused c. redefined d. overridden

overloaded

If a member of a class is ____, you cannot access it outside the class. Select one: a. automatic b. public c. private d. static

private

The ____ members of an object form its internal state. Select one: a.static b.protected c.private d.public

private

The constructor of a derived class cannot directly access the _________ member variables of the base class.

private

The ____ members of an object form its external state. Select one: a. public b. private c. protected d. static

public

To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. Select one: a. rename b. redefine c. reuse d. overload

redefine

Consider the following statements: class shape { public: virtual void draw() = 0; virtual void move(double x, double y) = 0; . . . }; The code above is an example of a(n) __________ class definition.

reference

Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter p is a(n) _________ parameter.

reference

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

shallow

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

static

Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? Select one: a. three b. none c. zero d. two

three

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

virtual

The _________ of a base class automatically makes the destructor of a derived class virtual.

virtual destructor

Consider the following class definitions: class bClass { public: void setX(int); void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int, int); void print() const; private: int y; }; Which of the following statements correctly redefines the member function print of bClass? Select one: a. void dClass::print() const { dClass:print(); cout << " " << y << endl; } b. void bClass::print() const { cout << x << " " << y << endl; } c. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } d. void dClass::print() const { cout << x << " " << y << endl; }

void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }

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

12, 81

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

33

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

43, 43

____ is a "has-a" relationship. Select one: a. Inheritance b. Composition c. Encapsulation d. Polymorphism

Composition

In protected inheritance, public and protected members of the base class become the protected members of the derived class. Select one: True False

True

Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass? Select one: a. class bClass: aClass { //... }; b. class bClass: public aClass { //... }; c. class aClass: bClass { //... }; d. class aClass: public bClass { //... };

class bClass: public aClass { //... };

Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class? Select one: a. +clockType b. clockType c. clock d. Type

clockType

If a function of a class is static, it is declared in the class definition using the keyword static in its ____. Select one: a. heading b. return type c. main function d. parameters

heading

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

instance

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

int

The statement int *p; is equivalent to int * p;, which is also equivalent to the statement ________ .

int p;

In OOD, a program is a collection of interacting ____________ ; in structured programming, a program is a collection of interacting functions.

objects

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

precondition

If inheritance is public, all protected members of the base class are _______ members of the derived class

protected

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? Select one: a. none b. two c. one d. three

two

Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter q is a(n) ______ parameter.

value

In C++, the ____ is called the member access operator. Select one: a. , b. . c. # d. ::

.

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

46

If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list. Select one: True False

True

The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class. Select one: True False

True

A class and its members can be described graphically using a notation known as the ____ notation. Select one: a. UML b. OOP c. OOD d. OON

UML

Existing classes, from which you create new classes, are called ____ classes. Select one: a. derived b. base c. sibling d. child

base

Consider the following class definitions: class bClass { public: void set(double a, double b); //Postcondition: x = a; y = b; void print() const; bClass(); //Postcondition: x = 0; y = 0; bClass(double a, double b); //Postcondition: x = a; y = b; private: double x; double y; }; class dClass: public bClass { public: void set(double a, double b, double c); //Postcondition: x = a; y = b; z = c; void print() const; dClass(); //Postcondition: x = 0; y = 0; z = 0 ; dClass(double a, double b, double c); //Postcondition: x = a; y = b; z = c; private: double z; }; Which of the following dClass constructor definitions is valid in C++? Select one: a. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; } b. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } c. dClass::dClass(double a, double c) { x = a; z = c; } d. dClass::dClass(double a, double b) : bClass() { x = a; y = b; }

dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

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

deep

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

delete

Question text The new classes that we create from existing classes are called ____ classes. Select one: a. parent b. base c. derived d. sibling

derived

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

dynamic

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

dynamic

Consider the accompanying class definition. Which of the following variable declarations is correct? Select one: a. class rectangleType rectangle; b. rectangleType rectangle; c. rectangle rectangleType.area; d. rectangle rectangleType;

rectangle rectangleType;

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

rulerType(const rulerType& myRuler)

Question text The binding of virtual functions occurs at program _______ time.

run

A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member. Select one: a. + b. $ c. - d. #

#

The preprocessor directive _________ is used to prevent multiple inclusions of a header file in a program.

#ifndef

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

&

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

*

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. Select one: a. + b. $ c. - d. #

+

What is the output of the following program? #include <iostream> using namespace std; class bClass { public: void print() const; bClass(int a = 0, int b = 0); //Postcondition: x = a; y = b; private: int x; int y; }; class dClass: public bClass { public: void print() const; dClass(int a = 0, int b = 0, int c = 0); //Postcondition: x = a; y = b; z = c; private: int z; }; int main() { bClass bObject(2, 3); dClass dObject(3, 5, 8); bObject.print(); cout << endl; dObject.print(); cout << endl; return 0 ; } void bClass::print() const { cout << x << " " << y << endl; } bClass::bClass(int a, int b) { x = a; y = b; } void dClass::print() const { bClass:print(); cout << " " << z << endl; } dClass::dClass(int a, int b, int c) : bClass(a, b) { z = c; } Select one: a. 3 5 8 3 5 8 b. 2 3 2 3 c. 5 8 3 5 8 d. 2 3 3 5 8

2 3 3 5 8

Which of the following is true about classes and structs? Select one: 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.

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

Which of the following is true about inheritance? Select one: a. All public member functions of the base class become the public member functions of the derived class. b. All public member variables of the base class become the public member variables of the derived class. c. The public member variables of the base class become the public or private member variables of the derived class. d. All public members of the base class become the public members of the derived class.

The public member variables of the base class become the public or private member variables of the derived class.

Which of the following statements about inheritance is true if memberAccessSpecifier is protected? Select one: a. The protected members of the base class become private members of the derived class. b. The private members of the base class become protected members of the derived class. c. The public members of the base class become protected members of the derived class. d. The derived class can directly access any member of the base class.

The public members of the base class become protected members of the derived class.

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function. Select one: a. constructor b. mutator c. destructor d. accessor

accessor

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

address of

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

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

If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class you use the statement ____. Select one: a. classD.functionName(); b. classD::functionName(); c. classB::functionName(); d. classB.functionName();

classB::functionName();

In___________ (aggregation), one or more members of a class are objects of another class type.

composition

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. Select one: a. static b. automatic c. private d. const

const

To guarantee that the member variables of a class are initialized, you use ____. Select one: a. constructors b. mutators c. accessors d. destructor

constructors

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

implementation file

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 ____. Select one: a. default initialization b. default assignment c. member-wise assignment d. member-wise initialization

member-wise initialization

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

mutator

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

new

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

nullptr

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

pointer

____ is the ability to use the same expression to denote different operations. Select one: a. Inheritance b. Encapsulation c. Composition d. Polymorphism

polymorphism

By default, all members of a class are _________

private

Consider the following class definition: class dClass: bClass { //class members list }; The class dClass is derived from the class bClass using the ____ type of inheritance. Select one: a. static b. private c. public d. protected

private

Consider the following declaration of a struct: struct studentType { char name[26]; double gpa; int sID; char grade; }; studentType student; studentType *studentPtr; The statement (*studentPtr).gpa = 2.5; is equivalent to ______ = 2.5;.

studentPtr->gpa

The copy constructor automatically executes when, as a parameter, an object is passed by ______

value

C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. Select one: a. overloaded b. redefined c. overridden d. virtual

virtual

C++ provides ________ functions as a means to implement polymorphism in an inheritance hierarchy.

virtual

Consider the following class definitions: class bClass { public: void setX(int a); //Postcondition: x = a; void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int a, int b); //Postcondition: x = a; y = b; void print() const; private: int y; }; Which of the following correctly sets the values of x and y? Select one: a. void dClass::setXY(int a, int b) { x = a; y = b; } b. void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; } c. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } d. void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); }

void dClass::setXY(int a, int b) { bClass::setX(a); y = b; }


Ensembles d'études connexes

GCSE History - how to answer 4, 6 and 10 mark questions

View Set