COP3330 Exam Study

Ace your homework & exams now with Quizwiz!

There may be more than 1 a. Which of the following are vector member functions studied in this chapter? indexing, like an array, with index values 0 to size( ) -1 b. reserve(newReserve) to tell a vector to change the capacity. c. size( ) tells how many base type objects have been inserted d. a constructor that takes an int argument and constructs a vector of that many base type default constructed elements. e. push_back(baseTypeObject) puts object on the back of the vector

All of the above

A constructor is always named construct with class name attached. If the class is Foo, then the constructor name is constructFoo. True or False

False

A constructor is like a function. It can return any type value needed. True or False

False

A friend function has access only to the private members and member functions of the class (and all objects of that class) of which it is a friend. True or False

False

A function can return an array.

False

A namespace grouping requires a semicolon after the closing curly brace. True or False

False

Dangling pointers present no problem in C++. True or False

False

If we use an out of range index with a vector, there be an error message from the compiler. True or False

False

If, in a class, one uses the keyword public:, it affects only the member that immediately follows the keyword public, making this member accessible to any other function defined anywhere. True or False

False

In defining a member function whose declaration is in a class, you use the dot operator to specify that the member function being defined belongs in the class, as class foo{ public: // other members void output( ); // other members }; void foo.output( ) { /* whatever */ } True or False

False

One can use the & operator to extract the value that a pointer points to. True or False

False

Overloading a binary operator as a member requires two arguments. True Or False

False

The default copy constructor and default operator = provide deep copy. True or False

False

The scope of a using directive or using declaration is from its position in the block to the end of the program. True or False

False

There is no aggregate initialization available for structure variables. You must declare structure variables then use assignment to initialize the members. True or False

False

When an operator is overloaded as a member of a class, the first parameter listed in parentheses, is the calling object. True or False

False

size and capacity of a vector are two names for the same thing. True or False

False

Suppose the following code is embedded in an otherwise correct and complete program. Answer below the question about what version of f() is called in g(). void f(); //global namespace A { void g() { f(); //Does this call A::f()? Or the global f()? } void f();} a. The call is to the global f(); b. There are other errors that prevent the code from running. c. The call is to the namespace A version of f(), i.e., A::f(); d. There is an error. There is a conflict between the namespace f() and the global f(), so there is no call made at all

The call is to the global f();

A class can have friends that are functions as well as friend classes. True or False

True

A constructor can be called implicitly or explicitly. (Implicitly means the compiler did it for you.) In the interest of uniformity in answers, please use classA; for your examples. True or False

True

A data type is a collection of a set of values together with a set of basic operations defined on the values. True or False

True

A namespace is a collection of name definitions such as class definitions, variable definitions and function definitions used to permit the same name, or names, to be used both in a library and in your own code. True or False

True

A pointer is a variable that holds the address of some other location in memory. True or False

True

A structure can have a member whose type is another structure. True or False

True

Consider this operator overloading for class Money, modified from Display 8.1 by omitting the const modifier on the return type: Money operator+(const Money& amt1,const Money& amt2); Is the following expression legal? Money m1(17.99), m2(23.57) m3(15, 22);(m1 + m2) = m3; True or False

True

During name resolution, nested namespaces behave like nested blocks. True or False

True

In a particular file, the names from the global namespace and names from an unnamed namespace defined in the file are accesses the same way: by writing the name. True or False

True

In deep copy, pointers are followed and data and the pointer structure are duplicated. True or False

True

It is impossible to get short-circuit behavior for overloaded operator && or operator || True or False

True

Overloading a binary operator as a stand-alone function requires two arguments. True or False

True

Overloading an operator cannot change the precedence of that operator with respect to other operators. True or False

True

The following definition of the structure variables of type myStruct s and t could be made using several definitions using the structure tag. struct myStruct { int i; double d; } s, t; True or False

True

The include statement, #include looks in the system defined directory for the file, file.h. (Windows PC and Macintosh users sometimes use "folder" for what I call "directory".) True or False

True

There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new. True or False

True

When overloading an operator, you can change the behavior of the operator, making + do things that feel like multiplication, but this is unwise. True or False

True

You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the "address-of" operator, &. True or False

True

There may be more than one correct answer. When you define a C++ class so that the result is an ADT, which of the following remarks about whether to make a member variable or function public or private are correct? a. Don't make member variables public. b. Make them all public. It simplifies life and makes things more efficient to be able access members anywhere. c. Make all member functions public. d. There are some member functions that shouldn't be public, but most should be public.

a. Don't make member variables public d. There are some member functions that shouldn't be public, but most should be public.

If a class represents a date (such as July 4, 1776), then the date could reasonably be stored in a. a string for the month and two int variables b. a member variable of type double c. two member variables of type int d. three member variables of type int e. a string of characters (like "July 4, 1776")

a. a string for the month and two int variables

There may be more than one correct answer. Some of the statements about separate compilation follow. Which are correct? a. Separate files for interface and implementation enhance reuse. b. Separating interface and implementation can save considerable time. c. Separate files are a big bother. There is no compelling advantage to separate files. d. Placing client and class implementations in separate files enhances project development.

a. b. d.

There may be more than one correct answer. Which of the following array initializations are correct? a. const int SIZE =4; int x[SIZE]; b. const int SIZE =4; int x[SIZE-4]; c. int x[4] = {8, 7, 6, 5, 4}; d. int x[4] = {8, 7, 6}; e. int x[] = {8, 7, 6, 5, 4};

a. const int SIZE =4; int x[SIZE]; d. int x[4] = {8, 7, 6}; e. int x[] = {8, 7, 6, 5, 4};

There may be more than one correct answer. The Big Three consists of which three from this list? a. copy constructor b. destructor c. default constructor d. constructor with two parameters e. operator =

a. copy constructor b. destructor e. operator=

Which of these array definitions will set all the indexed variables to 0? a. int array[5] = {0}; b. int array[5]; c. int array[5] = {0,0,0,0,0}; d. int array[5] = {0,1,2,3,4}; e. int array[5] = {0,0,0};

a. int array[5] = {0}; c. int array[5] = {0,0,0,0,0}; e. int array[5] = {0,0,0};

There may be more than one correct answer. We reproduce the class Money here, in part: class Money { public: Money( ); Money(int dollars, int cents); Money(int dollars); Money(double amount); // other public membersconst Money operator+(const MoneyADD& amt2)ADD; int getCents( ) const; int getDollars( ) const; private: int dollars; int cents;//other private members}; Note that * is not overloaded in the class, but operator + is overloaded using an operator function with the following declaration: constMoneyoperator+(constMoney& amt2);The question is: Given the declarations, Money baseAmount(100, 60); // $100.60 Money fullAmount; which of the following operations are legal? a. baseAmount+baseAmount. b. BaseAmount + 25; c. 25 + BaseAmount; d. baseAmount = 2 * baseAmount;

a.baseAmount+baseAmount. b. BaseAmount + 25; c. 25 + BaseAmount;

There may be more than one correct answer. Given the definition and code fragment:int matrix[2][3];int k = 0;for(int i =0; i < 3; i++)for (int j=0, j < 4; j++)matrix[i][j] = k++; The value of matrix[0][0] is a. 2 b. 0 c. 1 d. 4 e. 3

b. 0

There may be more than 1 correct answer. Which of the following is correct regarding presence and behavior of constructor is correct. Assume that the class name is C. a. To invoke the default constructor, the syntax must be C x(); b. In spite of the fact that a constructor appears to be a member function, a constructor may not be called as if it were a member function c. A constructor is called automatically when you declare an object of class type, but any constructor can be called after declaration to set all the member variables to a known state. d. An explicit call to a constructor creates an anonymous object, which can be assigned. e. To use the declaration, C x; requires a default constructor must be present.

b. In spite of the fact that a constructor appears to be a member function, a constructor may not be called as if it were a member function c. A constructor is called automatically when you declare an object of class type, but any constructor can be called after declaration to set all the member variables to a known state. d. An explicit call to a constructor creates an anonymous object, which can be assigned. e. To use the declaration, C x; requires a default constructor must be present.

There may be more than 1 correct answer. Concerning nested classes, which of the following are true? a. The inner class must always be public b. The inner class is within the scope of the outer class. c. Qualification by the outer class name with the scope resolution operator is necessary to use the inner class outside the outer class. d. A local class can contain static members. e. You can define a class within a class.

b. The inner class is within the scope of the outer class. c. Qualification by the outer class name with the scope resolution operator is necessary to use the inner class outside the outer class. e. You can define a class within a class.

Non-static function members of a class gain access to the calling object's members by a. There is no particular mechanism, the variables just know what the calling object is and automatically refer to the calling object. b. a pointer to the calling object that is implicitly provided by the compiler. The name of this pointer is this. Members are prefixed implicitly by this->, as in this->membername. c. None of the above d. a variable called self that is an alias for the calling object. This self is used to access the members of the object.

b. a pointer to the calling object that is implicitly provided by the compiler. The name of this pointer is this. Members are prefixed implicitly by this->, as in this->membername.

There may be more than 1 correct answer. A constructor .... a. can only be used to initialize b. can do anything other method can do c. must initialize all member variables d. usually initializes all or most member variables

b. can do anything any other method can do d. usually initializes all, or most, member variables.

A member of a structure or of a class is accessed using the a. comma operator b. dot operator c. indexing operator d. ampersand operator

b. dot operator

Which of the following are correct? When a function having an array formal parameter is called, the formal array parameter ... a. refers to the array using a name that is always different from the calling program's argument. b. is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter c. names a copy of the array argument. d. refers to exactly the same array as the calling program

b. is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter

You have a program with a class that is separated into files. The implementation has been changed. Of the interface file, the implementation file and the application file, which must be recompiled? a. Only the Application? b. None of the above? c. Only the implementation? d. Some of the above? e.Only the interface?

c. Only the implementation?

There may be more than one correct answer. Suppose you have the following array declaration in a program.int yourArray[5]; Further suppose that in the implementation of C++ you are using an int that requires 4 bytes.i) When your program runs, how much memory is required for this array?ii) Suppose further that your array starts at memory location decimal 100. What will be the address of yourArray[3]?iii) If you wrote to the (illegal) index 7 position in yourArray to what address would this clobber? a. The purpose of a high level language is to insulate the programmer from these details. It isn't possible to know this without probing the source to the operating system and the compiler, or extensive debugging. b. The array takes 10 bytes, ii) yourArray[3] will be an int located at Address 106. iii) writing to yourArray[7] will clobber an int starting at location 114 c. The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128 d. The array takes 5 bytes, ii) yourArray[3] will be an int located at Address 103. iii) writing to yourArray[7] will clobber an int starting at location 107.

c. The array takes 20 bytes, ii) yourArray[3] will be an int located at Address 112 iii) writing to yourArray[7] will clobber an int starting at location 128

There may be more than one correct answer. C++ allows the programmer to deal with data at a higher level of abstraction in part because related data of differing types can be treated as a unit in a. an array variable b. a function c. a structure variable d. a class variable

c. a structure variable d. a class variable


Related study sets

MGMT 340 Organizational Behavior, 16e (Robbins/Judge) Chapter 2 Diversity in Organizations

View Set

BIOLOGY: LIFE IN THE NATURAL WORLD

View Set

Chapter 6: Gross Anatomy of Muscles

View Set

MS-900 Microsoft 365 Fundamentals

View Set

Medical Terminology Chapter 9 Urinary System

View Set

Business Ethics midterm (mod. 3)

View Set

Chapter 16: Warrantless Searches

View Set

Financial Accounting Exam 2 - TF/MC

View Set