Output enter a student id or quit to quit input stuid

This preview shows page 17 - 23 out of 56 pages.

output “Enter a student ID or ”, QUIT, “ to quit” input stuID return collectStudentData() output “Enter the classroom number and score for student ”, stuID input classNum, score if classNum >= 1 AND classNum <= SIZE then totalPnts[classNum-1] = totalPnts[classNum-1] + score else output “Invalid classroom number” endif output “Enter a student ID or ”, QUIT, “ to quit” input stuID return finishUp() classNum = 0 while classNum < SIZE output classNum+1, totalPnts[classNum] classNum = classNum + 1 endwhile return b. Modify the Watson Elementary School program so that each classroom’s average of the test scores is output, rather than each classroom’s total. 17
Programming Logic and Design, 6e Solutions 6- Pseudocode: start Declarations num stuID num classNum num score 18
Programming Logic and Design, 6e Solutions 6- num avg num SIZE = 30 num QUIT = 9999 num totalPnts[SIZE] = 0 num classCnt[SIZE] = 0 getReady() while stuID not equal to QUIT collectStudentData() endwhile classNum = 0 finishUp() stop getReady() output “Enter a student ID or ”, QUIT, “ to quit” input stuID return collectStudentData() output “Enter the classroom number and score for student ”, stuID input classNum, score if classNum >= 1 AND classNum <= SIZE then totalPnts[classNum-1] = totalPnts[classNum-1] + score classCnt[classNum-1] = classCnt[classNum-1] + 1 else output “Invalid classroom number” endif output “Enter a student ID or ”, QUIT, “ to quit” input stuID return finishUp() while classNum < SIZE if classCnt[classNum] = 0 then avg = 0 else avg =totalPnts[classNum]/classCnt[classNum] endif output classNum+1, avg classNum = classNum + 1 endwhile return 6. The Billy Goat Fast-Food restaurant sells the following products: Product Price ($) Cheeseburger 2.49 Pepsi 1.00 Chips 0.59 Design the logic for an application allows a user to enter an order item continuously until a sentinel value is entered. After each item, display its price or the message 19
Programming Logic and Design, 6e Solutions 6- “Sorry, we do not carry that” as output. After all items have been entered, display the total price for the order. 20
Programming Logic and Design, 6e Solutions 6- 21
Programming Logic and Design, 6e Solutions 6- Pseudocode: start Declarations string itemOrdered num x num found = 0 num total = 0 num SIZE = 3 string QUIT = “ZZZZ” num PRICE[SIZE] = 2.49, 1, 0.59 string PRODUCT[SIZE] = “Cheeseburger”, “Pepsi”, “Chips” string ERROR_MSG = “Sorry, we do not carry that” getReady() while itemOrdered not equal to QUIT detailLoop() endwhile finishUp() stop getReady() output “Enter an item or ”, QUIT, “ to complete your order” input itemOrdered return detailLoop() found = 0 x = 0 while x < SIZE if itemOrdered = PRODUCT[x] then output PRICE[x] x = SIZE found = 1 total = total + PRICE[x] else x = x + 1 endif endwhile if found = 0 then output ERROR_MSG endif output “Enter an item or ”, QUIT, “ to complete your order” input itemOrdered return finishUp() output “Your order total is: $”, total return

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture