Solutions 8 47 sort num x 0 num y 0 num comps count 1

This preview shows page 47 - 51 out of 59 pages.

Solutions 8- 47sort() num x = 0 num y = 0 num COMPS = count - 1 while y < COMPS x = 0 // x must be reset to 0 while x < COMPS if numbers[x] < numbers[x + 1] then // Must compare numbers[x] to numbers[x + 1] swap() endif x = x + 1 endwhile y = y + 1 endwhile return swap() num temp temp = numbers[x + 1] numbers[x + 1] = numbers[x] numbers[x] = temp return DEBUG08-02 // This application reads student typing test data // including number of errors on the test, and the number // of words typed per minute. Grades are assigned based // on the following table: // Errors // Speed 0 1 2 or more // 030 C D F // 3150 C C F // 5180 B C D // 81100 A B C // 101 and up A A B start Declarations num MAX_ERRORS = 2 num errors num wordsPerMinute num grades[5][3] = {"C", "D", "F"}, {"C", "C", "F"}, {"B", "C", "D"}, {"A", "B", "C"}, {"A", "A", "B"} num LIMITS = 5 num speedLimits[LIMITS] = 0, 31, 51, 81, 101 num row output "Enter number of errors on the test " input errors if errors > MAX_ERRORS then errors = MAX_ERRORS // if errors are more than 2, then // they are in the same category as 2
Programming Logic and Design, 9e Solutions 8- 48endif output "Enter the speed in words per minute " input wordsPerMinute // variable to input is not speed; it is wordsPerMinute row = 0 while row < LIMITS AND wordsPerMinute >= speedLimits[row] // subscript for speedLimits should be row row = row + 1 endwhile row = row - 1 output "Your grade is ", grades[row][errors] // subscripts should be row and errors stop DEBUG08-03 // This application reads sales data for an automobile dealership. // Up to 100 sale amounts can be entered. The entered sale amounts // are sorted so that the median sale can be displayed. start Declarations num SIZE = 100 num QUIT = 99999 num saleAmount num sales[SIZE] num count = 0 num middlePosition num x num y num temp num comps getReady() while saleAmount <> QUIT and count < SIZE detailLoop() endwhile finish() stop getReady() output "Enter sale amount " input saleAmount return detailLoop() sales[count] = saleAmount // saleAmount must be stored in the array count = count + 1 output "Enter sale amount " input saleAmount return finish() sort() middlePosition = count / 2 // middle position is half the count, not half the array size output "The median sale amount is ", sales[middlePosition] return
Programming Logic and Design, 9e Solutions 8- 49sort() comps = count - 1 while y < comps x = 0 while x < comps if sales[x] > sales[x + 1] then swap() endif x = x + 1 // x must be incremented endwhile y = y + 1 // y must be incremented endwhile return void swap() temp = sales[x + 1] sales[x + 1] = sales[x] sales[x] = temp // temp must be assigned to sales[x] Return 2.Your downloadable files for Chapter 8 include a file named DEBUG08-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart, and then find and correct all the bugs.Answer:
Programming Logic and Design, 9e Solutions 8- 50Game Zone 1.In the Game Zone section of Chapter 6, you designed the logic for a quiz that contains multiple-choice questions about a topic of your choice. (Each question had three answer options.) Now, modify the program so it allows the user to retake the quiz up to four additional times or until the user achieves a perfect score, whichever comes first. At the end of all the quiz attempts, display a recap of the user

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture