Answer Sunrise Freight charges standard per pound shipping prices to the five

Answer sunrise freight charges standard per pound

This preview shows page 61 - 65 out of 77 pages.

Answer : // Sunrise Freight charges standard // per-pound shipping prices to the five states they serve // –- IL IN OH MI WI // -- 0.60 0.55 0.70 0.65 0.67 // Modify this program to reduce its size // by using arrays start Declarations string state num pounds num SIZE = 5 string STATES[SIZE] = “IL”, “IN”, “OH”, “MI”, “WI” num PRICES[SIZE] = 0.60, 0.55, 0.70, 0.65, 0.67 num sub string foundIt string BAD_STATE_MSG = "Sorry, we do not ship to ” string FINISH = “XXX” getReady() while state <> FINISH findPrice() endwhile finishUp() stop getReady() output "Enter state or ", FINISH, " to quit" input state 61
Programming Logic and Design, 8e Solutions 6- return findPrice() foundIt = "N" sub = 0 while sub < SIZE if state = STATES[sub] then foundIt = "Y" endif sub = sub + 1 endwhile if foundIt = "N" then output BAD_STATE_MSG, state else price = PRICES[sub] output “Enter pounds “ input pounds output “Cost per pound to ship to ”, state, “ is ”, price output “Total cost is ”, price * pounds endif output "Enter next state or ", FINISH, " to quit" input state return finishUp() output "End of job" return. Find the Bugs 1. Your downloadable files for Chapter 6 include DEBUG06-01.txt, DEBUG06-02.txt, and DEBUG06-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with two slashes (//). Following the comments, each file contains pseudocode that has one or more bugs you must find and correct. Answer : Debug06-01 // 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 enters 9 // After headings, output is four lines -- // one for each school year class start Declarations num year num cans num SIZE = 4 num QUIT = 9 62
Programming Logic and Design, 8e Solutions 6- num collectedArray[SIZE] = 0, 0, 0, 0 // need additional initialization value 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 collectedArray[year - 1] = collectedArray[year - 1] + cans // subscripts should be year - 1 output "Enter year of student or ", QUIT, " to quit " input year endwhile output HEAD1 output HEAD2 year = 1 while year <= SIZE // year should be compared <= SIZE output year, collectedArray[year - 1] // subscripts should be year - 1 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 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 sub = sub + 1 // sub must be incremented endwhile average = total / NUM_TESTS // average must be calculated sub = 0 63
Programming Logic and Design, 8e Solutions 6- while average < RANGES[sub] // RANGES requires a subscript sub = sub + 1 endwhile letterGrade = GRADES[sub] output name, letterGrade

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture