CIS115 WEEK 3 QUIZ

01 August, 2024 | 4 Min Read

CIS115 WEEK 3 QUIZ

( CORRECT ANSWERS ARE IN BOLD LETTERS )

Question 1 2 / 2 pts

( TCO 4) In a decision structure, the _____ clause executes when the condition is true.

If

While

Else

Case

Instructor Explanation: See Chapter 4, Lecture.

Question 2

0 / 2 pts

(TCO 4) If an expression contains relational, logical, and arithmetic operators, which type of operator is evaluated last? Logical

Relational

Arithmetic

Depends on the expression

Instructor Explanation: See Chapter 4, Lecture.

Question 3

0 / 2 pts

(TCO 4) In order to have the most efficient program, which question should be asked first when using an || (or) decision?

There is no way to determine this.

The one that is less likely to be true.

The one with the lower values.

The one that is more likely to be true.

Instructor Explanation: See Chapter 4, Lecture.

Question 4

2 / 2 pts

(TCO 4) If a valid score is between 0 and 100, which Boolean expression is true if the value in the score variable is valid?

score > 0 || score < 100 score >= 0 || score <= 100 score >= 0 && score <= 100 score < 0 && score > 100

Instructor Explanation: See Chapter 4, Lecture.

Question 5

2 / 2 pts

( TCO 4) Evaluate each of the following conditions (as being true or false). Assume A

= 3, B = 6, C = 3, and D = 18.

C <= 3 AND D < A

True

False

Instructor Explanation:

C = 3, so 3 <= 3? is true. 18 < 3 is false. True AND false is false.

Question 6

2 / 2 pts

( TCO 4) Evaluate each of the following conditions (as being true or false). Assume A

= 3, B = 10, and Z = ā€œfiveā€.

A * 2 > B / 2 AND Z > ā€œtwoā€

True

False

Instructor Explanation:

Evaluates to 3 * 2 > 10 / 2 AND ā€œfiveā€ < ā€œtwoā€. 6 > 5 AND ā€œfiveā€ > ā€œtwoā€. 6 > 5 is true. ā€œfiveā€ > ā€œtwoā€ is false because ā€œfiveā€ comes alphabetically after ā€œtwoā€. So true AND false = false.

Question 7 2 / 2 pts

( TCOs 3 and 4) Given the following If structure, assume B = 100. Which will be the output?

B

Missed It!

You got an A

100

Instructor Explanation:

B = 100, so (100 >= 90 AND 100 <= 100) evaluates to (true AND true) = true, so ā€œYou got an Aā€ is output.

Question 8 2 / 2 pts

( TCOs 3 and 8) Which will be displayed after the following process is completed?

        Start

                    Set x = 3

                    Set y = 2                                   

                    Set z = 3

                    If ((x = 1) OR (y = 1) OR (z = 1)) then

                                Set ans = ā€œTrueā€

                    Else      

                                Set ans = ā€œFalseā€

                    End if

                    Display ans 

        Stop

True

False

Instructor Explanation:

( x = 1) OR (y = 1) OR (z = 1) evaluates to (3 = 1) OR (2 = 1) or (3 = 1), which evaluates to (false) or (false) or

( false) = false, because in an Or expression one of the conditions must be true, so ā€œFalseā€ is displayed.

Question 9

2 / 2 pts

( TCO 8) Which will be displayed after the following process is completed?

        Start

Set w = 0

                    Set x = 1

                    Set y = 2

                    Set z = 3

                    If ((w \<> 0 OR x = 1) AND (y = 2 OR z \<> 3)) then

                                Set ans = ā€œTā€

                    Else

                                Set ans = ā€œFā€

                    End if

                    Display ans 

        Stop

True

False

Instructor Explanation:

(w <> 0 OR x = 1) AND (y = 2 OR z <> 3) evaluates to (0 <> 0 OR 1 = 1) AND (2 = 2 OR 3 <> 3), evaluates to

( false OR true) AND (true OR false) = (true) AND (true) = true, because in And expressions, all the conditions must be true. Thus, ā€œTā€ is displayed.

Question 10 0 / 2 pts

( TCO 8) Which will be displayed after the following process is completed?

        Start

Set grade = ā€œCā€

                    If (grade \<> ā€œAā€ AND grade \<> ā€œBā€ AND grade \<> ā€œCā€

                                AND grade \<> ā€œDā€ AND grade \<> ā€œFā€) then

                                Set message = "invalid grade"

                    Else

                                Set message = "valid gradeā€œ

                    End if

                    Display message             Stop

invalid grade valid grade

Instructor Explanation:

grade <> ā€œAā€ AND grade <> ā€œBā€ AND grade <> ā€œCā€ AND grade <> ā€œDā€ AND grade <> ā€œFā€ evaluates to ā€œCā€ <> ā€œAā€ AND ā€œCā€ <> ā€œBā€ AND ā€œCā€ <> ā€œCā€ AND ā€œCā€ <> ā€œDā€ AND ā€œCā€ <> ā€œFā€ evaluates to true AND true AND false AND true AND true = false, so “valid grade” will be displayed.

Related posts