0% found this document useful (0 votes)
27 views

Ch04 Drake Csharp 5e

The document is a chapter from a textbook about making decisions in programming. It covers topics like if/else statements, logical operators, relational operators, and data validation. It includes true/false and multiple choice questions about these concepts. Some key points covered are: - If/else and else if statements allow conditional execution of code - Logical operators like &&, ||, and ! are used to combine Boolean expressions - Relational operators like ==, <, > are used to compare values - Data validation ensures user input meets required criteria

Uploaded by

778nick
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Ch04 Drake Csharp 5e

The document is a chapter from a textbook about making decisions in programming. It covers topics like if/else statements, logical operators, relational operators, and data validation. It includes true/false and multiple choice questions about these concepts. Some key points covered are: - If/else and else if statements allow conditional execution of code - Logical operators like &&, ||, and ! are used to combine Boolean expressions - Relational operators like ==, <, > are used to compare values - Data validation ensures user input meets required criteria

Uploaded by

778nick
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Starting Out with Visual C#, 5e (Tony Gaddis)

Chapter 4 Making Decisions

TRUE/FALSE

1. The sequence structure is often used in programming because it can handle every type of task.

ANS: F

2. If you are writing an if statement that has only one conditionally executed statement, you must
enclose the conditionally executed statement in curly braces.

ANS: F

3. The equality operator is written like this: = (with only one equals sign).

ANS: F

4. It is often true that both sets of conditionally executed statements in an if-else statement are
executed.

ANS: F

5. Any if-else-if statement can be coded, alternatively, as a nested if-else statement.

ANS: T

6. In order for an && expression to be true, only the expression on one side of the && operator needs to
be true.

ANS: F

7. If the expression on the left side of the || operator is true, the expression on the right side is not
checked.

ANS: T

8. The == operator cannot be used to compare string expressions.

ANS: F

9. You should use try-catch statements primarily for exceptions that are beyond your control.

ANS: T

10. Because the TryParse methods return either true or false, they are commonly called as the
Boolean expression in an if statement.

ANS: T

11. Check boxes are similar to radio buttons in that they are both mutully exclusive.
ANS: F

12. A switch statement's test expression can be any data type.

ANS: F

13. When displaying an item from a ListBox, you have to call the SelectedItem property's ToString
method to retrieve the value as a string.

ANS: T

14. RadioButton controls are grouped according to the container in which they are placed.

ANS: T

15. A well-designed program should validate the contents of multiple TextBoxes in a single statement.

ANS: F

16. When a program compares characters, it actually compares the numeric Unicode values of the
characters.

ANS: T

17. Variables of the double data type are commonly used as flags.

ANS: F

18. The ! operator has a higher precedence than the relational operators such as < or >.

ANS: T

19. If an expression A is true, prefixing it with the ! operator (!A) causes the combined expression to
become false.

ANS: T

20. In a flowchart, the diamond symbol indicates some condition that must be tested.

ANS: T

MULTIPLE CHOICE

1. A __________ appears as a small box with some accompanying text.


a. list box c. check box
b. link d. radio button
ANS: C

2. When a RadioButton or a CheckBox control's Checked property changes, a __________ event


happens for that control.
a. SelectionChanged c. CheckChanged
b. Checked d. Click
ANS: C

3. When you want to create a check box on a form, you use the __________ control which is found in the
Common Controls section of the Toolbox.
a. CheckBox b. RadioButton c. ListBox d. LinkLabel
ANS: A

4. The __________ statement is a multiple-alternative decision structure which allows you to test the
value of a variable or an expression and then use that value to determine which statement or set of
statements to execute.
a. switch b. if c. try-catch d. else
ANS: A

5. In Visual C# you use the __________ control to create a list box on an application's form.
a. ListView c. CheckedListBox
b. MaskedTextBox d. ListBox
ANS: D

6. Once you create a ListBox control, you add items you wish to display to its __________ property.
a. Display b. Text c. Items d. Values
ANS: C

7. When the user selects an item in a ListBox, the item is stored in the ListBox's __________ property.
a. Checked c. DataSelection
b. SelectedValue d. SelectedItem
ANS: D

8. Each item in a ListBox has a(n) __________ which is an integer that identifies the item's position in
the ListBox.
a. index c. unique identifier
b. list number d. table key
ANS: A

9. When the user selects an item in a ListBox, the item's index is stored in the ListBox's __________
property.
a. DataValue c. Index
b. SelectedIndex d. ValueIndex
ANS: B

10. If no item is selected in a ListBox, what value is in the SelectedIndex property?


a. false b. true c. 0 d. -1
ANS: D
11. A(n) __________ structure is a logical design that controls the order in which a set of statements
execute.
a. elementary b. logic c. control d. sequence
ANS: C

12. A(n) __________ structure is a set of statements that execute in the order in which they appear.
a. ordered b. command c. control d. sequence
ANS: D

13. A(n) __________ structure can execute a set of statements only under certain conditions.
a. sequence b. decision c. circumstantial d. event
ANS: B

14. An action that is __________ occurs only when a certain condition is true.
a. conditionally executed c. interactively driven
b. logically executed d. truth bound
ANS: A

15. A(n) __________ decision structure provides only one path of execution.
a. alternative path c. single path
b. single-alternative d. ordered path
ANS: B

16. A __________ expression is an expression that can be evaluated as either true or false.
a. binary b. double c. Boolean d. classical
ANS: C

17. A(n) __________ compares the values of two expressions.


a. relational operator c. associative operator
b. bitwise assessment d. comparative structure
ANS: A

18. Which of the following expressions determines whether the value of the variable named length is
greater than or equal to the value of the variable named width?
a. length < width
b. width <= length
c. length > width
d. length >= width
ANS: D

19. Which of the following expressions determines if the value of the variable named balance is equal
to 0?
a. 0 = balance c. balance = 0
b. balance == 0 d. balance <= 0
ANS: B

20. A(n) __________ statement has two parts: an if clause and an else clause.
a. logic b. if-else c. Boolean d. else-if
ANS: B

21. The __________ structure has two possible paths of execution. One path is taken if the Boolean
expression is true and the other path is taken if the Boolean expression is false.
a. dual-alternative decision c. multi-decision
b. comparative d. branching
ANS: A

22. The C# language provides a set of operators known as __________ operators which you can use to
create complex Boolean expressions.
a. Boolean c. logical
b. relational d. expressional
ANS: C

23. The __________ operator is the logical AND operator which takes two Boolean expressions as
operands and creates a compound Boolean expression that is true only when both subexpressions are
true.
a. ! b. <> c. && d. ||
ANS: C

24. The __________ operator is the logical OR operator which takes two Boolean expressions as operands
and creates a compound Boolean expression that is true when either of the subexpressions is true.
a. ! b. <> c. && d. ||
ANS: D

25. The __________ operator is the logical NOT operator which is a unary operator that takes a Boolean
expression as its operand and reverses its logical value.
a. ! b. <> c. && d. ||
ANS: A

26. Both the && and || operators perform __________ in which CPU time is saved by not checking the
expression on the right side of the operator depending on the value of the expression on the left side of
the operator.
a. logical optimization c. cycle-branching
b. short-circuit evaluation d. single-stage execution
ANS: B

27. The expression given below will determine if the value in A is outside a range, if XX is replaced by
which logical operator?
(A < 1) XX (A > 10)
a. && b. ! c. || d. >=
ANS: C

28. The expression given below will determine if the value in A is inside a range, if XX is replaced by
which logical operator?
(A < 1) XX (A > 10)
a. && b. ! c. || d. >=
ANS: A

29. You can use the __________ logical operator to compare two strings.
a. && b. == c. || d. !
ANS: B

30. The __________ method can be used to determine whether one string is greater than or less than
another string.
a. String.Equals c. String.IsGreater
b. String.Compare d. String.String
ANS: B

31. The __________ method can determine whether a string contains a value that can be converted to a
specific data type before it is converted to that data type.
a. Parse c. Peek
b. TryParse d. String.Compare
ANS: B

32. The __________ method can be used to convert a string to an integer.


a. Try.Parse.int c. int.TryParse
b. int.Parse d. TryParse.int
ANS: C

33. To convert a string to a double, use the __________ method.


a. String.ToDouble c. Try.ParseDouble
b. double.TryParse d. ToString
ANS: B

34. A string can be converted to a decimal with the __________ method.


a. decimal.ParseString c. Try.Parse(decimal)
b. decimal.ToString d. decimal.TryParse
ANS: D

35. The __________ keyword is required when specifying a variable as an output argument.
a. in b. out c. extern d. static
ANS: B

36. A(n) __________ is a variable that is passed as an argument to a method and, when the method is
finished, a value is stored in the variable.
a. output variable c. parameter variable
b. result variable d. method variable
ANS: A

37. The process of checking input for errors before it is processed is called __________.
a. parsing c. pre-rendering
b. input validation d. data authentication
ANS: B

38. __________ are useful when you want the user to select one choice from several possible choices.
a. Radio buttons c. Buttons
b. Check boxes d. Text boxes
ANS: A

39. __________ selection works by automatically deselecting any other items in the same group when a
single item is selected.
a. Multiple c. Mutually exclusive
b. Mutually inclusive d. Monographic
ANS: C

40. Radio button controls have a __________ property that determines whether the control is selected or
deselected.
a. Selected b. Checked c. Pushed d. Active
ANS: B

You might also like