programming logic

posted by .

Find Bugs in the pseudocode

// A high school is holding a recycling competition
// This program allows a user to enter a student's
// year in school (1 through 4)
// and number of cans collected
// Data is entered continuously until the user wnats to quit
// After headings, output is four lines
// one for each school year class
start
Declarations
num year
num cans
num SIZE = 4
num QUIT = 9
num collected[SIZE] = 0, 0, 0, 0
string HEAD1 = "Can Recycling Report"
string HEAD2 = "Year Cans Collected"
output "Enter year of student or ", QUIT, " to quit "
input year
while year <> QUIT
output "Enter number of cans collected "
input cans
collected[year] = collected[year] + cans
endwhile
output HEAD1
output HEAD2
while year <= SIZE
output year, collected[year - 1]
year = year + 1
endwhile
stop

DEBUG06-02.txt

// 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
start
string name
num score
num NUM_TESTS = 4
num NUM_RANGES = 5
num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
num 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
while sub < NUM_TESTS
output "Enter score "
input score
total = total + score
endwhile
average = total / NUM_TESTS
sub = 0
while average < RANGES[NUM_TESTS]
sub = sub + 1
endwhile
letterGrade = GRADES[NUM_TESTS]
output name, letterGrade
output "Enter student name or ", QUIT, " to quit "
input name
endwhile
stop

DEBUG06-03.txt

// This program counts how many sales are made in each of 5 categories of products
start
Declarations
num category
num SIZE = 5
num QUIT = 9
num sales[SIZE] = 0, 0, 0, 0, 0
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
output "Enter category ", QUIT, " to quit "
input category
while category = QUIT
if category >= 1 AND category < SIZE then
sales[category + 1] = sales[category - 1] + 1
else
output "Invalid category"
endif
output "Enter category ", QUIT, " to quit "
input category
endif
output HEAD1
output HEAD2
category = 0
while category <= SIZE
output category + 1, sales[category]
category = category + 1
endwhile
stop

  • programming logic -

    To debug, always keep in your mind the value of variables at any time as the program proceeds, and think of exceptional values a user can enter.
    Your program must expect users to enter anything because of human errors.
    For example, for the recycling program:

    // A high school is holding a recycling competition
    // This program allows a user to enter a student's
    // year in school (1 through 4)
    // and number of cans collected
    // Data is entered continuously until the user wnats to quit
    // After headings, output is four lines
    // one for each school year class
    start
    Declarations
    num year
    num cans
    num SIZE = 4
    num QUIT = 9
    num collected[SIZE] = 0, 0, 0, 0
    string HEAD1 = "Can Recycling Report"
    string HEAD2 = "Year Cans Collected"
    output "Enter year of student or ", QUIT, " to quit "
    input year what if user enters 6? -5?
    while year <> QUIT
    output "Enter number of cans collected "
    input cans
    collected[year] = collected[year] + cans
    endwhile
    output HEAD1
    output HEAD2
    what is the value of "year" at this point, (logic requires it to be 0)
    while year <= SIZE
    output year, collected[year - 1]
    year = year + 1
    endwhile
    stop

  • programming logic -

    DEBUG06-02.txt

    // 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
    start
    string name
    num score
    num NUM_TESTS = 4
    num NUM_RANGES = 5
    num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0
    num 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
    while sub < NUM_TESTS
    output "Enter score "
    input score
    total = total + score
    endwhile
    average = total / NUM_TESTS
    sub = 0
    while average < RANGES[NUM_TESTS]
    sub = sub + 1
    endwhile
    letterGrade = GRADES[NUM_TESTS]
    output name, letterGrade
    output "Enter student name or ", QUIT, " to quit "
    input name
    endwhile
    stop

    DEBUG06-03.txt

    // This program counts how many sales are made in each of 5 categories of products
    start
    Declarations
    num category
    num SIZE = 5
    num QUIT = 9
    num sales[SIZE] = 0, 0, 0, 0, 0
    string HEAD1 = "Sales"
    string HEAD2 = "Category Number of Sales"
    output "Enter category ", QUIT, " to quit "
    input category
    while category = QUIT
    if category >= 1 AND category < SIZE then
    sales[category + 1] = sales[category - 1] + 1
    else
    output "Invalid category"
    endif
    output "Enter category ", QUIT, " to quit "
    input category
    endif
    output HEAD1
    output HEAD2
    category = 0
    while category <= SIZE
    output category + 1, sales[category]
    category = category + 1
    endwhile
    stop

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. MATH

    Elsie is starting a recycling club at her school and hopes to use the money earned from recycling cans to buy recycling bins for the school. Elsie first needs to figure out how much the cans that can be collected at her school will …
  2. Computer programming

    Sorting is a common operation used in programming. Although languages such as Visual Basic 2008 offer built-in methods for sorting, other languages such as C do not support such a method. In order to be a programmer you should be able …
  3. CIS

    Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter a value. The program multiplies the value by 10 and outputs the result.
  4. programming

    Pseudocode - Create the logic for a program that continuously prompts a user for a numeric value until the user enters 0. The application passes the value in turn to a method that squares the number and to a method that cubes the number. …
  5. programming pseudocode

    Create the logic for a program that continuously prompts a user for a numeric value until the user enters 0. The application passes the value in turn to a method that squares the number and to a method that cubes the number. The program …
  6. programming

    using pseudocode debug the following 3 programs // A high school is holding a recycling competition // This program allows a user to enter a student's // year in school (1 through 4) // and number of cans collected // Data is entered …
  7. programming

    Write a program which allows user to enter 10 student names and scores for Java programming 1 and Java programming 2. Allow user to choose which course they want to enter the record for. Use the loop to ask input from user. The program …
  8. programming logic and design

    I need help writing pseudocode for this problem: Design a retirement planning calculator for skulling financial services • Allow a user enter a number of working years remaining in the user career and the annual amount of money the …
  9. Programming

    Design and plan the logic for a program that prompts the user for and allows the user to enter TWO numbers. The program outputs the sum of the two values. Provide declarations.
  10. computer programming

    Design the pseudocode for a program that allows a user to enter 10 numbers, then displays them in the reverse order of their entry

More Similar Questions