selection Flashcards

(11 cards)

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

What does the conditional (age <= 5) ? “Infant” : (age <= 12) ? “Child” : … represent?

A

It uses the ternary operator to assign an age group based on the age input.

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

Rewrite a nested ternary operator using if…else if…else.

A

if (age <= 5) AgeGroup = “Infant”;
else if (age <= 12) AgeGroup = “Child”;

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

What is the purpose of switch statements in selection?

A

To simplify multiple conditional branches comparing a single variable.

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

What operator is used for combining conditions?

A

Logical operators like &&, ||.

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

What is the output of: (x > 10) && (x < 75) if x = 20?

A

true

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

When should you use else if instead of separate if blocks?

A

When conditions are mutually exclusive.

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

Which statement assigns “PASS” if average is 55?

A

if (avg < 60) grade = “PASS”;

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

What is a nested if statement?

A

An if statement inside another if.

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

How would you write a simple grade classifier using if?

A

if (avg < 50) grade = “FAIL”;
else if (avg < 60) grade = “PASS”;

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

Can switch be used with strings in C#?

A

Yes, C# supports switch on strings.

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