Pseudocode Algorithms for Score Analysis
Pseudocode Algorithms for Score Analysis
The pseudocode ensures repeatability through the use of a `WHILE` loop. The construct checks the variable `anotherGo` at line 3. As long as `anotherGo` is set to 'Yes', the loop continues, allowing the user to repeat the input and counting process. This provides a mechanism for continuous execution until the user decides to stop .
The 'Selection' programming construct is utilized in line 10 with the IF statement: `IF (count MOD 5 <> 0) AND (count MOD 7<>0) THEN`. Selection allows the algorithm to make decisions based on conditions, directing the flow along different paths depending on whether the condition is true or false .
The algorithm for counting scores over 100 is as follows: ``` SET countOver100 TO 0 SEND 'Enter score or -1 to end:' TO DISPLAY RECEIVE score FROM (INTEGER) KEYBOARD WHILE score <> -1 DO IF score > 100 THEN countOver100 = countOver100 + 1 END IF SEND 'Enter next score or -1 to end:' TO DISPLAY RECEIVE score FROM (INTEGER) KEYBOARD END WHILE SEND countOver100 TO DISPLAY ``` This pseudocode repeatedly checks and counts scores exceeding 100 .
To calculate the average of scores, the pseudocode is: ``` SET total TO 0 SET count TO 0 SEND 'Enter score or -1 to end:' TO DISPLAY RECEIVE score FROM (INTEGER) KEYBOARD WHILE score <> -1 DO total = total + score count = count + 1 SEND 'Enter next score or -1 to end:' TO DISPLAY RECEIVE score FROM (INTEGER) KEYBOARD END WHILE IF count > 0 THEN average = total / count SEND average TO DISPLAY ELSE SEND 'No scores were entered' TO DISPLAY END IF ``` This ensures the calculation accounts for the number of scores entered, including a check for zero scores .
The MOD operator returns the remainder of a division operation. In the pseudocode, it filters out numbers that are divisible by 5 or 7; specifically, `count MOD 5 <> 0` and `count MOD 7<>0` ensure that numbers that are multiples of 5 or 7 are not printed .
To convert the flowchart into pseudocode: ``` SEND 'Please enter a new ID' TO DISPLAY RECEIVE newID FROM KEYBOARD IF IDinUse(newID) THEN SEND 'Choose another ID' TO DISPLAY ELSE WRITE newID TO FILE END IF ``` This emphasizes the decision-making process through condition checks and corresponding actions .
The 'Iteration' constructs begin at lines 3 and 9 and end at lines 18 and 14, respectively. Iteration is crucial for this algorithm to repeatedly execute a block of code, essential for tasks like counting or accumulating values over a range or set times .
The program employs logical reasoning by using conditional checks within a loop structure. Specifically, it evaluates each number in the range for divisibility by 5 and 7 using the MOD operator. If a number is not divisible by either 5 or 7 (i.e., `count MOD 5 <> 0 AND count MOD 7 <> 0`), it is displayed; otherwise, it is skipped. This logic ensures only those numbers that meet the criteria are outputted .
The 'Sequence' programming construct is demonstrated in lines 1, 2, 4, 6, 8, 15, and 16. Sequence is significant in algorithm development as it ensures steps are executed in a specific order, which is crucial for the logical flow and correctness of the algorithm .
At line 15, the program will output '8 numbers', as the algorithm counts the numbers from 1 to 10, excluding those that are multiples of 5 or 7, specifically counting 1, 2, 3, 4, 6, 8, 9, and 10 .