CSCN 112 Exam 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

The rand function generates a data value of the type: a. unsigned int. b. int. c. long int. d. short int.

NOT a. unsigned int.

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? a. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } b. void dClass::setXY(int a, int b) { x = a; y = b; } c. void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); } d .void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; }

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

Given the following function: int strange(int x, int y) { if (x > y)return x + y;else return x - y; } what is the output of the following statement?cout << strange(4, 5) << endl; a. -1 b. 1 c. 9 d. 20

a. -1

A default constructor has how many parameters? a. 0. b. 1. c. 2. d. Variable number.

a. 0.

Consider the following definition of a recursive function. int puzzle(int start, int end) { if (start > end) return start - end; else if (start == end) return start + end; else return end * puzzle(start + 1, end - 1); } What is the output of the following statement?cout << puzzle(5, 10) << endl; a. 720 b. 5040 c. 5760 d. 10800

a. 720

A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by: a. :: b. : c. . d. ->

a. ::

To use the predefined function tolower, the program must include the header file ____. a. <cctype> b.<iostream> c. <cmath> d.<cstdlib>

a. <cctype>

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.

a. Are not inherited by derived classes.

Utility functions: a. Are private member functions that support operations of the class's other member functions. b. Are part of a class's interface. c. Are intended to be used by clients of a class. d. Are a type of constructor.

a. Are private member functions that support operations of the class's other member functions.

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.

a. Base class, base class.

Which of the following is true about using inheritance in software engineering? a. Common attributes and behaviors should be factored out of closely related classes and placed into a base class from which the original classes can now inherit. b. It is best to create a huge class library to make it easy for a client to find the most appropriate class for his or her needs. c. A class produced through inheritance should be as large as possible to fully encompass all of the functionality it should offer. d. The standard C++ libraries that are shipped with C++ compilers are usually enough to accomplish anything an application might need to do.

a. Common attributes and behaviors should be factored out of closely related classes and placed into a base class from which the original classes can now inherit.

Overloaded functions must have: a. Different parameter lists. b. Different return types. c. The same number of parameters. d. The same number of default arguments.

a. Different parameter lists.

Assuming the following is the beginning of the constructor definition for class BasePlusCommissionEmployee which inherits from class CommissionEmployee BasePlusCommissionEmployee:: BasePlusCommissionEmployee ( string first, string last, string ssn, double sales, double rate, double salary ) : CommissionEmployee( first, last, ssn, sales, rate) The line following the single colon(:) a. Invokes the CommissionEmployee constructor with arguments. b. Causes a compiler error. c. Is unnecessary because the CommissionEmployee constructor is called automatically. d. Indicates composition.

a. Invokes the CommissionEmployee constructor with arguments.

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

a. accessor

Which of the following is most likely a base class of the other three? a. automobile. b. convertible. c. miniVan. d. sedan.

a. automobile.

In order to apply a(n) ____________________ search, the list must be sorted. a. binary b. selection c. sequential d. insertion

a. binary

Which of the following class definitions is correct in C++? a. class studentType { 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. studentType class { public: void setData(string, double, int); private: string name; };

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

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

a. class subclass : private superClass

Given the class definition: class CreateDestroy { public: CreateDestroy() {cout << "constructor called."; } ~CreateDestroy() { cout << "destructor called.";} }; What will the following program output? int main() { for ( int i = 1; i <= 2; ++i ) CreateDestroy cd; return 0; } a. constructor called, destructor called, constructor called, destructor called, b. constructor called, constructor called, c. constructor called, constructor called, destructor called, destructor called, d. Nothing.

a. constructor called, destructor called, constructor called, destructor called,

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.

a. count must be a non- const variable.

A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates. a. static b. automatic c. local d. public

a. static

If the search item is the 900th item in the list, the sequential search makes ____ key comparisons to determine whether the search item is in the list. a. 100 b. 900 c. 9000 d. 90000

b. 900

In C++, the scope resolution operator is ____. a. : b. :: c. $ d. .

b. ::

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

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

The inline keyword: a. Increases function-call overhead. b. Can reduce a function's execution time but increase program size. c. Can decrease program size but increase the function's execution time. d. Should be used with all frequently used functions.

b. Can reduce a function's execution time but increase program size.

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

b. Encapsulation

The is-a relationship represents: a. Composition. b. Inheritance. c. Information hiding. d. A friend

b. Inheritance.

Recursion is memory-intensive because: a. Recursive functions tend to declare many local variables. b. Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack. c. Many copies of the function code are created. d. It requires large data values

b. Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack.

Theoretically, clients do not need to see the ________ of classes from which they derive other classes. a. Header files b. Source code c. Object code d. Interface .

b. Source code

Consider the following definition of a recursive function. int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else //Line 5 return n + foo(n - 1); //Line 6} Which of the statements represents the base case? a. Statements in Lines 1-6. b. Statements in Lines 3 and 4. c. Statements in Lines 5 and 6 d. Statements in Lines 3, 4, and 5.

b. Statements in Lines 3 and 4.

Which of the following statements is false? a. You can overload a classes constructors. b. There is no mechanism in C++ for a constructor to call another constructor in the same class. c. Just as a constructor can call a class's other member functions to perform tasks, C++ allows constructors to call other constructors in the same class. d. To overload a constructor, provide in the class definition a prototype for each version of the constructor, and provide a separate constructor definition for each overloaded version.

b. There is no mechanism in C++ for a constructor to call another constructor in the same class.

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

b. automatic

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 above class definition and the following object declaration: rectangleType bigRect(14,10); Which of the following statements is correct? a. bigRect.setLengthWidth(); b. bigRect.setLengthWidth(3.0, 2.0); c. bigRect.length = 2.0; d. bigRect.length = bigRect.width;

b. bigRect.setLengthWidth(3.0, 2.0);

The sequential search algorithm uses a(n) ____ variable to track whether the item is found. a. int b. bool c. char d. double

b. bool

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 ____. a. classD::functionName(); b. classB::functionName(); c. classD.functionName(); d. classB.functionName();

b. classB::functionName();

From most restrictive to least restrictive, the access modifiers are: a. protected, private, public b. private, protected, public c. private, public, protected d. protected, public, private

b. private, protected, public

Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function. a. value b. reference c. constant d. global

b. reference

After the second iteration of bubble sort for a list of length n, the last ____ are sorted. a. element b. two elements c. three elements d. n-2

b. two elements

The statement ____ creates the vector object vecList of size size. a. vector[elemType] vecList(size); b. vector<elemType> vecList(size); c. vector(size) vecList<elementType> d. vector{elemType::size} vecList;

b. vector<elemType> vecList(size);

Which statement declares intList to be a vector of size 5 and the element to be of type int? a. vector intList[5]; b. vector<int> intList(5); c. vector<int> intList(); d. vector(int) intList[5];

b. vector<int> intList(5);

Assuming that GradeBook.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file? a. #include <iostream> b. #include "iostream" c. #include <GradeBook.h> d. #include "GradeBook.h"

c. #include <GradeBook.h>

The formula to find the index of the middle element of a list is ____. a. (mid + last)/2 b. (first + last) - 2 c. (first + last) / 2 d. (first + mid ) * 2

c. (first + last) / 2

Consider the following definition of the recursive function mystery. int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Given the declaration: int alpha[5] = {1, 4, 5, 8, 9}; what is the output of the following statement? cout << mystery(alpha, 0, 4) << endl; a. 1 b. 18 c. 27 d. 35

c. 27

Consider the following list: int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search, the element to be found is first compared with ____. a. 4 b. 25 c. 39 d. 95

c. 39

Assuming the following pseudocode for the Fibonacci series, what is the value of the 5th Fibonacci number ( fibonacci ( 5 ))? fibonacci( 0 ) = 0 fibonacci( 1 ) = 1 fibonacci( n ) = fibonacci( n - 1 ) + fibonacci( n - 2 ) a. 1 b. 3 c. 5 d. 7

c. 5

Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement?cout << next(next(5)) << endl; a. 5 b. 6 c. 7 d. 8

c. 7

Variables defined inside a member function of a class have: a. File scope. b. Class scope. c. Block scope. d. Class or block scope, depending on whether the binary scope resolution operator ( ::) is used.

c. Block scope.

A recursive function is a function that: a. Returns a double. b. Takes 3 arguments. c. Calls itself, directly or indirectly. d. Is inside of another function.

c. Calls itself, directly or indirectly.

Attributes of a class are also known as: a. Constructors b. Local variables c. Data members d. Classes.

c. Data members

Which of the following statements will not produce a syntax error? a. Defining a const member function that modifies a data member of the object. b. Invoking a non- const member function on a const object. c. Declaring an object to be const. d. Declaring a constructor to be const.

c. Declaring an object to be const.

Recursion is to the base case as iteration is to what: a. The counter. b. A repetition structure. c. Failure of the loop continuation test. d. A selection structure.

c. Failure of the loop continuation test.

Which of the following is true of function templates? a. All function templates begin with the keyword class. b. Every formal type parameter is preceded by either keyword typename or template. c. Formal type parameters act as placeholders for built-in types or user-defined types and are used to specify the types of arguments to the function, to specify the return type of the function, and to declare variables within the body of the function definition. d. A programmer must define a separate function template for each template function specialization to be used in the program.

c. Formal type parameters act as placeholders for built-in types or user-defined types and are used to specify the types of arguments to the function, to specify the return type of the function, and to declare variables within the body of the function definition.

When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client's code during the: a. Programming phase. b. Compiling phase. c. Linking phase. d. Executing phase.

c. Linking phase.

When composition (one object having another object as a member) is used: a. The host object is constructed first and then the member objects are placed into it. b. Member objects are constructed first, in the order they appear in the host constructor's initializer list. c. Member objects are constructed first, in the order they are declared in the host's class. d. Member objects are destructed last, in the order they are declared in the host's class.

c. Member objects are constructed first, in the order they are declared in the host's class.

What type of member functions allow a client of a class to assign values to private data members? a. Client member functions. b. Get member functions. c. Set member functions. d. None of these.

c. Set member functions

The compiler will implicitly create a default constructor if: a. The class does not contain any data members. b. The programmer specifically requests that the compiler do so. c. The class does not define any constructors. d. The class already defines a default constructor.

c. The class does not define any constructors.

Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call? a. Types and order of the arguments in the function call. b. The number of arguments in the function call. c. The return type of the function. d. It examines All of these.

c. The return type of the function.

If the function int volume( int x = 1, int y = 1, int z = 1 ); is called by the expression volume( 3 ), how many default arguments are used? a. None. b. One. c. Two. d. Three.

c. Two.

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

c. When these members should be available only to derived classes (and friends), but not to other clients.

Given the following function prototype: ​int test(float, char); ​which of the following statements is valid? a. cout << test(12, &); b. cout << test("12.0", '&'); c. int u = test(5.0, '*'); d. cout << test('12', '&');

c. int u = test(5.0, '*');

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

c. private

Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d. protected.

c. static.

If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values. a. int b. array c. void d. reference

c. void

In the expression n = x + rand() % y; a. y is the shifting value. b. x is the scaling value. c. y is the scaling value. d. Both y is the shifting value and x is the scaling value.

c. y is the scaling value.

Consider the following definition of a recursive function. int recFunc(int num) { if (num >= 10) return 10; else return num * recFunc(num + 1); } What is the output of the following statement? cout << recFunc(8) << endl; a. 4 b. 8 c. 72 d. 720

d. 720

A constructor can specify the return type: a. int. b. string. c. void. d. A constructor cannot specify a return type.

d. A constructor cannot specify a return type.

Which of the following is not true of class template vector? a. The size of a vector can be changed after it is declared. b. A vector can be assigned to another vector by using the assignment operator. c. A vector object can be initialized with a copy of another vector by invoking the copy constructor. d. A vector can store only data of type int.

d. A vector can store only data of type int.

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 these are disadvantages of the "copy-and-paste" approach.

d. All of these are disadvantages of the "copy-and-paste" approach.

When compiling a class's source code file (which does not contain a main function), the information in the class's header file is used for all of the following, except: a. Ensuring that the header of each member function matches its prototype. b. Ensuring that each member function knows about the class's data members and other member functions. c. Determining the correct amount of memory to allocate for each object of the class. d. All of these are uses that the compiler has for the header file information.

d. All of these are uses that the compiler has for the header file information.

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 constructor.

d. An object data member is not initialized in the member initialization list and does not have a default constructor.

Linear search can be used on: a. Unsorted arrays. b. Sorted arrays. c. Integer arrays. d. Any of these.

d. Any of these.

Linear search can be used on: a. Unsorted arrays b. Sorted arrays c. Integer arrays d. Any of these.

d. Any of these.

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

d. Base classes are usually more specific than derived classes.

In regards to default arguments, which of the following is false? a. When an argument is omitted in a function call, the default value of that argument is automatically inserted by the compiler and passed in the function call. b. They must be the rightmost (trailing) arguments in a function's parameter list. c. Default values can be constants. d. Default values cannot be global variables or function calls.

d. Default values cannot be global variables or function calls.

If a set of functions have the same program logic and operations and differ only in the data type(s) each receives as argument(s) then a(n) ________ should be used. a. Overloaded function b. Recursive function c. Macro d. Function template

d. Function template

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

d. Prime numbers.

Which of the following is not included in a function's activation record? a. The return address of its caller function b. Parameter values received from its caller c. Local variables it has declared d. The name of the function

d. The name of the function

Given the class definition:class CreateDestroy { public: CreateDestroy() {cout << "constructor called."; } ~CreateDestroy() { cout << "destructor called."; } }; What will the following program output? int main() { CreateDestroy c1; CreateDestroy c2; return 0; } a. constructor called, destructor called, constructor called, destructor called, b. constructor called, destructor called, c. constructor called, constructor called, d. constructor called, constructor called, destructor called, destructor called,

d. constructor called, constructor called, destructor called, destructor called,

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++? a. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } b. dClass::dClass(double a, double c) { x = a; z = c; } c. dClass::dClass(double a, double b) : bClass() { x = a; y = b; } d. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

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

Consider the following list. int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search for 75, after the first comparison, the search is restricted to ____. a. list[0]...list[6] b. list[0]...list[7] c. list[5]...list[11] d. list[6]...list[11]

d. list[6]...list[11]

The type vector provides the expression ____________________, which inserts a copy of elem into vecList at the end. a. front b. push c. pop d. push_back

d. push_back

In the bubble sort algorithm, which code accomplishes swapping values in elements at positions index and index + 1? a. list[index] = list[index + 1] list[index + 1] = list[index] b. list[index + 1] = list[index] list[index] = list[index + 1] c. list[index] = temp; list[index] = list[index + 1]; temp = list[index + 1]; d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;

d. temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp;

Which statement declares intList to be an empty vector? a. vector intList(); b. vector<int> intList(0); c. vector<int> intList(10); d. vector<int> intList;

d. vector<int> intList;

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? a. void dClass::print() const { dClass:print(); cout << " " << y << endl; } b. void dClass::print() const { cout << x << " " << y << endl; } c. void bClass::print() const { cout << x << " " << y << endl; } d. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }

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

What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number <= 1 ) return 1; else return number * mystery( number - 1 ); } a. 0. b. 1. c. 4. d. 24.

d.24


Conjuntos de estudio relacionados

Lecture #3 - Conditioning and Development

View Set

Central Tendency & Variability, Frequency Distributions, Hypothesis Testing, and Chi Square

View Set

Evolve Community Health Quiz #1/#2

View Set

System Analysis and Design 7 and 8

View Set

Chapter 3: Providing Equal Employment Opportunity & a Safe Workplace

View Set