# Logic7e_Solutions_ch08 - Programming Logic and Design 7e...

• Homework Help
• 50
• 93% (46) 43 out of 46 people found this document helpful

This preview shows page 1 - 10 out of 50 pages.

Programming Logic and Design, 7eSolutions 8-Programming Logic and Design, 7th EditionChapter 8Exercises1.Design an application that accepts 10 numbers and displays them in descending order.Answer: A sample solution follows. Please note that students could either sort the array indescending order and display, or sort the array in ascending order and display the array inreverse order, which is done here. Flowchart:1
Programming Logic and Design, 7eSolutions 8-Pseudocode:startDeclarations2
Programming Logic and Design, 7eSolutions 8-num SIZE = 10num numbers[SIZE]num xnum ynum tempnum COMPS = SIZE - 1fillArray()sortArray()displayArray()stopfillArray()x = 0while x < SIZEoutput “Enter a number”input numbers[x]x = x + 1endwhilereturnsortArray()x = 0y = 0while y < COMPSx = 0while x < COMPSif numbers[x] > numbers[x + 1] thenswap()endifx = x + 1endwhiley = y + 1endwhilereturnswap()temp = numbers[x+1]numbers[x+1] = numbers[x]numbers[x] = tempreturndisplayArray()x = SIZE - 1while x >= 0output numbers[x]x = x - 1endwhilereturn2.Design an application that accepts enter eight friends’ first names and displays them in alphabetical order.Answer: A sample solution follows. 3
Programming Logic and Design, 7eSolutions 8-Flowchart:Pseudocode:4
Programming Logic and Design, 7eSolutions 8-startDeclarationsnum SIZE = 8string names[SIZE]num xnum ystring tempnum COMPS = SIZE - 1fillArray()sortArray()displayArray()stopfillArray()x = 0while x < SIZEoutput “Enter a name”input names[x]x = x + 1endwhilereturnsortArray()x = 0y = 0while y < COMPSx = 0while x < COMPSif names[x] > names[x + 1] thenswap()endifx = x + 1endwhiley = y + 1endwhilereturnswap()temp = names[x+1]names[x+1] = names[x]names[x] = tempreturndisplayArray()x = 0while x < SIZEoutput names[x]x = x + 1endwhilereturn3.a. Professor Zak allows students to drop the two lowest scores on the ten 100-point quizzes she gives during the semester. Design an application that accepts a student name and 10 quiz scores. Output the student’s name and total points for the student’s eight highest-scoring quizzes.5
Programming Logic and Design, 7eSolutions 8-Answer: A sample solution followsFlowchart:6
Programming Logic and Design, 7eSolutions 8-Pseudocode:start7
Programming Logic and Design, 7eSolutions 8-Declarationsnum SIZE = 10num MAX = 8string namenum scores[SIZE]num xnum ynum tempnum totalnum COMPS = SIZE - 1fillArray()sortArray()displayTotal()stopfillArray()output “Enter the student’s name”input namex = 0while x < SIZEoutput “Enter a quiz score”input scores[x]x = x + 1endwhilereturnsortArray()x = 0y = 0while y < COMPSx = 0while x < COMPSif scores[x] > scores[x + 1] thenswap()endifx = x + 1endwhiley = y + 1endwhilereturnswap()temp = scores[x+1]scores[x+1] = scores[x]scores[x] = tempreturndisplayTotal()x = 0total = 0while x < MAXtotal = total + scores[x]x = x + 1endwhileoutput name, totalreturn8
Programming Logic and Design, 7eSolutions 8-b. Modify the application in Exercise 3a so that the student’s mean and median scores on the eight best quizzes are displayed.