MIDTERM 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 b. sum = 5 c. sum = 10 d. sum = 15

d. sum = 15

Which executes first in a do... while loop? a. update statement b. loop condition c. the expression d. the statement

d. the statement

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

d. true

The expression static_cast<int>(9.9) evaluates to ____. a. 9 b. 10 c. 9.0 d. 9.9

a. 9

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

c. !=

____ is a valid char value. a. 'A' b. "-129" c. "A" d. 129

a. 'A'

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 13 b. 14 c. 14.8 d. 15

a. 13

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

Consider the following code. // Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong? a. Insertion Point 1 b. Insertion Point 2 c. Insertion Point 3 d. Anywhere in the program

a. Insertion Point 1

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny Day b. Sunny \nDay endl c. Sunny \nDay d. Sunny \n Day

a. Sunny Day

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W b. X c. Y d. Z

a. W

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. a. algorithm b. analysis c. linker d. design

a. algorithm

A sequence of eight bits is called a ____. a. byte b. binary digit c. character d. double

a. byte

Which of the following is a reserved word in C++? a. char b. Char c. character d. CHAR

a. char

Consider the following code. int limit; int reps = 0; cin >> limit; while (reps < limit) { cin >> entry; triple = entry * 3; cout << triple; reps++; } cout << endl; This code is an example of a(n) ____ while loop. a. counter-controlled b. EOF-controlled c. sentinel-controlled d. flag-controlled

a. counter-controlled

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

c. #define NDEBUG

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. ignore b. delete c. clear d. skip

a. ignore

Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip

a. iostream

In a ____ control structure, the computer executes particular statements depending on some condition(s). a. selection b. sequence c. repetition d. looping

a. selection

Which of the following statements generates a random number between 0 and 50? a. srand(time(0)); num = rand() % 50; b. srand(time(0)); num = rand()50; c. srand(time(10)); num = rand()/50; d. srand(time(10)); num = rand() % 50;

a. srand(time(0)); num = rand() % 50;

The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language. a. syntax b. logical c. grammatical d. semantic

a. syntax

Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: ​ 15A 73.2 ​ Choose the values after the following statement executes: ​ cin >> x >> ch >> y; a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A.

a. x = 15, ch = 'A', y = 73.2

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2; a. W b. X c. Y d. Z

b. X

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ What is the value of ch3 after the following statements execute? ​ cin.get(ch1); cin.get(ch2); cin.get(ch3); ​a. 'A' b. 'B' c. 'C' d. '\n'

b. 'B'

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

b. 10 < x && x < 20

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18**Happy Sleepy** b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18 Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy

b. 12345678901234567890 ***18**Happy**Sleepy

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 value of the expression 33/10, assuming both values are integral data types, is ____. a. 0.3 b. 3 c. 3.0 d. 3.3

b. 3

The programming language C++ evolved from ____. a. C+ b. C c. assembly d. BASIC

b. C

____ is a parameterized stream manipulator. a. endl b. setfill c. scientific d. fixed

b. setfill

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

b. break

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​ What are the values after the following statement executes? ​ cin.get(ch1); cin.get(ch2); cin >> alpha; ​a. ch1 = 'A', ch2 = '1', alpha = 8 b. ch1 = 'A', ch2 = ' ', alpha = 18 c. ch1 = 'A', ch2 = '\n', alpha = 1 d. ch1 = 'A', ch2 = ' ', alpha = 1

b. ch1 = 'A', ch2 = ' ', alpha = 18

The memory allocated for a float value is ____ bytes. a. two b. four c. eight d. sixteen

b. four

The term GB refers to ____. a. giant byte b. gigabyte c. great byte d. group byte

b. gigabyte

Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. open.inFile("progdata.dat"); b. inFile.open("progdata.dat"); c. open(inFile,"progdata.dat"); d. inFile(open,"progdata.dat");

b. inFile.open("progdata.dat");

What does <= mean? a. less than b. less than or equal to c. greater than d. greater than or equal to

b. less than or equal to

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

b. looping

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____. a. one = 11, two = 31 b. one = 10.5, two = 30.6 c. one = 10.5, two = 10.5 d. one = 30.6, two = 30.6

b. one = 10.5, two = 30.6

Which of the following is a legal identifier? a. program 1 b. program_1 c. program! d. 1program

b. program_1

Main memory is called ____. Answers: a. read only memory b. random access memory c. random read only memory d. read and write memory

b. random access memory

Dividing a problem into smaller subproblems is called ____ design. Answers: a. analog b. structured c. OOD d. top-down refinement

b. structured

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ Choose the value of ch3 after the following statement executes: ​ cin >> ch1 >> ch2 >> ch3; ​a. 'A' b. 'B' c. 'C' d. '\n'

c. '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) c. (x > 0) || ( x <= 0) d. (x > 0) && (x == 0)

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

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

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.780 123.980 b. 1565.680 85.8000 123.98 c. 1565.683 85.7800 123.98 d. 1565.683 85.8000 123.98

c. 1565.683 85.7800 123.98

The length of the string "computer science" is ____. a. 14 b. 15 c. 16 d. 18

c. 16

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; a. 25.67 356.87 7623.96 b. 25.67 356.87 7623.97 c. 25.67 356.88 7623.97 d. 25.67 356.876 7623.967

c. 25.67 356.88 7623.97

The value of the expression 17 % 7 is ____. a. 1 b. 2 c. 3 d. 4

c. 3

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320

c. 300

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; a. 35 45 0 b. 35 45 80 c. 35 45 10 d. 35 45 -10

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

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

c. ==

The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer. Answers: a. RAM b. MM c. CPU d. ROM

c. CPU

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

____ are executable statements that inform the user what to do. a. Variables b. Named constants c. Prompt lines d. Expressions

c. Prompt lines

Which of the following is the newline character? a. \b b. \r c. \n d. \l

c. \n

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. a. alpha = 5 b. alpha = 10 c. alpha = 50 d. alpha = 50.0

c. alpha = 50

The digit 0 or 1 is called a binary digit, or ____ . a. bytecode b. Unicode c. bit d. hexcode

c. bit

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch = ' ', x = 276 b. ch = 'b', x = 76 c. ch = '2', x = 76 d. ch = '276', x = '.'

c. ch = '2', x = 76

____ loops are called posttest loops. a. while b. for c. do...while d. break

c. do...while

An example of a floating point data type is ____. a. short b. int c. double d. char

c. double

A(n) ____-controlled while loop uses a bool variable to control the loop. a. counter b. sentinel c. flag d. EOF

c. flag

When a continue statement is executed in a ____, the update statement always executes. a. switch structure b. while loop c. for loop d. do...while loop

c. for loop

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)

The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; b. int a b c; c. int a,b,c; d. int abc;

c. int a,b,c;

You can use either a(n) ____ or a ____ to store the value of a logical expression. a. float, string b. char, string c. int, bool d. float, double

c. int, bool

What executes immediately after a continue statement in a while and do-while loop? a. the body of the loop b. loop condition c. loop-continue test d. update statement

c. loop-continue test

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

c. nested

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 ​ Choose the values after the following statement executes: cin >> x >> y; a. x = 10, y = 20 b. x = 10, y = 20.0 c. x = 10, y = 20.7 d. x = 10, y = 21.0

c. x = 10, y = 20.7

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

d. !

For a program to use the assert function, it must include which of the following? a. #include <assertc> b. #include NDEBUG c. #include <assert> d. #include <cassert>

d. #include <cassert>

What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl; a. 0 b. 6 c. 8 d. 10

d. 10

What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; a. 123456789012345678901234567890 ####Mickey####Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald#####Goofy c. 23456789012345678901234567890 ****Mickey####Donald#####Goofy d. 123456789012345678901234567890 ####Mickey Donald*****Goofy

d. 123456789012345678901234567890 ####Mickey Donald*****Goofy

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

____ is a valid int value. a. 46,259 b. -32.00 c. 462.59 d. 46259

d. 46259

Which of the following operators has the lowest precedence? 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.

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure

d. This statement results in input failure

Suppose that x and y are int variables. Which of the following is a valid input statement? a. cout << x << y; b. cin << x << y; c. cin >> x >> cin >> y; d. cin >> x >> y;

d. cin >> x >> y;

A program called a(n) ____ translates instructions written in high-level languages into machine code. Answers: a. linker b. assembler c. decoder d. compiler

d. compiler

Which of the following loops is guaranteed to execute at least once? a. for loop b. counter-controlled while loop c. sentinel-controlled while loop d. do...while loop

d. do...while loop

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)

d. if (x = 5)

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

d. infinite

Main memory is an ordered sequence of items, called ____. Answers: a. addresses b. pixels c. registers d. memory cells

d. memory cells

What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } a. section 2 b. section 3 c. section 4 d. section 5

d. section 5

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​ Choose the values of x, y, and z after the following statement executes: ​ cin >> x >> y >> z; a. x = 28, y = 12, z = 0.6 b. x = 28, y = 12, z = 32.6 c. x = 28, y = 32, z = 12.0 d. x = 28, y = 32, z = 0.6

d. x = 28, y = 32, z = 0.6


Kaugnay na mga set ng pag-aaral

Chemical Reactions and Compounds Test- Mrs. Cyr

View Set

Conceptual integration & Phonation 1 (Chapter 5)

View Set