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:...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
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...
Below is the problem that I have and here is the code that I have in...
Below is the problem that I have and here is the code that I have in c++. Can someone help me on what I am doing wrong or the correct code. A teacher has asked all her students to line up according to their first name. For example, in one class Amy will be at the front of the line, and Yolanda will be at the end. Write a program that prompts the user to enter the number of 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...
I have run huge piece of code. I need a UML for it. I dont what...
I have run huge piece of code. I need a UML for it. I dont what a UML is, but my professor said he needs it. Please help. Thanks. import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.Scanner; public class CreditCardValidation { private String inputFileName; private String outputValidCardFileName; private String outputInvalidCardFileName; public static void main(String[] args) { CreditCardValidation ccValidationObj = new CreditCardValidation(); ccValidationObj.readFile(); } //Deafult Constrictor to inilialize instance variable public CreditCardValidation () { this.inputFileName = "data.txt"; this.outputValidCardFileName =...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item = 0; 4. while (count < 4) { 5.      cout << "Enter item cost: "; 6.      cin >> item; 7.      item_total += item; 8.      ++count; 9. } 10. int average_cost = round(item_total / count); 11. cout << "Total cost: " << item_total << "\nAverage cost: " << average_cost; (Refer to Code Example 8-1.) If the user enters 5, 10, and 15 at the prompts, the output is: Total...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the following CFG: 1. exps --> exp | exp NEWLINE exps 2. exp --> term {addop term} 3. addop --> + | - 4. term --> factor {mulop factor} 5. mulop --> * | / 6. factor --> ( exp ) | INT The 1st production defines exps as an individual expression, or a sequence expressions separated by NEWLINE token. The 2nd production describes an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT