COSC 1436 Review exam 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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. 2 b. 3 c. 4 d. 6

a. 2

What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl; a. 2 b. 5 c. 8 d. 10

a. 2

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code? cin >> sum; cin >> num; for (j = 1; j <= 3; j++) { cin >> num; sum = sum + num; } cout << sum << endl; a. 24 b. 25 c. 41 d. 42

a. 24

What is the next Fibonacci number in the following sequence? 1, 1, 2, 3, 5, 8, 13, 21, ... a. 34 b. 43 c. 56 d. 273

a. 34

The standard header file for the abs(x)function is ____. a. <cmath> b. <cstdlib> c. <cctype> d. <ioinput>

a. <cmath>

Which of the following operators has the highest precedence? a. = b. ! c. * d. %

b. !

You can disable assert statements by using which of the following? a. #include <cassert> b. #define NDEBUG c. #define <assert> d. #clear NDEBUG

b. #define NDEBUG

The statement: return 8, 10; returns the value ____. a. 8 b. 10 c. 18 d. 80

b. 10

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x || x < 20 b. 10 < x && x < 20 c. 10 < x < 20 d. (10 < x < 20)

b. 10 < x && x < 20

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl; a. 124 b. 125 c. 126 d. 127

b. 125

The expression in an if statement is sometimes called a(n) ____. a. selection statement b. decision maker c. action maker d. action statement

b. decision maker

What is the initial statement in the following for loop? (Assume that all variables are properly declared.) int i; for (i = 1; i < 20; i++) cout << "Hello World"; cout << "!" << endl; a. i < 20; b. i = 1; c. cout << "Hello World"; d. i++;

b. i = 1;

Functions that do not have a return type are called ____ functions. a. zero b. void c. null d. empty

b. void

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

b.nested

Which of the following is the "not equal to" relational operator? a. | b. ! c. != d. &

c. !=

Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x >= 0) || (x == 0) b. (x > 0) && (x == 0) Correct c. (x > 0) || ( x <= 0) d. (x > 0) && ( x <= 0)

c. (x > 0) || ( x <= 0)

What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout << j << " "; cout << j << endl; a. 10 b. 10 10 c. 10 11 d. 11 11

c. 10 11

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; cin >> num; while (num != -1) { sum = sum + num; cin >> num; } cout << sum << endl; a. 92 b. 109 c. 110 d. 119

c. 110

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;

c. 35 45 10

What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 a. 2 b. 3 c. 4 d. 5

c. 4

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

Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ while loop. a. sentinel-controlled b. flag-controlled c. EOF-controlled d. counter-controlled

c. EOF-controlled

Which statement below about prototypes and headers is true? a. Headers end with a semicolon, but prototypes do not. b. Headers should come before prototypes. c. Prototypes end with a semicolon, but headers do not. d. Parameter names must be listed in the prototype, but not necessarily in the header.

c. Prototypes end with a semicolon, but headers do not.

The ____ statement can be used to eliminate the use of certain (flag) variables. a. switch b. while c. break d. if

c. break

Which of the following is a repetition structure in C++? a. switch b. if c. do...while d. while...do

c. do...while

Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x <= 5) b. if (x >= 5) c. if (x = 5) d. if (x == 5)

c. if (x = 5)

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, '*');

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

c. true

What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout << count << " " << num << endl; a. 24 0 b. 24 1 c. 25 0 d. 25 1

d. 25 1

What is the value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40

d. 40

The statement: return 37, y, 2 * 3; returns the value ____. a. y b. 3 c. 2 d. 6

d. 6

Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____. a. 65 b. 67 c. 96 d. 98

d. 98

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

d. ==

What is the output of the following loop? count = 5; cout << 'St'; do { cout << 'o'; count--; } while (count <= 5); a. St b. Sto c. Stop d. This is an infinite loop.

d. This is an infinite loop.

A variable or expression listed in a call to a function is called the ____. a. type of the function b. data type c. formal parameter d. actual parameter

d. actual parameter

Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared. a. cout << tryMe(tryMe(float, float), float); b. cin >> tryMe(x); c. cout << tryMe(tryMe(double, double), double); d. cout << tryMe(2.0, 3.0);

d. cout << tryMe(2.0, 3.0);

Which of the following loops does not have an entry condition? s: a. sentinel-controlled while loop b. for loop c. EOF-controlled while loop d. do...while loop

d. do...while loop

A loop that continues to execute endlessly is called a(n) ____ loop. a. definite b. end c. unhinged d. infinite

d. infinite

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s). a. sequence b. branching c. selection d. looping

d. looping


Ensembles d'études connexes

APUSH Unit 5 Practice Exam Questions & Answers

View Set

FSHN150 - Chapter 4 Carbohydrates

View Set

mental health: fundamental and legal ethical, treatment setting and program, legal and ethical

View Set

CISC3000 Quiz 02 - Chapter 02 Introduction to the Relational Model

View Set

Assessment individual differences

View Set

Economics Day 3 Notes: Incentives and Disincentives

View Set

POS2041 Midterm Study Guide: Chapter 6-9

View Set

chapter 15 specimen collection and diagnostic testing

View Set