98%(246)240 out of 246 people found this document helpful
This preview shows page 64 - 68 out of 77 pages.
output "Enter student name or ", QUIT, " to quit "input name// next name must be inputendwhilestopDebug06-03// This program counts how many sales are made// in each of five categories of productsstartDeclarationsnum categorynum SIZE = 5num QUIT = 9num sales[SIZE] = 0, 0, 0, 0, 0string HEAD1 = "Sales"string HEAD2 = "Category Number of Sales"output "Enter category ", QUIT, " to quit "input categorywhile category <> QUIT// category must be not equal to quitif category >= 1 AND category <= SIZE then// category can be equal to 1 or SIZE and still be validsales[category - 1] = sales[category - 1] + 1elseoutput "Invalid category"endifoutput "Enter category ", QUIT, " to quit "input category// category must be inputendwhileoutput HEAD1output HEAD2category = 0// category should start at 0 if// it is used as sales subscriptwhile category < SIZEoutput category + 1, sales[category]category = category + 1endwhilestop 2.Your downloadable files for Chapter 6 include a file named DEBUG06-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart and then find and correct all the bugs.Answer:64
Programming Logic and Design, 8eSolutions 6-65
Programming Logic and Design, 8eSolutions 6-Game Zone1.Create the logic for a Magic 8 Ball game in which the user enters a question such as What does my future hold?The computer randomly selects one of eight possible vague answers, such as It remains to be seen.startDeclarationsnum LIMIT = 8num indexstring userQuestionstring QUIT = “zzzz”string ANSWERS[LIMIT] = “As I see it, yes”, “It is certain”,“Signs point to yes”,66
Programming Logic and Design, 8eSolutions 6-“It remains to be seen”, “Reply hazy, try again”,“Outlook not so good”,“Cannot predict now”,“My sources say no”getReady()while userQuestion <> QUITdetailLoop()endwhilefinishUp()stopgetReady()output “Enter a question or ”, QUIT, “ to quit”input userQuestionreturndetailLoop()index = random(LIMIT)output ANSWERS[index]output “Enter a question or ”, QUIT, “ to quit”input userQuestionreturnfinishUp()output “End of program”return2.Create the logic for an application that contains an array of 10 multiple-choice questions related to your favorite hobby. Each question contains three answer choices.Also create a parallel array that holds the correct answer to each question—A, B, or C. Display each question and verify that the user enters only A, B, or C as the answer—if not, keep prompting the user until a valid response is entered. If the user responds to a question correctly, display Correct!;otherwise, display The correct answer is and the letter of the correct answer. After the user answers all the questions,display the number of correct and incorrect answers.Answer: A sample solution followsPseudocode (Please note, for brevity this solution contains only five questions.