The assignment below has three pseudocodes below I need to fix the debug exercises in it. Please help. Thanks. Highlight or mark in bold the corrections. Thanks!
//DEBUG06-01
// A high school is holding a recycling competition,
// and this program allows a user to enter a student's
// year in school (1 through 4) and number of cans collected
// for recycling. Data is entered continuously until the user
// enters 9 for the year.
// After headings, output is four lines --
// one for each school year class.
// There are 4 errors
start
Declarations
num year
num cans
num SIZE = 4
num collectedArray[SIZE] = 0, 0, 0
string HEAD1 = "Can Recycling Report"
string HEAD2 = "Year Cans Collected"
output "Enter year of student or 9 to quit "
input year
while year <> 9
output "Enter number of cans collected "
input cans
collectedArray[year - 1] = collectedArray[year] + cans
output "Enter year of student or 9 to quit "
input year
endwhile
output HEAD1
output HEAD2
year = 1
while year < SIZE
output year, collectedArray[year]
year = year + 1
endwhile
stop
//DEBUG06-02
// Program lets user input scores on four tests
// Average is computed and letter grade is determined
// Letter grades are based on 90 for an A, 80 for a B, and so
on
// There are 5 errors
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
string QUIT = "ZZZZZ"
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
num total
num average
num sub
output "Enter student name or ", QUIT, " to quit "
input name
while name <> QUIT
sub = 0
total = 0
while sub < NUM_TESTS
output "Enter score "
input score
total = score
endwhile
sub = 0
while average < RANGES
sub = sub + 1
endwhile
letterGrade = GRADES[sub]
output name, letterGrade
output "Enter student name or ", QUIT, " to quit "
input lettergrade
endwhile
stop
//DEBUG06-03
// This program counts how many sales are made
// in each of five categories of products
// There are 4 errors
start
Declarations
num category
num SIZE = 5
num sales[SIZE] = 0, 0, 0, 0, 0
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
output "Enter category or 9 to quit "
input category
while category = 9
if category > 1 AND category < SIZE then
sales[category - 1] = sales[category - 1] + 1
else
output "Invalid category"
endif
endwhile
output HEAD1
output HEAD2
while category < SIZE
output category + 1, sales[category]
category = category + 1
endwhile
stop
Note: The lines which have errors are marked bold and the correction made is highlighted in red color.
//DEBUG06-01
start
Declarations
num year
num cans
num SIZE = 4
num collectedArray[SIZE] = 0, 0, 0, 0 // Size of array is 4 so we
should initialize whole array to 0
string HEAD1 = "Can Recycling Report"
string HEAD2 = "Year Cans Collected"
output "Enter year of student or 9 to quit "
input year
while year <> 9
output "Enter number of cans collected "
input cans
collectedArray[year - 1] = collectedArray[year - 1] + cans // assuming 0 based
indexing
output "Enter year of student or 9 to quit "
input year
endwhile
output HEAD1
output HEAD2
year = 1
while year <=
SIZE // year should be from 1 to 4 so it should
be less than or equal to SIZE
output year, collectedArray[year - 1] // again 0 based
indexing
year = year + 1
endwhile
stop
----------------------------------------------------------------------------------------------
//DEBUG06-02
// Program lets user input scores on four tests
// Average is computed and letter grade is determined
// Letter grades are based on 90 for an A, 80 for a B, and so
on
// There are 5 errors
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
string QUIT = "ZZZZZ"
string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F"
num total
num average
num sub
output "Enter student name or ", QUIT, " to quit "
input name
while name <> QUIT
sub = 0
total = 0
while sub < NUM_TESTS
output "Enter score "
input score
total = total +
score // score should be adding into total
sub = sub + 1 // incrementing sub otherwise while loop condition will never satisfy
endwhile
average =
total/NUM_TESTS // calculating average
sub = 0
while average < RANGES
sub = sub + 1
endwhile
string letterGrade =
GRADES[sub] // string letterGrade was not declared
before
output name, letterGrade
output "Enter student name or ", QUIT, " to quit "
input name
endwhile
stop
----------------------------------------------------------------------------
//DEBUG06-03
// This program counts how many sales are made
// in each of five categories of products
// There are 4 errors
start
Declarations
num category
num SIZE = 5
num sales[SIZE] = 0, 0, 0, 0, 0
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
output "Enter category or 9 to quit "
input category
while category <>
9
if category >= 1 AND
category <= SIZE
then
sales[category - 1] = sales[category - 1] + 1
else
output "Invalid category"
endif
input
category // otherwise loop will never
terminate
endwhile
output HEAD1
output HEAD2
category =
0
while category < SIZE
output category + 1, sales[category]
category = category + 1
endwhile
stop
Get Answers For Free
Most questions answered within 1 hours.