Chapter 3 : Selection Structure Flashcards

1
Q

What is a control structure?

A
  1. logical design that controls the order in which statements execute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a sequence structure?

A
  1. Set of statements that execute in the order that
    they appear
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What circumstances that lets decision structure execute statements execute its statements?

A
  1. Certain condition exists
  • Decision structure is also known as selection structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What type for expression on decision structure?

A
  1. Boolean expression that can be evaluated as either true or false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to write if statements in C#?

A

if ( expression )
{
statements
statements
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List out all relational operator ( 6 )

A
  1. >
  2. <
  3. > =
  4. <=
  5. ==
  6. !=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the format for if-else statement?

A

if ( expression )
{
statements
}
else
{
statements
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Format for Nested Decision Structures

A

if ( expression )
{
if ( expression )
{
statement
}
else
{
statement
}
}
else
{
statements
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Format for if-else-if statement

A

if ( expression )
{
}
else if ( expression )
{
}
else if ( expression )
{
}
else
{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

List out 3 logical operator

A
  1. && ( And )
  2. || ( Or )
  3. ! ( Not )
  • ! ( Not Operator )
    if ( ! ( temperature > 100 ) )
    {
    MessageBox.Show(“Ok”)
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does switch statement does?

A
  1. Lets the value of a variable or an expression determine which path of execution the program will take
  • It is a multiple-alternative decision structure
  • It can be used as an alternative to an if-else-if statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Format for switch statement

A

switch (testExpression)
{
case value_1:
statements
break
case value_n:
statements
break
default:
statements
break
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a testExpression in switch statement?

A
  1. Variable or an expression that given an integer, string, or bool value
  • It cannot be floating-point or decimal value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

List out 3 methods for comparing strings

A
  1. Use == operator
    string n_1 = “Mark”
    string n_2 = “Max”

if ( n_1 == n_2 )
{
}

  1. Compare string variables with string literals
    if ( n_1 = “Max” )
    {
    }
  2. Use String.Compare
    string n_1 = “Mark”
    string n_2 = “Max”

if ( String.Compare(name1,name2)==0 )
{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List out the syntax for preventing data conversion exception

A

int.TryParse( string , out targetVariable )

  • Examples
    • int.TryParse
    • double.TryParse
    • decimal.TryParse
  • out keyword is required, it specifies that the targetVariable is an output variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is input validation?

A
  1. The process of inspecting data that has been entered into a program to make sure it is valid before it is used

if ( hours > 0 && hours <= 168 )
{
}
else
{
}

  • TryParse methods check if the user enters the data, but it doesn’t check the integrity of the data
17
Q

What is the difference between Radio Buttons & Check Boxes?

A
  1. Radio Buttons allow usrs to select one choice from several possible choices
  2. Check boxes allows users to select multiple options
18
Q

By clicking on a radio button, the program automatically deselects any others, this is known as what?

A
  1. Mutually exclusive selection
19
Q

What is the common properties for RadioButton ? ( 2 )

A
  1. Text
    • Holds the text that is displayed next to the radio button
  2. Checked
    • A boolean property that determines whether the control is selected or deselected
20
Q

How to determine whether a RadioButton is selected?

A

if ( choiceRadioButton.Checked ) {
}
else{
}

  • Is Same As

if ( choiceRadioButton.Checked == true ) {
}
else{
}

21
Q

What is raised when a RadioButton or CheckBox control’s Checked property changes?

A
  1. CheckedChanged event
  • I can write codes to respond to the event
  • I can click the control in the Designer to create an empty CheckedChanged event

private void yellowRadioButton_CheckedChanged(object sender, EventArgs e) { }

22
Q

What is a list box?

A
  1. Display a list of items and allow the user to select an item from the list
23
Q

List out 4 commonly used properties for the List Box

A
  1. Text
    • Gets or searches for the text of the currently selected item in the List Box
  2. Items
    • Gets the items of the ListBox
  3. SelectedItem
    • Get or sets the currently selected item in the ListBox
  4. SelectedIndex
    • Gets or sets the zero-based index of the currently selected item in a ListBox
24
Q

What will occur when I try to get the value of a ListBox SelectedItem property when no item is selected?

A
  1. Exception will occur
25
Q

What is the starting index for SelectedItem property?

A
  1. 0
26
Q

What is the index for SelectedIndex when there is no item selected?

A
  1. -1
  • Selection Structure to check if user didn’t select anything
    if (fruitListBox.SelectedIndex != -1) { }