Must compare numbersx to numbersx 1 swap endif x x 1

This preview shows page 32 - 36 out of 414 pages.

// 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 // 0–30 C D F // 31–50 C C F // 51–80 B C D // 81–100 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 endif output "Enter the speed in words per minute " input 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 sort() 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 Game Zone 1. In the Game Zone section of Chapter 6, you designed the logic for a quiz that contains multiple- start Declarations num correct = 0 num incorrect = 0 num x num SIZE = 5 num MAX_ATTEMPTS = 5 num attempt = 0 string perfectScore = “No” string guesses[SIZE] = “” string QUESTIONS[SIZE] = “What is the closest star to Earth?”, “What is the name of Earth’s moon?”, “How many miles (in trillions) are in a light yea “How many moons does Pluto have?”, “What planet is the biggest?” string CHOICES[SIZE] = “A. Scooper, B. Dipper, C. Sun”, “A. Luna, B. Europa, C. Sol”, “A. 6, B. 93, C. 10”, “A. 6, B. 2, C. 3”, “A. Saturn, B. Jupiter, C. Earth” string ANSWERS[SIZE] = “C”, “A”, “A”, “C”, “B” num scoreCorrect[MAX_ATTEMPTS] = 0 num scoreIncorrect[MAX_ATTEMTPS] = 0 startNewQuiz() while attempt < MAX_ATTEMPTS AND perfectScore = “No” takeQuiz() endwhile 2. Your downloadable files for Chapter 8 include a file named DEBUG08-04.jpg that contains a flo Answer : Answer: A sample solution follows Pseudocode (Please note, for brevity this solution contains only five questions. Students should

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture