C++ test prep 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

_______ parameters are useful when you want to return more than one value from a function a) reference b) default c) automatic d) value

a) reference

Suppose that printHeading is a function without any parameters. Which of the following is a valid function heading? a) void printHeading() b) void prindHeading(noParameters) c) void printHeading(); d) void printHeading(void);

void printHeading()

Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData? a) 0 to 99 b) 1 to 1000 c) 1 to 1001 d) 0 to 1000

a) 0 to 99

The output of the statement: cout << pow(3,2) + 5; is ____. a) 14 b) 9 c) 15 d) 10

a) 14

cin >> num; if (num > 0) num = num + 10; else if (num > 5) num = num + 15; After the execution of the code above, what will be the value of num if the input value is 5? a) 15 b) 0 c) 25 d) 5

a) 15

int x = 5; return x + 1; What value is returned by the return statement above? a) 6 b) 0 c) 5 d) 7

a) 6

int next(int x) { return (x + 1); } Given the above function, choose the output of the following statement: cout << next(next(5)); a) 7 b) 8 c) 5 d) 6

a) 7

Which of the following is a relational operator? a) == b) = c) && d) !

a) ==

function prototype is _____ a) a declaration, but not a definition b) a definition, but not a declaration c) a declaration and definition d) a comment line

a) a declaration, but not a definition

Which of the following function prototypes is valid? a) int funcExp(int x, float v); b) funcExp(int x, float v) {}; c) int funcExp(void); d) funcExp(void);

a) int funcExp(int x, float v);

The first step in the binary search is to compare the search item with the ____ element of the list a) middle b) 1 c) last d) 0

a) middle

All components of an array are of the same type. a) true b) false

a) true

Parameters allow the programmer to use different values each time the function is called a) true b) false

a) true

Suppose that you have the following list: int list[7] = {2, 5, 8, 11, 14, 17, 20};. Assume that a sequential search on an ordered list is used to determine whether 11 is in the list. When the loop terminates, the value of the index variable loc is 3. a) true b) false

a) true

Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true a) true b) false

a) true

The binary search algorithm is usually implemented on array-based lists. a) true b) false

a) true

The value of the expression 7 + 8 <= 15 is true a) true b) false

a) true

The word const is used before the array declaration in a function heading to prevent the function from modifying the array. a) true b) false

a) true

To determine whether a given item is in an ordered list of length 1000, a binary search makes ay most 10 key comparisons. a) true b) false

a) true

To use a predefined function, the program must include the appropriate header file a) true b) false

a) true

To use the predefined functions abs, the program must include the header file cmath. a) true b) false

a) true

Which of the following is a legal C++ function definition? a) void funcTest( int& u, double& v) {cout << u << " " << y << endl;} b) void funcTest( int& u, double& v); {cout << u << " " << y << endl; } c) void funcTest( int& u, double& v) (cout << u << " " << y << endl) d) void funcTest( int& u, double& v) [cout << u << " " << y << endl;]

a) void funcTest( int& u, double& v) {cout << u << " " << y << endl;}

x =10; y = 15; muystery(x, y); void mystery(int& one, int two) {int temp; temp = one; one = two; two = temp; } What are the values of x and y after the statements above execute? (Assume that variable are properly declared) a) x = 15; y = 15 b) x = 15; y = 10 c) x = 10; y = 15 d) x = 10; y = 10

a) x = 15; y = 15

Suppose that L is a sorted list of 1000 elements. To determine whether the x item is in L, the maximum number of comparisons executed by the binary search algorithm is_______. a) 250 b) 10 c) 22 d) 500

b) 10

int num int alpha = 10; cin >> num; switch(num) { case 3: alpha++ break; case 4: case 6: alpha = alpha + 3; case 8: alpha: alpha + 4; break; default: alpha = alpha = alpha + 5; } cout << alpha << endl; What is the output of the code fragment above if the input value is 4? a) 22 b) 17 c) 13 d) 14

b) 17

if (x > y) z = x + y; else z = y - x; cout << x << "__" << y << "__" << z << endl; What is the output of the code above when x = 35, y = 45? a) 35__45__0 b) 35__45__10 c) 35__45__80 d) 35__45__-45

b) 35__45__10

What type of search algorithm divides the list by two (2) each time? a) quick b) binary c) selection d) sequential

b) binary

int list[5 = {0, 5, 10, 48, 20}; int j; for(j = 0; j <= 5; j++) cout << lit[j] << "_"; cout << endl; a) 0_5_10_15_20 b) code contains index out of bond c) 0, 10, 15, 20, 0 d) 5, 10, 15, 20, 10

b) code contains index out of bond

A sequential search is very efficient for large lists a) true b) false

b) false

A value-returning unction can return two values via the return statement a) true b) false

b) false

Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference. a) true b) false

b) false

Every if statement must have a corresponding else a) true b) false

b) false

Every switch statement must have the default label a) true b) false

b) false

Suppose that you have the following list: int list[9] = {5, 10, 15, 20, 25, 30, 35, 40, 45};. Assume that sequential search on an ordered list is used to determine whether 28 is in the list. When the loop terminates, the value of the index variable loc is 4. a) true b) false

b) false

The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. a) true b) false

b) false

The value of the expression 'a' < 'A' is true. a) true b) false

b) false

int alpha[100]; int beta[25][4]; Assume that you have the declaration above. In this declaration, the array alpha has more elements than the array beta. a) true b) false

b) false

num = 5; if (num >= 5) cout << num; else out << num + 5; The output of the code above is 10 a) true b) false

b) false

the expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100 a) true b) false

b) false

When one control statement is located within another, it is said to be ________. a) closed b) nested c) blocked d) compound

b) nested

The statement num is less than 10 or num is greater than 50 in C++ is written as (num < 10) || (num > 50) a) num 50 b) true c) null d) not sure

b) true

A void function accomplish has three parameters: a parameter u of the type int, a parameter v of the type double, and a parameter letter of the type char. The parameters u and letter need to pass their values out of the function and the parameter v is to only receive the value from the calling environment. Which of the following is a correct function heading? a) void accomplish( int u, double& v, char letter) b) void accomplish( int& u, double v, char& letter) c) void accomplish( int& u, double v, char& letter); d) void accomplish( int u, double& v, char letter);

b) void accomplish( int& u, double v, char& letter)

Which of the following operators gives a remainder of a division? a) * b) / c) % d) !

c) %

The sequential search starts with the ____ element of the array a) int b) 1 c) 0 d) 2

c) 0

Consider the following list: list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};. Suppose that the sequential search is used to determine whether 95 is in the list. How many key comparisons are executed by the sequential search algorithm? a) 8 b) 4 c) 10 d) 9

c) 10

Consider the following list: list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};. Suppose that the sequential search is used to determine whether 2 is in the list. How many key comparisons are executed by the sequential search algorithm? a) 2 b) 10 c) 4 d) 5

c) 4

Consider that L is a sorted list of 1,000,000 elements. To determine whether the x item is in L, the average number of comparisons executed by the sequential search algorithm is _______. a) 250 b) 1000 c) 500000 d) 1000000

c) 500000

A _____ is a set of values of the same type a) set b) map c) array or list d) dictionary

c) array or list

A __________ statement causes an immediate exit from the switch structure. a) default b) endl; c) break d) exit

c) break

double sales[50]; int j; consider the declaration above. Which of the following correctly initializes the array sales? a) for(j = 0; j <= 49; j++) sales[j] = 0; b) for(j = 1; j <= 50; j++) sales[j] = 0; c) for(j = 0; j <= 49; j++) sales[j] = 0.0; d) for(j = 1; j <= 50; j++) sales[j] = 0.0;

c) for(j = 0; j <= 49; j++) sales[j] = 0.0;

int gamma[50]; int j; Given the declaration above, which of the following for loops sets the index of gamma out of bonds? a) for(j = 0; j <= 49; j++) cout << gamma[j] << " "; b) for(j = 1; j < 50; j++) cout << gamma[j] << " "; c) for(j = 0; j <= 50; j++) cout << gamma[j] << " "; d) for(j = 0; j <= 48; j++) cout << gamma[j] << " ";

c) for(j = 0; j <= 50; j++) cout << gamma[j] << " ";

Which of the following statements declares alpha to be an array of 25 components of the type int? a) int array alpha[25]; b) int alpha[2][5]; c) int alpha[25]; d) int array alpha[25][25];

c) int alpha[25];

Consider the following declaration int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement? a) int alpha[] = {3 5 7 9 11}; b) int alpha[] = (3, 5, 7, 9, 11); c) int alpha[] = {3, 5, 7, 9, 11}; d) int alpha[5] = {3, 5, 7, 9, 11};

c) int alpha[] = {3, 5, 7, 9, 11};

Consider the following list : list = [24, 20, 10, 75, 70, 18, 60, 35]. Suppose that the list is sorted using the selection sort algorithm. What is the resulting list after two iterations of selection sort? a) list = [10, 18, 24, 20, 75, 70, 60, 35] b) list = [10, 18, 24, 75, 70, 20, 35, 60] c) list = [10, 18, 24, 75, 70, 20, 60, 35] d) list = [10, 18, 20, 24, 75, 70, 60, 35]

c) list = [10, 18, 24, 75, 70, 20, 60, 35]

The ____ search is called the linear search a) binary b) bobble c) sequential d) quick

c) sequential

The ______ of a list is the number of elements in the list a) capacity b) width c) size d) volume

c) size

int mystery(int u, int v) { int a; a = u - v; u = a; v = u; return u + v; } Given the above functions choose the output of the following statement: cout << mystery(9, 7); a) 7 b) 2 c) 9 d) 4

d) 4

______ is a set of values of the same type. a) set b) map c) dictionary d) array

d) array

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

d) -1

suppose x is 5 and y is 7. Choose the value of the following expression: (x!=7)&&(x<=y) a) null b) 0 c) not true d) 1

d) 1

Consider the following list: list = [20, 10, 17, 12, 18, 35, 30, 90, 48, 47]; Suppose that the sequential search is used to determine whether 2 is in the list. Maximum how many key comparisons are executed by the sequential search algorithm a) 3 b) 2 c) 5 d) 10

d) 10

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y/x > 0) ? x: y;. a) 3 b) 4 c) 6 d) 2

d) 2

Item comparisons in the sequential search are called ____ comparisons a) record b) map c) lock d) key

d) key

Placing = in an expression instead of == cause a ______. a) input failure b) silent killer c) syntax error d) logical error

d) logical error

int one = 5; char letter = 'A'; strange(one, letter); void strange( int& u, char& ch) {int a; a = u++; u = 2 * u; a =static_cast<int>(ch); a++; ch = static_cast<char>(a); } What are the values of one and letter after the statements above execute? a) one = 10; letter = 'B' b) one = 5; letter = 'A' c) one = 10; letter = 'A' d) one = 12; letter = 'B'

d) one = 12; letter = 'B'


Set pelajaran terkait

Nutrition Chapter 6: Lipids, Triglycerides, Phospholipids and steroids

View Set

BIOCHEMISTRY TOPIC 2: MUTATION AND REPAIR

View Set

DMLSS: Catalog Search and Record Management

View Set

FNAN 300 Exam 1 PRACTICE PROBLEMS

View Set

Kansas Life Insurance #4: Life Insurance Policies

View Set

Shape (left skew, right skew, symmetrical)

View Set

Interpreting and Statistically Evaluating a Correlation

View Set

Ch. 7 TB: Consumer Buying Behavior

View Set

Anthropology 120 Exam 1. Chap 3+4

View Set