Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below you will see psuedocode, please debug the code (find the errors) and make

ID: 3733312 • Letter: B

Question

Below you will see psuedocode, please debug the code (find the errors) and make the correct changes to psuedocode.

// This application reads 10 numbers and sorts them,
// then displays the three highest numbers

start
Declarations
  num SIZE = 10
  num number
  num numbers[SIZE]
  num count = 0
  getReady()
while count <= SIZE
  detailLoop()
  endwhile
finish()
stop

getReady()
output "Enter a number "
input number
return

detailLoop()
numbers[count] = number
output "Enter a number "
input number
return

finish()
sort()
output "The highest three are ", numbers[1], numbers[2], numbers[3]
return

sort()
  num x = 0
  num y = 0
  num COMPS = count - 1
while y < COMPS
while x < COMPS
if numbers[x] < numbers[x] then
swap()
  endif
x = x + 1
  endwhile
y = y + 1
  endwhile
return

swap()
  num temp
temp = numbers[x + 1]
numbers[x + 1] = numbers[x]
numbers[x] = temp
return

Explanation / Answer

Psuedocode:

Correction in the function detailLoop()

detailLoop()

numbers[count] = number ...............................//The array index must be count and not SIZE

count = count + 1

output "Enter a number "

input number

return

______________________________________________________

Corrections in sort() function

sort()

num x = 0

num y = 0

num COMPS = count - 1

while y < COMPS

x = y + 1.....................................// In selection-sort the inner loop variable always starts at one value more than the outer-loop variable

while x < COMPS

if numbers[x] < numbers[x + 1] then

swap()

endif

x = x + 1

endwhile

y = y + 1

endwhile

return

_____________________________________________

finish()

sort()

output "The highest three are ", numbers[0], numbers[1], numbers[2].// First three elements of the array

return

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote