click below
click below
Normal Size Small Size show me how
Computer Science E#2
| Question | Answer |
|---|---|
| Relational and logical expressions allow to incorporate decision making into programs. | True |
| In C++, both ! and != are relational operators. | False |
| In C++, !, &&, and || are called relational operators. | False |
| The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. | False |
| The value of the expression 'a' < 'A' is true. | False |
| In C++, all relational operators are evaluated before logical operators. | False |
| If a semicolon is placed after the expression in an if...else statement, the else statement is always executed. | False |
| The expression in the following if statement evaluates to true only if the value of score is 50. if (score = 50) grade = 'Z'; | False |
| In a switch statement, every case must have a break. | False |
| To use the predefined function abs, the program must include the header file ctype. | False |
| To use a predefined function, the program must include the appropriate header file. | True |
| To use a predefined value-returning function in a program, the programmer only needs to know the appropriate header file, the name of the function, and the type of the value returned by the function. | False |
| Which of the following is a relational operator? | == |
| Suppose that x is an int variable. Which of the following expressions always evaluates to true? | (x > 0) || (x <= 0) |
| Which of the following operators has the highest precedence? | ! |
| Which of the following expressions correctly determines that x is greater than 10 and less than 20? | 10 < x && x < 20 |
| When one control statement is located within another, it is said to be ____. | nested |
| Which of the following will cause a logical error if you are attempting to compare x to 5? | if( x = 5) |
| To use the predefined function fmod, the program must include the header file ____. | <cmath> |
| The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____. | 8.0 |
| The ++ operator | All of the above |
| A for statement contains three expressions: initialization, test, and | update |
| An End-of-File type of loop is in the category of Event-controlled loops. | True |
| num = 5; num++; cout << num << " "; --num; cout << num << " "; num--; cout << num; If the code above is executed what is the output? | 6 5 4 |
| Something within a while loop must eventually cause the condition to become false, or a(n) ________ results. | infinite loop |
| A ________ is a special value that marks the end of a list of values. | sentinel |
| The statements in the body of a while loop will never be executed if the test condition | is initially false |
| The statements in the body of a do-while loop will always be executed | at least once |
| The ideal loop to use for validating a value entered at the keyboard is | do-while |
| for (outcount = 1; outcount <= 2; outcount++ ) { for (incount = 1; incount <= 3; incount++ ) cout << incount << ' '; cout << endl; } What is the output after the statements above execute? | 123 123 |
| The do-while loop is considered a pretest loop. | False |
| The while loop has two important parts: an expression that is tested for a true or false value, and a | statement or block that is repeated as long as the expression is true |
| The block of code that follows a while condition can contain an unlimited number of statements, provided they are enclosed in braces. | True |
| A while loop requires a semicolon after the test expression and before the body of the loop. | False |
| When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop. | False |
| In a for statement, the ________ expression is executed only once. | initialization |
| You may define a ________ in the initialization expression of a for loop. | variable |
| If you want to stop a loop before it goes through all its iterations, the break statement can be used. | True |
| The ________ statement may be used to skip the rest of a loop's current iteration and begin the next one. | continue |
| If the code below is executed, the output will be: int x = 3; do { cout<<x<<" "; x--; } while(x > 1); | 3 2 |
| If the code below is executed, the output will be: int counter = 1; while(counter != -8) { cout << counter << " "; counter = counter - 2; } | an infinite loop |
| If the code below is executed and the user enters 10 20 30 40 -1, the output will be: int num, accu = 0; cin>>num; while(num != -1) { cin>>num; accu = accu + num; } cout<<accu<<endl; | 89 |
| If the code below is executed and the user enters 10 20 30 40 -1, the output will be: int num, accu = 0; cin>>num; while(num != -1) { accu = accu + num; cin>>num; } cout<<accu<<endl; | 100 |
| A loop is a control structure that allows you to repeat a set of statements until certain conditions are met. | True |
| In a counter-controlled while loop, the loop control variable must be initialized before the loop. | True |
| In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered. | True |
| The control variable in a flag-controlled while loop is a bool variable. | True |
| In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s). | looping |
| What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout << count << " " << num << endl; | 25 1 |
| Assume all variables are properly declared. What is the output of the following C++ code? num = 100; while (num <= 150) num = num + 5; cout << num << endl; | 155 |
| Consider the following code. int limit; int counter = 0; cin >> limit; while (counter < limit) { cin >> entry; triple = entry * 3; cout << triple; counter++; } cout << endl; This code is an example of a(n) ____ while loop. | counter-controlled |
| A(n) ____-controlled while loop uses a bool variable to control the loop. | flag |
| 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. | EOF-controlled |
| What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout << j << " "; cout << j << endl; | 10 11 |
| 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; | 24 |
| Which executes first in a do...while loop? | the body of the loop |
| Which of the following is true about a do...while loop? | The body of the loop is executed at least once. |
| Which of the following loops is guaranteed to execute at least once? | do-while loop |
| What executes immediately after a continue statement in a while and do-while loop? | the evaluation of the expression controlling the loop |
| When a continue statement is executed in a ____, the update statement always executes. | for loop |