sharonkodali / sharonk

MIT License
0 stars 0 forks source link

2021 MCQ review #9

Open sharonkodali opened 4 months ago

sharonkodali commented 4 months ago

I got a 63/70 which is a 90%

Questions I missed

Q14 Error in isIncreasing Procedure

I chose B but this is incorrect because he procedure will immediately return true any time it encounters a value that is greater than or equal to the preceding value. It will not check any subsequent values in the list.

C is correct because the procedure traverses numberList from left to right and returns true whenever it encounters a value that is less than the preceding value. If it never encounters such a value, false is returned. This has the effect of returning true whenever the list is not increasing and returning false whenever the list is increasing, which is the opposite of what is intended. By interchanging lines 8 and 12, the procedure will return true or false appropriately.

Question 22 - Code segment that move robot along the same path

I chose answer D which is incorrect because The given code segment causes the robot to end in the lower-right corner of the grid, facing toward the top of the grid. In this code segment, count is 0 in the first iteration of the outer loop, so the robot rotates left, but does not move forward. The robot ends in the upper-right corner of the grid, facing toward the top of the grid.

Answer A is correct because the given code segment initializes count to 1 and increments count at the end of the outer loop. This causes the robot to move 1 square forward, then rotate left, then move 2 squares forward, then rotate left, then move 3 squares forward, then rotate left, then move 4 squares forward, then rotate left. The robot ends in the lower-right corner of the grid, facing toward the top of the grid. This code segment initializes count to 0 and increments count at the beginning of the outer loop. Because count is initialized to 0 and then immediately incremented inside the loop, the inner loop iterates the same number of times for each iteration of the outer loop as in the given code segment. The robot ends in the lower-right corner of the grid, facing toward the top of the grid.

Question 47- Expression to count restaurants

I chose D which is incorrect because the expression ill evaluate to true for restaurants with the correct price range or with the correct customer rating. The intent is for the expression to evaluate to true only for restaurants with the correct price range and the correct customer rating.

Answer B is correct because this expression evaluated to true only for restaurants with the correct price range

Question 53- Determine if target appeards in list multiple times

Choice B is incorrect because This algorithm will only display true if every element in the list is equal to target. In step 5, it is not possible for count to be greater than position, and count will only be equal to position if count was incremented for every element in the list.

A is correct because step 4 checks every element of the list, incrementing count each time target appears. Step 5 prints true if and only if count appears multiple times in the list.

Question 53-Inforation determined by delivery truck database

A is incorrect because the inormation can be determined by analyzing the dates and times that trucks entered and left the depot

B is correct because the data captured each time a truck enters or leaves the depot do not include any information about the number of customers or deliveries associated with the truck.

Question 55

A is incorrect because This code segment assigns the value of the last element of the list to the variable temp, then removes the last element of the list, then appends temp to the end of the list. The resulting list is the same as the original list.

C is correct because This code segment assigns the value of the last element of the list to the variable temp, then removes the last element of the list, then inserts temp as the first element of the list.

Question 64 Error in age procedure

D is incorrect because line 15 should not be remived sine the value of the result should be resturned at the end of the procedure after age is compared to both 65 and 18

C is correct because line 10 should be removed since it causes result too be assigned to the value adult even if it should have been assigned the value senior citizen.