Question

The assignment below has three pseudocodes below I need to fix the debug exercises in it....

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   

  

Homework Answers

Answer #1

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   

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
debug the following 1) // The main program calls a method that // prompts for and...
debug the following 1) // The main program calls a method that // prompts for and returns a name start Declarations string usersName name = askUserForName() output "Your name is ", usersName stop string askUserForName() Declarations string name output "Please type your name " input usersName return 2) // The main program passes a user’s entry to // a method that displays a multiplication table // using the entered value. The table includes the // value multiplied by every factor...
The City of Atlanta is holding a special census. The census takers collect one record for...
The City of Atlanta is holding a special census. The census takers collect one record for each resident. Each record contains a resident’s age, gender, and voting district. The voting district field contains a value between 1 and 22. The program will accept resident information until a sentinel value is entered. At the end, the program will produce a list of districts and the count for each district. Given the following pseudocode, fill in the missing lines of code: (Grading:...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Java Script I need the code to produce these 3 output. I can only get it...
Java Script I need the code to produce these 3 output. I can only get it to produce input #3 I need it to produce the following: // Input #1: // http://www.example.com // Output // http://www.example.com // Input #2: // http://www.example.com?name=r2d2 // Output // http://www.example.com // name: r2d2 // Input #3: // http://www.example.com?name=r2d2&email=r2d2%40me.com&human=no // Output // http://www.example.com // name: r2d2 // email: [email protected] // human: no THIS IS WHAT I HAVE SO FAR: HTML <!DOCTYPE html> <html lang="en"> <head> <meta...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...