











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












b. 0 <= x <= 100 c. 0 == 0 && x < 100 d. 0 <= x | x <= 100 e. 0 <= x && x < 100 f. 0 <= x || x <= 100 g. -1 < x < 101 h. 0 <= x & x <= 100 i. 0 < x < 100 j. x < 0 || x > 100
g. Once h. 40 times i. 41 times j. 50 times
d. 0.8 is less than or equal to 1 e. 1 is less than or equal to 25 f. 1 is greater than or equal to 1 g. ab/70 is greater than or equal to c/2 h. ab/70 is less than or equal to c/2 i. 0 is greater than or equal to 1 j. 0 is less than or equal to 1
int x = 10, y = 0; for (int i=10; i>50; i=i+1) { cin >> x; y = y + x; } a. Until a number larger than 10 is entered b. 49 times c. 50 times d. 40 times e. Twice f. Zero g. 51 times h. 41 times i. 39 times j. Once
e. 6.0e+ f. 73. g. 60. h. 61 i. 70. j. 73
On the other hand, if num2 is an odd value, say, 21 , then the if condition would be evaluated as 21 % 2 == 0 which reduces to 1 == 0 which is FALSE , and which will cause the cout statement within the else block to be executed: second option Hence the condition num2 % num1 == 0 causes the if block to be executed whenever num2 is even, and the else block otherwise. Correct Answer: x < 0 || x > 100 Feedback: Since the value of x is to be checked against two ranges, the condition must be expressed using a logical OR expression. The expression x < 0 || x > 100 will be evaluated as (x < 0) || (x > 100) The first expression checks if x is less than 0 , and the second expression checks if x is greater than 100. The entire expression evaluates to TRUE if either expression evaluates to TRUE. Hence, the expression x < 0 || x > 100 is TRUE if and only if the value of x does not lie between 0 and
Correct Answer: red blue green yellow Feedback: When the switch statement is executed with a value of 0, the label case 0: will be executed. However, due to absence of any break or return statements, execution will continue down until the end of the switch block. This will execute all the cout statements in sequence. The output therefore will be: red blue green yellow Correct Answer: central processing unit Correct Answer: 41 times Feedback: The variable i has an initial value of 10 and is incremented by 1 for
every execution of the for loop. The statements within the for loop do not change the value of the variable i. The for loop is executed aslong as the variable i is less than or equal to 50 ; that is, the variable i is incremented from 10 through 51. When i reaches the value of 51 , the condition i<= will evaluate to FALSE and the loop will not be executed. Hence, the loop will be executed for values of i from 10 up through 50. This means that the body of the loop will be executed 41 times. Correct Answer: Statements (3) and (1) are true. Feedback: Explanation (1) This statement is FALSE: The three primary control structures are: 1. Sequential (Statements executed sequentially one after the other) 2. Selective (if-then-else, switch-case-default statements) 3. Repetition (while, for and do-while loops) (2) This statement is TRUE: The statement if (x = 10) assigns 10 to x before evaluating the expression. The expression returns the value of x, which is 10. This condition evaluates to TRUE and the cout statement will be executed. As a result, x is 10 is always displayed regardless of the earlier value of x. (3) This statement is TRUE: The expression ( < 20 || 20 >= 20) will be evaluated as: (TRUE || TRUE) The result of the expression will be TRUE. Correct Answer: 0 is less than or equal to 25 Feedback: The if statement will be evaluated as: if ((87)/70 >= (10/2)5) which reduces to: if (56/70 >= 5*5) which reduces to (the integer-integer division 56/70 is 0): if (0 >= 25) The if statement will therefore evaluate to FALSE; and hence, the else block will be executed. The output will therefore be: 0 is less than or equal to 25
value returned by the pow function is a double, the output displayed will be: 1. Correct Answer: 3 is greater than or equal to 4 Feedback: The if statement will be evaluated as: if ( ((8/10)5)+3 > (10/5)2 )** which reduces to: if ((05)+3 > (22))** which reduces to: if ((0+3) > 4) which reduces to: if (3 > 4) The if statement will therefore evaluate to FALSE ; and hence, the else block will be executed. The output will therefore be: 3 is greater than or equal to 4 Correct Answer: zero Feedback: Explanation The condition i> will be evaluated before every execution of the loop, including the very first time. The variable i has an initial value of 10, and hence the condition will immediately evaluate to FALSE and the loop will not be executed. This means that the body of the loop will be executed 0 times. Correct Answer: Logic errors make output indeterminable because code may act differently on different compilers. Feedback: Correct Answer: 40 Correct Answer: Statements (3) and (1) are true. Feedback: (1) This statement is TRUE.
Note that the character string "program.data" contains the name of the file to be read from. This particular filename is perfectly legal (it does not have to end with .TXT or .DAT). Note that outfile is a variable associated with file input because of ifstream. This particular variable name is perfectly legal (as would be aaa or infile). (2) This statement is FALSE. It is not necessary for a for loop to be executed at least once. For instance, consider the following: int i; for (i=101; i<100; i++) { // ... } The expression i< is evaluated before every iteration of the loop, including the very first time. In the above case, the variable i has an initial value of 101 and hence the expression i< will evaluate to FALSE , and the for loop will not be executed at all. (3) This statement is TRUE Correct Answer: line 3 Feedback: The output operator for a cout object is '<<' and not '>>' Correct Answer:
Feedback: The ***** and / operators have higher precedence than the + operator. Hence, the expression int n = (4.0 + 6.1) * 7 + 5 / 2. will be evaluated as int n = (10.1) * 7 + (5 / 2.0) which reduces to int n = 70.7 + (5 / 2.0) which reduces to int n = 70.7 + 2. which reduces to int n = 73. However, since n is an int , it cannot have any fractions. The value of