QUESTION IMAGE
Question
- the algorithm below is not working correctly. which line of code will make it work as intended?
(compare cars to available parking spots)
availslots ← 180
parkinglot ←
repeat until (availslots = 0)
{
availslots ← availslots − 1
}
display (parkinglot)
a. append(parkinglot, availslot)
b. remove(parkinglot, availslot)
c. insert(parkinglot, availslot, name)
d. repeat until (length(parkinglot) = length(availslots))
- which line of code can be placed inside the braces {} to fix the following loop so it will not be an infinite loop?
name ← \ \
repeat until (name = \done\)
{
display (\student name is: \, name)
}
a. if name ≠ \done\)
b. count = count + 1
c. name ← input()
d. name ← studentroster
Question 5
The algorithm is about comparing cars to available parking spots. The parkingLot is an empty list, and we need to add parking spots (or related info) to it as we decrement availSlots. The APPEND function is used to add an element to a list. Option A's APPEND(parkingLot, availSlot) would add the relevant slot info to the parkingLot list, which makes sense for tracking parking spots. Option B is for removal, which is not needed. Option C has an extra name parameter and INSERT is not the right operation here. Option D changes the loop condition in a way that doesn't align with the intended task of populating the parking lot.
The loop is REPEAT UNTIL (name = "done"), but currently, name is initialized to a space and never changes, causing an infinite loop. To fix this, we need to update name inside the loop. Option C's name ← INPUT() gets user input, which will update name each iteration, allowing the loop to end when "done" is entered. Option A is an incomplete IF statement. Option B's count is not related to changing name. Option D's studentRoster is not defined or related to updating name for the loop condition.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
A. APPEND(parkingLot, availSlot)