Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. If no documentation for analysis, design, testing and evaluation has been requested for this challenge then some of the assessments for these criteria can be implied through the solution given e.g. have all of the tasks and sub-tasks been identified? Have all of the inputs and outputs been identified? Does the solution produce the expected output with normal, extreme and boundary data?
  2.  
  3. The following should be included in the solution:
  4.  
  5. There should be a minimum of 5 questions with 4 alternative answers.
  6. The user should be able to select an option for each question and their choice should be validated.
  7. The user should be told their score and the correct answers for those answered incorrectly.
  8. For the extension, the user should be able to input their name and their name and score should be saved in a text file.
  9.  
  10. There are different possible algorithms that can be designed. The one shown uses the basic constructs studied in previous chapters.
  11.  
  12. Answer:
  13.  
  14. #This sample solution shows only the first two questions. Questions 3 to 5 would be written as the ones shown.
  15.  
  16. OUTPUT "Please enter your name. "
  17.  
  18. name ← USERINPUT
  19.  
  20. score ← 0
  21.  
  22. array incorrectQuestions ← [] #This array will save question numbers of those answered incorrectly.
  23.  
  24. array correctAnswers ← [] #This array will save the correct answers for thiose answered incorrectly.
  25.  
  26. OUTPUT
  27.  
  28. OUTPUT "Please select the option that contains the correct answer for the following questions."
  29.  
  30. OUTPUT
  31.  
  32. OUTPUT "Question1:"
  33.  
  34. pOUTPUT
  35.  
  36. OUTPUT "What is meant by an embedded system?"
  37.  
  38. OUTPUT "A" + " " + "A system inside a computer.") # " " will insert a tab.
  39.  
  40. OUTPUT "B" + " " + "A system containing a processor."
  41.  
  42. OUTPUT "C" + " " + "A computer system built within a another device to control it."
  43.  
  44. OUTPUT "D" + " " + "A computer system that can be programmed."
  45.  
  46. OUTPUT
  47.  
  48. answer1 ← "" #A variable to hold the user's answer.
  49.  
  50. WHILE answer1 = ""
  51.  
  52. OUTPUT "Please input the letter of the correct answer: " #A 'while' loop is used to validate the entry.
  53.  
  54. answer1 ← USERINPUT
  55.  
  56. IF answer1 ≠ "A" AND answer1 ≠ "B" AND answer1 ≠ "C" AND answer1 ≠ "D" THEN
  57.  
  58. OUTPUT "Your choice is not recognised."
  59.  
  60. answer1 ← ""
  61.  
  62. ENDIF
  63.  
  64.  
  65.  
  66. ENDWHILE
  67.  
  68. IF answer1 = "C" THEN
  69.  
  70. score ← score + 1
  71.  
  72. ELSE
  73.  
  74. #If the answer is incorrect then the question number and the correct answer are appended to the arrays.
  75.  
  76. incorrectQuestions.append("1")
  77.  
  78. correctAnswers.append("A computer system built within a another device to control it.")
  79.  
  80. endif
  81.  
  82.  
  83.  
  84. #Question 2
  85.  
  86. OUTPUT
  87.  
  88. OUTPUT "Question2:"
  89.  
  90. OUTPUT
  91.  
  92. OUTPUT "The component of the CPU used to store data items is the..."
  93.  
  94. OUTPUT "A" + " " + "Control unit."
  95.  
  96. OUTPUT "B" + " " + "Arithmetic and logic unit."
  97.  
  98. OUTPUT "C" + " " + "Bus."
  99.  
  100. OUTPUT "D" + " " + "Registers."
  101.  
  102. OUTPUT
  103.  
  104. answer2 = ""
  105.  
  106. WHILE answer2 = ""
  107.  
  108. OUTPUT "Please input the letter of the correct answer:
  109.  
  110. answer2 ← USERINPUT
  111.  
  112. IF answer2 ≠ "A" AND answer2 ≠ "B" AND answer2 ≠ "C" AND answer2 ≠ "D" THEN
  113.  
  114. OUTPUT "Your choice is not recognised."
  115.  
  116. answer2 ← ""
  117.  
  118. ENDIF
  119.  
  120. UNDWHILE
  121.  
  122. IF answer2 = "D" THEN
  123.  
  124. score ← score + 1
  125.  
  126. ELSE
  127.  
  128. incorrectQuestions.append("2")
  129.  
  130. correctAnswers.append("Registers.")
  131.  
  132. ENDIF
  133.  
  134.  
  135.  
  136. #Questions 3 to 5 would be written in the same way.
  137.  
  138. #The following code would be written after the last question.
  139.  
  140. OUTPUT "Hi " + name + ". Your score is " + score + "/5."
  141.  
  142.  
  143.  
  144. IF LEN(incorrectQuestions) > 0: #This will check if there are any incorrect answers and if there are it will print them and their correct answers for the user.
  145.  
  146. OUTPUT "Here are the questions you got wrong with their correct answers."
  147.  
  148. FOR index = 0 to LEN(incorrectQuestions) - 1
  149.  
  150. OUTPUT "Question " + incorrectQuestions[index] + " " + correctAnswers[index]
  151.  
  152. ENDFOR
  153.  
  154. ENDIF
  155.  
  156. #Saving the data to a text file.
  157.  
  158. WRITELINE (name + ".txt", 1, name) #The file name is given the name of the user and name is added.
  159.  
  160. WRITELINE (name + ".txt", 2, score) #The score is added.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement