Worked example 1
A teacher needs a program to calculate the average test score for a class of 30 students. The scores are integers out of 100. Describe how computational thinking could be used to solve this problem.
Show solution outline
Here is a breakdown of the solution using computational thinking skills:
- Decomposition: The problem can be broken down into smaller parts:
- Get the score for each of the 30 students.
- Add all the scores together to get a total.
- Divide the total by the number of students (30) to get the average.
- Display the final average score.
- Pattern Recognition: The process of 'getting a score and adding it to a running total' is repeated for every student. This pattern is identical for all 30 students.
- This suggests that a loop (iteration) would be an efficient way to implement this part of the solution.
- Abstraction: We can abstract away unnecessary details. We don't need to know the students' names or the specific date of the test. The essential information is:
- A list or sequence of 30 integer scores.
- A variable to hold the running total (e.g., TotalScore).
- A constant for the number of students (e.g., ).
- A variable to hold the final result (e.g., AverageScore).
- Algorithm Design (in Pseudocode):
DECLARE TotalScore : INTEGER DECLARE Counter : INTEGER DECLARE StudentScore : INTEGER DECLARE AverageScore : REAL TotalScore <- 0 FOR Counter <- 1 TO 30 OUTPUT "Enter score for student ", Counter INPUT StudentScore TotalScore <- TotalScore + StudentScore NEXT Counter AverageScore <- TotalScore / 30 OUTPUT "The average score is: ", AverageScore