C++ Ch 6 - 13

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

What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl; A) 87 B) 0 C) garbage D) This code will not compile

0

25) After the following statement executes, what value is stored in the variable num? num = atoi("1000"); A) 1000 B) 999 (1000 minus 1 for the null terminator) C) "1000" D) "thousand" E) None of these

1000

array names can be used as constant pointers and pointers can

be used as array names

functions can return pointers

but you must be sure the item the pointer references still exists

When a function is called, flow of control moves to the function's prototype.

false

The name of an array stores the ________ of the first array element. A) memory address B) value C) element number D) data type E) None of these

memory address

The value in a ________ variable persists between function calls. A) dynamic B) local C) counter D) static local

static local

It is not considered good programming practice to declare all of your variables globally.

true

When you pass an array as an argument to a function, the function can modify the contents of the array.

true

How many elements does the following array have? int bugs[1000]; A) 1000 B) 999 C) 1001 D) Cannot tell from the code

1000

3) This is the escape sequence representing the null terminator. A) \n B) \t C) \0 D) nullptr E) None of these

\0

Unlike regular variables, these can hold multiple values. A) constants B) named constants C) arrays D) floating-point variables E) None of these

arrays

16) This function accepts a C-string containing a number as its argument and returns the integer equivalent. A) strToInt B) itoa C) atoi D) int_from E) None of these

atoi

9) This function converts a C-string to an integer and returns the integer value. A) atoint B) strtoint C) strint D) atoi E) None of these

atoi

10) Which statement converts the string "10" to the integer value 10? A) itoa("ten") B) atoi("ten") C) atoi("10") D) itoa(10) E) None of these

atoi("10)

8) This function accepts a C-string as an argument and converts the string to a long integer. A) atol B) strlong C) strtolong D) stringlong E) None of these

atol

2) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________. A) values, morals B) data, activities C) attributes, activities D) attributes, methods E) None of these

attributes, methods

Subscript numbering in C++________. A) can be set at runtime B) can begin with a programmer-defined value C) varies from program to program D) begins with zero E) None of these

begins with zero

A(n) ________ search is more efficient than a ________ search. A) character, string B) integer, double C) binary, linear D) linear, binary E) None of these

binary, linear

A ________ argument is passed to a parameter when the actual argument is left out of the function call. A) false B) true C) null D) default E) None of these

default

These types of arguments are passed to parameters automatically if no argument is provided in the function call. A) Local B) Default C) Global D) Relational E) None of these

default

12) When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________. A) empty constructor B) default constructor C) stand-alone function D) arbitrator function E) None of these

default constructor

18) Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr; A) declares an object of class Rectangle B) assigns the value of *BoxPtr to the object Rectangle C) defines a Rectangle pointer variable called BoxPtr D) is illegal in C++ E) None of these

defines a Rectangle pointer variable called BoxPtr

A function ________ contains the statements that make up the function. A) definition B) prototype C) call D) expression E) parameter list

definition

When an array is sorted from highest to lowest, it is said to be in ________ order. A) reverse B) forward C) descending D) ascending E) None of these

descending

pointer variables (pointers)

designed to hold memory address; with pointer variables you can indirectly manipulate data stored in other variables ex: int *ptr;

22) This is automatically called when an object is destroyed. A) constructor function B) specification deallocator C) destructor function D) coroner function E) None of these

destructor function

In C++, you can have constant pointers, and you can have pointers to constants, but you cannot have constant pointers to constants.

false

Local variables are initialized to zero by default.

false

The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.

false

The statement: double money[25.00]; is a valid C++ array definition.

false

Using a binary search, you are more likely to find an item than if you use a linear search.

false

You must furnish an argument with a function call.

false

An array can easily be stepped through by using a ________. A) for loop B) reference variable C) named constant D) null value E) None of these

for loop

it is common for one byte to be allocated for chars, two bytes for shorts,

four bytes for ints, longs, and floats, and eight bytes for doubles

Data that is sorted in ascending order is ordered ________. A) from lowest to highest value B) from highest to lowest value C) always with a binary sort algorithm D) always with a linear sort algorithm E) None of these

from lowest to highest value

This is a collection of statements that performs a specific task. A) infinite loop B) variable C) constant D) function E) None of these

function

This is a statement that causes a function to execute. A) for loop B) do-while loop C) function prototype D) function call E) None of these

function call

A ________ variable is declared outside all functions. A) local B) global C) floating-point D) counter E) None of these

global

If a function does not have a prototype, default arguments may be specified in the function ________. A) call B) header C) execution D) return type E) None of these

header

if one address comes before another address in memory the first address is considered

less than the second; relational operators may be used to compare pointer values relational operators >, <, ==, !=, <=, >=

A two-dimensional array is like ________ put together. A) an array and a function B) several identical arrays C) two functions D) two arrays of different types E) None of these

several identical arrays

The advantage of a linear search is its ________. A) complexity B) efficiency C) simplicity D) speed E) None of these

simplicity

This vector function returns the number of elements in a vector. A) size B) num_elements C) elements D) length

size

Array elements must be ________ before a binary search can be performed. A) summed B) set to zero C) sorted D) positive numbers E) None of these

sorted

________ algorithms are used to arrange random data into some order. A) Standard search B) Linear C) Sorting D) Binary search E) None of these

sorting

The value in this type of local variable persists between function calls. A) global B) internal C) static D) dynamic E) None of these

static

23) This function concatenates the contents of one C-string with another C-string. A) strcopy B) strappend C) strcat D) stradd E) None of these

strcat

1) True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.

true

10) True/False: A private member function is useful for tasks that are internal to the class, but is not directly called by statements outside the class.

true

10) True/False: If a C-string that cannot be converted to a numeric value is passed to the atoi function, the function's behavior is undefined by C++.

true

11) True/False: If an uppercase character is passed as an argument to toupper, the result will be an uppercase character.

true

11) True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

true

12) True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

true

13) True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.

true

13) True/False: You may use the <, >, <=, >=, ==, and != relational operators to compare string objects.

true

14) True/False: C++ 11 introduces a function named to_string that converts a numeric value to a string object.

true

14) True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.

true

15) True/False: The string class's front and back member functions were introduced in C++ 11.

true

15) True/False: When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.

true

2) True/False: The isdigit function will return a true if its argument is a digit between 0 and 9.

true

3) True/False: When using the strcat function, you must be careful not to overwrite the bounds of an array.

true

5) True/False: More than one constructor function may be defined for a class.

true

5) True/False: The itoa function is similar to atoi, but it works in reverse.

true

6) True/False: By being able to pass arrays as arguments, you can write your own functions for processing C-strings.

true

7) True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.

true

8) True/False: The C++ library provides functions for converting a string representation of a number to a numeric data type, and vice-versa.

true

A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.

true

A static variable that is defined within a function is initialized only once, the first time the function is called.

true

A vector object automatically expands in size to accommodate the items stored in it.

true

An individual array element can be processed like any other type of C++ variable.

true

Each individual element of an array can be accessed by the array name and an element number, called a subscript.

true

2) True/False: Class objects can be defined prior to the class declaration.

false

4) True/False: A destructor function can have zero to many parameters.

false

Global variables are initialized to zero by default.

true

30) The statement: char var1 = tolower('A'); will result in: A) var1 storing the character value 'A'. B) var1 storing the ASCII value for lower case 'a'. C) A is output to the monitor. D) a is output to the monitor. E) None of these

var1 storing the ASCII value for lower case 'a'.

Which statement correctly uses C++ 11 to initialize a vector of ints named n with the values 10 and 20? A) vector n<int>(10, 20); B) vector<int> n = {10, 20}; C) vector<int> n { 10, 20 }; D) int vector n ({10}, {20});

vector<int> n { 10, 20 };

Which statement correctly defines a vector object for holding integers? A) vector v<int>; B) int vector v; C) int<vector> v; D) vector<int> v;

vector<int> v;

const int SIZE = 4; int results[SIZE] = { 54, 44, 34, 22 }; int *resultsPtr = nullptr; resultsPtr = results + 2; cout << *resultsPtr << endl;

what value will be displayed by the cout statement? 34

indirection operator (*)

when the indirection operator is placed in front of a pointer variable name it dereferences the pointer; when you are working with a dereferenced pointer you are actually working with the value the pinter is pointing to

assigning nullptr to a pointer variable makes the variable point to the address 0

when the pointer is set to the address 0, it is referred to as a null pointer because it points to nothing Ex: int *ptr = nullptr;

in C++, when you add a value to a pointer

you are actually adding that value times the size of the data type being referenced by the pointer

7) This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once. A) #include B) #guard C) #ifndef D) #endif E) None of these

#ifndef

you should return a pointer from a function only if it is

- a pointer to an item that was passed into the function as an argument - a pointer to a dynamically allocated chunk of memory

19) When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these

-> operator

4) The null terminator stands for this ASCII code. A) 57 B) 100 C) 1000 D) 0 E) None of these

0

Given the following function definition: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A) 1 2 3 B) 1 6 3 C) 3 6 3 D) 1 14 9 E) None of these

1 6 3

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

10

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

15

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0

2 0 0

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0

2 0 2

Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared. A) 20,000 B) only the first C) only half D) 2000 E) None of these

20,000

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have? A) 1 B) 2 C) 3 D) Can't tell from the prototype

3

What will the following C++ 11 code display? vector<int> numbers { 3, 5 }; for (int val : numbers) cout << val << endl; A) 5 5 5 B) 3 3 3 3 3 C) 3 5 D) Nothing. This code has an error.

3 5

What is the last legal subscript that can be used with the following array? int values[5]; A) 0 B) 5 C) 6 D) 4

4

Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

4

What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; } A) 2 2 B) 4 2 C) 2 4 D) 4 4

4 2

What will the following code display? int numbers[] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl; A) 55 B) 66 C) 101 D) 87

55

What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; } A) 5 B) 2 C) 7 D) "getValue(x)"

7

31) What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test(77); return 0; } A) The program runs, but with no output. B) 77 C) Hello! D) The program will not compile.

77

What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << endl; A) 99 87 66 55 101 B) 87 66 55 101 C) 87 66 55 D) Nothing. This code has an error.

87 66 55

22) To use the strlen function in a program, you must also write #include ________. A) <strlen> B) <iostring> C) <cstring> D) <stringlib> E) None of these

<cstring>

Which of the following statements about global variables is true? A) A global variable is accessible only to the main function. B) A global variable is declared in the highest-level block in which it is used. C) A global variable can have the same name as a variable that is declared locally within a function. D) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function. E) All of these are true.

A global variable can have the same name as a variable that is declared locally within a function.

15) A practical application of this function is to allow a user to enter a response of 'y' or 'Y' to a prompt. A) tolower B) toupper C) A or B D) ignorecase E) None of these

A or B

14) "Whitespace" encompasses which of the following? A) tab B) newline C) space D) All of these E) None of these

All of these

What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; } A) Each element in the array is initialized to 0.0 B) Each element in the array, except the first, is initialized to 0.0 C) Each element in the array, except the first and the last, is initialized to 0.0 D) An error will occur when the code runs

An error will occur when the code runs

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called. A) EXIT_TERMINATE B) EXIT_SUCCESS C) EXIT_OK D) RETURN_OK E) None of these

EXIT_SUCCESS

30) What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test; return 0; } A) The program runs, but with no output. B) 0 C) Hello! D) The program will not compile.

Hello!

25) The process of object-oriented analysis can be viewed as the following steps: A) Identify objects, then define objects' attributes, behaviors, and relationships B) Define data members and member functions, then assign a class name C) Declare private and public variables, prototype functions, then write code D) Write the main() function, then determine which classes are needed E) None of these

Identify objects, then define objects' attributes, behaviors, and relationships

What does the following statement do? vector<int> v(10, 2); A) It creates a vector object and initializes all the first two elements with the values 10 and 2. B) It creates a vector object with a starting size of 2 and the first element initialized with the value 10. C) It creates a vector object with a starting size of 10 and the first element initialized with the value 2. D) It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

What does the following statement do? vector<int> v(10); A) It creates a vector object and initializes all of its elements to the value 10. B) It creates a vector object with a starting size of 10. C) It creates a vector object and initializes the first element with the value 10. D) It creates a vector object that can store only values of 10 or less.

It creates a vector object with a starting size of 10.

10) The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these

None of these

27) This library function reverses the order of a C-string. A) reverstr B) strrev C) reversit D) backward E) None of these

None of these

11) The destructor function's return type is ________. A) tilde B) int C) float D) Nothing. Destructors have no return type. E) None of the above

Nothing. Destructors have no return type.

32) What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; } A) The program runs, but with no output. B) 77 C) 0 D) The program will not compile.

The program will not compile

int scores[5] = { 454, 556, 445, 234, 343 };

Which one of the following cout statements would display the contents of the fifth element in the array? cout << *(scores +4) << endl;

To assign the contents of one array to another, you must use ________. A) the assignment operator with the array names B) the equality operator with the array names C) a loop to assign the elements of one array to the other array D) Any of these E) None of these

a loop to assign the elements of one array to the other array

each byte of memory has a unique address

a variable's address is the address of the first byte allocated to that variable

pointers may be initialized with the

address of an existing object

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list. A) all dimensions B) all but the first dimension C) the size declarator of the first dimension D) all element values E) None of these

all but the first dimension

A two-dimensional array of characters can contain ________. A) strings of the same length B) strings of different lengths C) uninitialized elements D) All of these E) None of these

all of these

In a function header, you must furnish: A) data type(s) of the parameters B) data type of the return value C) the name of function D) names of parameter variables E) All of these

all of these

dynamic memory allocation

allow the program to create its own variables on the fly; only possible through the use of pointers

the ++ and -- operators may be used to increment or decrement a pointer variable

an integer may be added t or subtracted from a pointer variable; this may be performed with the + and - operators or the += and -= operators a pointer may be subtracted from another pointer

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. A) function call, function header B) parameter, argument C) argument, parameter D) prototype, header E) None of these

argument, parameter

13) Look at the following statement. if (!isdigit(var1)) The expression being tested by this statement will evaluate to true if var1 is: A) an alphabetic character B) 9 C) a symbol such as $ or & D) both A and C E) None of these

both A and C

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. A) call B) prototype C) define D) declare E) None of these

call

A function is executed when it is: A) defined B) prototyped C) declared D) called E) None of these

called

28) To define a C-string that will store students' last names of up to 25 characters in length, which is an appropriate statement? A) char lastName[25]; B) string lastName[25]; C) char lastName[26]; D) string lastName[24]; E) None of these

char lastName[26];

29) Which of the following lines of code defines an array of C-strings that will hold 49 characters and the null terminator? A) char [49]; B) char str[50]; C) char[50] str; D) character str[50]; E) None of the above

char str[50];

26) When a member function is defined outside of the class declaration, the function name must be qualified with the ________. A) class name, followed by a semicolon B) class name, followed by the scope resolution operator C) name of the first object D) private access specifier E) None of these

class name, followed by the scope resolution operator

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? A) computeValue(10) B) computeValue(10); C) void computeValue(10); D) void computeValue(int x);

computeValue(10);

An array's size declarator must be a ________ with a value greater than ________. A) number, one B) number, zero C) constant integer expression, zero D) variable, -1 E) None of these

constant integer expression, zero

9) A ________ is a member function that is automatically called when a class object is ________. A) destructor, created B) constructor, created C) static function, deallocated D) utility function, declared E) None of these

constructor, created

16) A class is a(n) ________ that is defined by the programmer. A) data type B) function C) method D) attribute E) None of these

data type

1) Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floats E) None of these

data, functions

15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these

data, functions

you can use the const key word to define a constant pointer

diff between a pointer to const and a const pointer: - a pointer to const points to a constant item; the data that the pointer points to cannot change, but the pointer itself can change - with a const pointer it is that the pointer itself that is constant; once the pointer is initialized with an address, it cannot point to anything else Ex const pointer: int value = 22; int *const ptr =&value;

It is a good programming practice to ________ your functions by writing comments that describe what they do. A) execute B) document C) eliminate D) prototype E) None of these

document

17) Members of a class object are accessed with the ________. A) dot operator B) cin object C) extraction operator D) stream insertion operator E) None of these

dot operator

Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable? A) int B) double C) void D) Can't tell from the prototype

double

The individual values contained in array are known as ________. A) parts B) elements C) numbers D) constants E) None of these

elements

12) The C-string company[12] can hold ________. A) twelve characters B) thirteen characters C) eleven characters and the null terminator D) twelve characters and the null terminator E) None of the above

eleven characters and the null terminator

This vector function returns true if the vector has no elements. A) has_no_elements B) null_size C) empty D) is_empty

empty

when the address operator & is placed in front of the variable name, it returns the address of that variable

ex: &amount ex: cout << &amount

This function causes a program to terminate, regardless of which function or control mechanism is executing. A) terminate() B) return() C) continue() D) exit() E) None of these

exit ( )

1) True/False: A test using the isupper function will return false if the argument is an uppercase character.

false

12) True/False: Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.

false

3) True/False: The constructor function may not accept arguments.

false

4) True/False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.

false

6) True/False: More than one destructor function may be defined for a class.

false

7) True/False: The strlen function returns a C-string's length and adds one for \0.

false

8) True/False: You must declare all data members of a class before you declare member functions.

false

9) True/False: The ftoa function converts a floating-point value to an ASCII value.

false

9) True/False: You must use the private access specification for all data members of a class.

false

A function's return data type must be the same as the function's parameter(s).

false

A linear search can only be implemented with integer values.

false

A local variable and a global variable may not have the same name within the same program.

false

Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

false

An array initialization list must be placed on one single line.

false

Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement. array1 = array2;

false

Before you can perform a bubble sort, the data must be stored in descending order.

false

Before you can perform a selection sort, the data must be stored in ascending order.

false

C++ limits the number of array dimensions to two.

false

If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.

false

In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.

false

An array with no elements is ________. A) legal in C++ B) illegal in C++ C) automatically furnished one element, with a value of zero D) automatically furnished one value—the null terminator E) None of these

illegal in C++

It is ________ to pass an argument to a function that contains an individual array element, such as numbers[3]. A) illegal in C++ B) legal in C++ C) not recommended by the ANSI committee D) not good programming practice E) None of these

illegal in C++

The statement: int grades[ ] = { 100, 90, 99, 80}; shows an example of: A) default arguments B) an illegal array declaration C) an illegal array initialization D) implicit array sizing E) None of these

implicit array sizing

6) Class declarations are usually stored here. A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these

in their own header files

A(n) ________ can be used to specify the starting values of an array. A) initialization list B) array name C) subscript D) element E) None of these

initialization list

Arrays may be ________ at the time they are ________. A) resized, executed B) re-scoped, deleted C) initialized, declared D) pre-compiled, typecast E) None of these

initialized, declared

8) When the body of a member function is defined inside a class declaration, it is said to be ________. A) static B) global C) inline D) conditional E) None of these

inline

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value? A) int B) double C) void D) Can't tell from the prototype

int

Which of the following is a valid C++ array definition? A) int array[0]; B) float $payments[10]; C) void numbers[5]; D) int array[10]; E) None of these

int array[10];

Which of the following is a valid C++ array definition? A) int scores[0]; B) float $payments[10]; C) int readings[4.5]; D) int scores [10]; E) None of these

int scores [10];

17) To determine whether a character entered is a letter of the alphabet, use this function. A) isdigit B) fromkeyboard C) alphaok D) isalpha E) None of these

isalpha

1) To test whether a character is a numeric digit character, use this function. A) isnumber B) notAlpha C) isnumeric D) isdigit E) None of these

isdigit

2) To test whether a character is a printable character, use this function. A) isprint B) isprintable C) isprintok D) isoktoprint E) None of these

isprint

11) This function will return true if its argument is a printable character other than a digit, letter, or space. A) isprint B) ispunct C) ischar D) isnotdls E) None of these

ispunct

18) To determine whether a character is whitespace, use this function. A) iswhite B) isspace C) iswhitespace D) isblank E) None of these

isspace

a pointer can be use as a function parameter

it gives the function access to the original argument, like the reference parameter does

nullptr

it is never a good idea to define a pointer variable without initializing it with a valid memory address; if you inadvertently use an uninitialized pointer variable, you will be affecting some unknown location in memory; for that reason, it is a good idea to initialize pointer variables with the special value nullptr

the address operator, &,

it returns the memory address of a variable

A(n) ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) None of these

linear

The ________ is adequate for searching through small arrays. A) binary search B) linear search C) unary search D) bubble sort E) None of these

linear search

This type of variable is defined inside a function and is not accessible outside the function. A) global B) reference C) local D) counter E) None of these

local

20) What is the output of the following statement? cout << tolower(toupper('Z')) << endl; A) upper case Z B) lower case z C) a lower case z followed by an upper case Z D) a compiler error E) None of these

lower case z

A binary search begins with the ________ element of an array. A) first B) last C) largest D) middle E) None of these

middle

29) Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();

myCar.accelerate();

To pass an array as an argument to a function, pass the ________ of the array. A) contents B) size, expressed as an integer C) name D) value of the first element E) None of these

name

Regardless of the algorithm being used, a search through an array is always performed ________. A) from lowest to highest element B) from highest to lowest element C) beginning with the middle element D) using a binary search E) None of these

none of these

21) In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a ________. A) period B) space C) null character D) semicolon E) None of these

null terminator

The ________ is automatically appended to a character array when it is initialized with a string constant. A) array name B) number of elements C) value of the first element D) null terminator E) None of these

null terminator

smart pointers

objects that work like pointers but have the ability to automatically delete dynamically allocated memory that is no longer being used; helps to prevent memory leaks form occurring

A two-dimensional array can have elements of ________ data type(s). A) one B) two C) four D) Any of these E) None of these

one

23) A class may have this many default constructor(s). A) only one B) more than one C) a maximum of two D) any number E) None of these

only one

A function can have zero to many parameters, and it can return this many values. A) zero to many B) no C) only one D) a maximum of ten E) None of these

only one

If a function is called more than once in a program, the values stored in the function's local variables do not ________ between function calls. A) persist B) execute C) communicate D) change E) None of these

persist

array names are

pointer constants; you can't make them point to anything but the array they represent

This vector function removes an item from a vector. A) remove_item B) delete_item C) erase D) pop_back

pop_back

14) If you do not declare an access specification, the default for members of a class is ________. A) inline B) private C) public D) global E) None of these

private

20) This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these

private

5) This is used to protect important data. A) public access specifier B) private access specifier C) protect() member function D) class protection operator, @ E) None of these

private access specifier

4) Examples of access specifiers are the key words: A) near and far B) opened and closed C) private and public D) table and row E) None of these

private and public

A function ________ eliminates the need to place a function definition before all calls to the function. A) header B) prototype C) argument D) parameter E) None of these

prototype

13) This type of member function may be called from a statement outside the class. A) public B) private C) undeclared D) global E) None of these

public

This vector function is used to insert an item into a vector. A) insert_item B) add_item C) store D) push_back

push_back

The range-based for loop, in C++ 11, is designed to work with a built-in variable known as the ________. A) counter variable B) i variable C) iterator D) range variable E) None of these

range variable

When used as parameters, these types of variables allow a function to access the parameter's original argument. A) reference B) floating-point C) counter D) undeclared E) None of these

reference

) This statement causes a function to end. A) end B) terminate C) return D) release E) None of these

return

A two-dimensional array can be viewed as ________ and ________. A) rows, columns B) arguments, parameters C) increments, decrements D) All of these E) None of these

rows, columns

27) If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used. A) variable B) ambiguity C) scope D) global E) None of these

scope

Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97}; A) scores[0] B) scores[1] C) scores[2] D) scores[4]

scores[2]

A ________ algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) search C) standard D) linear E) None of these

search

The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) binary, linear C) selection, bubble D) ANSI, ASCII E) None of these

selection, bubble

26) To change a lower case character to an upper case character, use this function. A) atoi B) itoa C) ltou D) toupper E) None of these

toupper

An array of string objects that will hold 5 names would be declared using which statement? A) string names[5]; B) string names(5); C) string names5; D) String[5] names; E) None of these will work.

string names[5];

5) This function accepts a pointer to a C-string as an argument, and it returns the length of the C-string (not including the null terminator). A) numchar B) strlength C) strlen D) countstring E) None of these

strlen

24) This function accepts pointers to two C-strings and an integer argument, which indicates how many characters to copy from the second C-string to the first. A) strcpy B) strncpy C) copystring D) strintcpy E) None of these

strncpy

7) A library function that can find one C- string inside another is: A) strcmp B) strstr C) strfind D) strsearch E) None of these

strstr

3) A C++ class is similar to one of these. A) inline function B) header file C) library function D) structure E) None of these

structure

This is a dummy function that is called instead of the actual function it represents. A) main function B) stub C) driver D) overloaded function

stub

By using the same ________ you can build relationships between data stored in two or more arrays. A) array name B) data C) subscript D) arguments E) None of these

subscript

To access an array element, use the array name and the element's ________. A) data type B) subscript C) name D) value E) None of these

subscript

24) Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these

subscripts

21) The constructor function always has the same name as ________. A) the first private data member B) the first public data member C) the class D) the first object of the class E) None of these

the class

An element of a two-dimensional array is referred to by ________ followed by ________. A) the array name, the column number of element B) the row subscript of the element, the column subscript of the element C) a comma, a semicolon D) the row subscript of element, the array name E) None of these

the row subscript of the element, the column subscript of the element

An array can store a group of values, but the values must be: A) the same data type B) each of a different data type C) constants D) integers E) None of these

the same data type

this compares the addresses stored int the pointer variables if (ptr1 < ptr2)

this compares the values that ptr1 and ptr2 point to if (*ptr1 < *ptr2)

a reference variable acts as an alias to the original variable used as an argument

this gives the function access to the original argument variable allowing it to change the variable's contents

19) To change a character argument from lower to upper case, use this function. A) isupper B) toupper C) tolarge D) fromlower E) None of these

toupper

If an array is partially initialized, the uninitialized elements will be set to zero.

true

In C++ 11, you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference.

true

In the average case, an item is just as likely to be found near the beginning of an array as near the end.

true

It is possible for a function to have some parameters with default arguments and some without.

true

One reason for using functions is to break programs into manageable units, or modules.

true

The amount of memory used by an array depends upon the array's data type and the number of elements in the array.

true

The number of comparisons made by a binary search is expressed in powers of two.

true

With a const pointer, it is the pointer itself that is constant. Once the pointer is initialized with an address, it cannot point to anything else

true

You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

true

the new operator dynamically allocates memory

true

when a program is finished with a chunk of dynamically allocated memory it should free it with the delete operator

true

you cannot multiply or divide a pointer

true

6) The strcpy function's arguments are: A) two C-strings B) two addresses C) three pointers D) one array and one pointer E) None of these

two addresses

________ functions may have the same name, as long as their parameter lists are different. A) Only two B) Two or more C) Zero D) Un-prototyped E) None of these

two or more

3 types of smart pointer

unique_ptr, shared_ptr, weak_ptr have to use #include<memory> to use the above functions

unique_ptr

unique_ptr<int> ptr(new int); - notation <int> that appears after unique_ptr indicates that the pointer can point to an int - the name of the pointer is ptr - the expression new int that appears inside the parentheses allocates a chunk of memory to hold an int; the address of the chunk of memory will be assigned to the ptr pointer

The only difference between array names and pointer variables is that

you cannot change the address an array name points to

If you leave out the size declarator in an array definition: A) you must furnish an initialization list B) you are not required to initialize the array elements C) all array elements default to zero values D) your array will contain no elements

you must furnish an initialization list

28) For the following code, which statement is not true? class Point { private: double y; double z; public: double x; }; A) x is available to code that is written outside the class. B) The name of the class is Point. C) x, y, and z are called members of the class. D) z is available to code that is written outside the class.

z is available to code that is written outside the class.


Conjuntos de estudio relacionados

High-Risk Neonatal Nursing Care, Exam 3 Practice

View Set

CURRENT: L&D, Common Reproductive Concerns, L&D at Risk, 312 Exam 3

View Set

Multiplication 1 x 1 to 100 x 20

View Set