Chapter 5
C# Programming: From Problem Analysis to Program Design · 15 exercises
Problem 1
The result of the expression if (aValue == 10) is: a. true or false b. 10 c. an integer value d. aValue e. determined by an input statement
3 step solution
Problem 2
. Which expression is evaluated first in the following statement? if(ƒaƒ>ƒbƒ&&ƒcƒ==ƒdƒ||ƒaƒ==ƒ10ƒ&&ƒbƒ>ƒaƒ+ƒ7)? a. a > b b. b && c c. d || a d. a + 7 e. none of the above
4 step solution
Problem 5
allows you to do the following: properly check the variable code to determine whether it contains the character \(C,\) and if it does, display "This … # Which statement in C# allows you to do the following: properly check the variable code to determine whether it contains the character \(C,\) and if it does, display "This is a check" and then advance to a new line? a. if code is equal to \(\mathrm{C}\) Console.WriteLine("This is a check"); b. if (code = "C") Console.WriteLine("This is a check"); c. if (code = = ' c' ) Console.WriteLine("This is a check"); d. if \((\operatorname{code}==c)\) Console.WriteLine("This is a check"); e. none of the above
6 step solution
Problem 6
What will be displayed from executing the following segment of code? You may assume testscore has a value of 90 a. You failed the test! b. You passed the test! c. You failed the test! You passed the test! d. You failed the test! You need to study for the next test! e. none of the above
4 step solution
Problem 7
The ___________ operator represents the logical AND. a. ++ b. || c. && d. @ e. none of the above
4 step solution
Problem 11
Which logical operator (op) is defined by the following table? (T and F denote true and false.) $$\begin{array}{ccc} \mathrm{P} & \mathrm{Q} & \mathrm{P} \circ \mathrm{p} \mathrm{Q} \\ \mathrm{T} & \mathrm{T} & \mathrm{T} \\ \mathrm{T} & \mathrm{F} & \mathrm{F} \\ \mathrm{F} & \mathrm{T} & \mathrm{F} \\ \mathrm{F} & \mathrm{F} & \mathrm{F} \end{array}$$ a. \(\mathrm{NOT}\) b. AND c. OR d. not enough information is given e. none of the above
3 step solution
Problem 12
Examine the code to complete the following question. (Be careful.) \\[ \begin{aligned} \text { if }(A&=B) ; \\ C &=3 ; \end{aligned} \\] When will C get the value of 3 ? a. when \(A\) is equal to \(B\) b. when \(A\) is not equal to \(B\) c. never d. every time the program is executed e. not enough information is given
4 step solution
Problem 13
Consider the following if statement, which is syntactically correct, but uses poor style and indentation: if \((x>=y)\) if \((y>0) x=x \star y ;\) else if \((y<4) x=x-y\) Assume that \(x\) and \(y\) are int variables containing the values 9 and 3 , respectively, before execution of the preceding statement. After execution of the statement, what value does \(x\) contain? a. 9 b. 1 c. 6 d. 27 e. none of the above
5 step solution
Problem 14
After execution of the following code, what will be the value of inputValue? int inputValue = 0; ifƒ(inputValueƒ>ƒ5) ƒƒƒƒinputValueƒ+=ƒ5; else ifƒ(inputValueƒ>ƒ2) ƒƒƒƒƒƒƒƒƒinputValueƒ+=ƒ10; elseƒinputValueƒ+=ƒ15; a. 15 b. 10 c. 25 d. 0 e. 5
4 step solution
Problem 15
If you intend to place a block of statements within an if statement, you must use ___________ around the block. a. parentheses b. square brackets c. quotation marks d. curly braces e. none of the above
4 step solution
Problem 17
What is the result of the following conditional expression when aValue \(=100\) and bvalue \(=7 ?\) result \(=\) avalue \(>\) bvalue \(+100 \quad ? 1000: 2000\) a. 0 b. 1000 c. 2000 d. 7 e. none of the above
5 step solution
Problem 19
Which of the following statements about logical operators is correct? a. Logical AND yields true if and only if both of its operands are either true or false. b. Logical OR yields true if either or both of its operands are true. c. Logical OR is represented in C# by && . d. Logical NOT is represented in C# by | . e. none of the above
5 step solution
Problem 20
The string data type can be used: a. as an operand for the == or != b. as an expression in the switch statement to be evaluated c. as an operand for the > or < operator d. a and b are correct e. all of the above
4 step solution
Problem 21
Assuming a is 5, b is 6, and c is 8, which of the following is false? a. a == 5; b. 7 <= (a + 2); c. c <= 4; d. (1 + a) != b; e. c >= 8; f. a >= 0; g. a <= (b * 2);
7 step solution
Problem 24
Rewrite the following compound expression as nested if statements. if ( (avalue > bvalue) \&\& (bvalue = = 10 )) Console.WriteLine("Test complete");
5 step solution