Exam 2

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

c) &t[3]

assuming that i is an array and tPtr is a pointer to that array, which expression refers to the address of element 3 of the array? a) *(tPtr+3) b) tPtr[3] c) &t[3] d) *(t+3)

c) sort(begin(values), end(values));

given a built-in array of ints named values, which of the following statements would sort the array? c) sort(begin(values), end(values));

d) All the public and protected members of class Circle are inherited as public and protected members, respectively, into class Point.

Assuming the definition, class Circle : public Point which of the following is false? a) The keyword public indicates the type of inheritance. b) The colon ( : ) in the header of the class definition indicates inheritance. c) Point is the base class and Circle is the derived class. d) All the public and protected members of class Circle are inherited as public and protected members, respectively, into class Point.

b) Test * const

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

line 12

Given the following class declaration: line 1 class Widget { line 2 public: line 3 int x[50]; line 4 Widget (); line 5 Widget (int a, int b, int c); line 6 Widget (float a); line 7 int GetValue() const; line 8 int y; line 9 void SetValue(int Value); line 10 private: line 11 TimeType z; line 12 int PutValue(int Value); line 13 }; Identify the private member functions in the class Widget. (Mark all that apply.)

-3

Given the following code: int x = 4; int y = 5; int n; int * p; int *q; p = &x; q = &y; p = q; n = -1; *p = n; *q = n + *p + *q; Question: What is *p equal to? the value...

b) The President

If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class? a) Age. b) The President. c) Place of birth. d) Favorite food

a) In any order and multiple times.

Member access specifiers (public and private) can appear: a) In any order and multiple times. b) In any order (public first or private first) but not multiple times. c) In any order and multiple times, if they have brackets separating each type. d) Outside a class definition

b) Require the scope resolution operator only when being defined outside of the definition of their class.

Member function definitions: a) Always require the scope resolution operator (::). b) Require the scope resolution operator only when being defined outside of the definition of their class. c) Can use the scope resolution operator anywhere, but become public functions. d) Must use the scope resolution operator in their function prototype.

a) Base classes are usually more specific than derived classes.

Select the false statement regarding inheritance. a) Base classes are usually more specific than derived classes. b) A derived class can contain more attributes and behaviors than its base class. c) Some derived classes can have multiple base classes. d) A derived class can be the base class for other derived classes.

a) operator+

The correct function name for overloading the addition (+) operator is: a) operator+ b) operator(+) c) operator:+ d) operator_+

inheritance

The is-a relationship represents

a) class subclass : private superClass

To declare class subClass a privately derived class of superClass one would write: a) class subclass : private superClass b) class subclass :: private superClass c) class subclass <private superClass> d) class subclass inherits private superClass

an endless loop occurs

What is the output of the following program? #include <iostream> using namespace std; int main() { int Set[8] = { 5, 10, 15, 20, 25, 30, 35, 40 }; int *Nums = Set; while ( Nums < &Set[7] ) { Nums--; cout << *Nums << " " ; } return 0; }

a) Base class, base class.

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.

c) protected, protected.

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.

only public

Which forms of inheritance are is-a relationships? a) All forms of inheritance are is-a relationships. b) Only public and protected. c) Only public and private. d) Only public.

c) sizeof r / sizeof (int)

Which of the following gives the number of elements in the array int r[10]? a) sizeof r b) sizeof (*r) c) sizeof r / sizeof (int) d) sizeof (*r) / sizeof (int)

b) Prime numbers.

Which of the following is not a good example of a hierarchy that could be modeled by inheritance? a) Animals. b) Prime numbers. c) Geometric shapes. d) Airplanes.

a) Time::operator double() const;

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;

a) The . operator.

Which of the following operators cannot be overloaded? a) The . operator. b) The -> operator. c) The & operator. d) The [ ] operator.

c) You must explicitly delete the memory that's managed by a unique_ptr before the object goes out of scope

Which of the following statements about a unique_ptr object is false? 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

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

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.

possible using public functions and references

a client changing the values of private data members is:

both a and b

a default constructor:

a nonconstant pointer to nonconstant data

a function that modifies an array by usning pointer arithmetic such as ++ptr to process every value of the array should have a parameter that

a pointer of a type other than its own type and void without using the cast operator

a pointer can not be assigned to:

without using the cast operator

a pointer can not be assignment to: a pointer of a type other than its own type and void...

t.a().b().d();

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 as a syntax error:

a) contain at most one pure virtual function

abstract classes: a) contain at most one pure virtual function b) can have objects instantiated from them if the proper permissions are set c) cannot have abstract derived classes d) are defined, but the programmer never intends to instantiate any objects from them

d) dereferencing a variable that is not a pointer

all of the following can cause a fatal execution-time error except: a) dereferencing a pointer that has not ben assigned to point to a specific address b) dereferencing a pointer that has not been initialized properly c) dereferencing a null pointer d) dereferencing a variable that is not a pointer

d) an object data member is not initialized in the member initialization list and does not have a default consctructor

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 consctructor

the postfix increment operator typically returns a temp object that contains the original value of the object before the increment occured

because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference

a) are not inherited by derived classes

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

\n

cin.getline(superstring, 30);is equivalent to which of the following? cin.getline(superstring, 30, '\n');

they point to elements of the same array

comparing pointers and performing pointer arithmetric on them is meaningless unless:

can convert between user defined types

conversion constructors:

gets a copy of every member variable

every object fo the same class:

binary operators can have one argument, and unary operators cannot have any

for operators overloaded as non-static member functions:

*this.x

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) Functions that are neither friends of the base class, derived-class member functions nor friends of a derived class.

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 derived classes. c) friends of the base class. d) Functions that are not derived-class member functions.

until explicitly set to a different setting

parameterized stream manipulator setfill specifies that fill character that's displayed when an output is displayed in a field wider than the number of characters or digits in the output. the effect of setfille applies:

b)

pointers cannot be used to: a) contain memory addresses b) reference values directly c) pass an argument by reference d) manipulate dynamic data structures

b) virtual functions and dynamic binding

polymorphism is implemented via: a) member functions b) virtual functions and dynamic binding c) inline functions d) non-virtual functions

c) allows private member variables to be modified, thus "breaking encapsulation"

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

d) returns the total number of bytes in a variable

sizeof: a) is a binary operator b) returns the total number of elements in an array c) usually returns a double d) returns the total number of bytes in a variable

s.operator!()

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 fnds the expression is?

ostream& operator<<(ostream& output, const Data& dataToPrint)

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 time of the function definition would be:

lvalues

the & operator can be applied to:

take multiple values inside (e.g., [4,8])

the array subscript operator [], when overloaded, cannot:

b) copy data from one object to another

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

b) have virtual functions

the c++ compiler makes objects take up more space in memory if they: a) are derived from base classes b) have virtual functions c) have only protected members d) are referenced by pointers

a) count must be a non-const variable

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

*ptr

three of the following expressions have the same value. which of the following expressions has a value different from the others'?

c) *ptr

three of the following expressions have the same value. which of the following expressions has a value different from the others'? a) *&ptr b) &*ptr c) *ptr d) ptr

block scope

variables defined inside a member function of a class have:

d) a constant pointer to constant data

what method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation a) a nonconstant pointer to nonconstant data b) a nonconstant pointer to constant data c) a constant pointer to nonconstant data d) a constant pointer to constant data

int*a

when a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

c) int *a

when a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to: a) int a b) int &a c) int *a

c) when these member should be available only to derived classes ( and friends), but not to other clients

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 member should be available only to derived classes ( and friends), but not to other clients d) the protected access specified should never be used

n is a constant pointer to nonconstant data

which of the following best describes the array name n in the delcaration int n[10];?

++

which of the following can have a pointer as an operand?

a) it always knows the size of the built-in array that is being passed

which of the following is false about a function to which a built-in array is being passed? a) it always knows the size of the built-in array that is being passed

c++ ensures that you cannot "walk off" either end of an array

which of the following is false?

int n[5]{0, 7, 0, 3, 8, 2};

which of the following is not a correct way to initialize a built-in array?

requiring the explicit overloading of the assignment operator

which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

static

which of the following is not a kind of inheritance in c++?

d) by value with pointer arguments

which of the following is not a valid way to pass arguments to a function in c++? a) by reference with reference arguments b) by value c) by reference with pointer arguments d) by value with pointer arguments

a) objects of abstract classes

which of the following is not allowed? a) objects of abstract classes b) multiple pure virtual functions in a single abstract class c) references to abstract classes d) arrays of pointers to abstract classes

d) all of the above are disadvantages of the "copy and paste" approach

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

a) a class can either grant friendship to or take friendship from another class using the friend keyword

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

d) flapWings

which of the following would not be a member function that derived classes Fish, Frog and Bird should inherit from the base call 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

certain overloaded operators can change the number of arguments they take

which statement about operator overloading is false?


Kaugnay na mga set ng pag-aaral

Behavior and the Brain Chapter 1-5

View Set

Smartbook Pre-Topic Readings Topic 2a Blood

View Set

med surg chapter 66 caring for clients with burns

View Set

Social Class & Mobility (Exam #2)

View Set

AIC 30 - Assignment 5 Practice Test

View Set