Algorithms For use in Unit 2 Exam
Algorithms – recap Declare variables that you intend to use Declare numberOfSprints = 0 Declare sprintTime = 0 Declare fastestTime = 100 Declare slowestTime = 0 Declare totalTime = 0 Declare average as real = 0
Algorithms – recap Output and input – to display information and input data. Output “Welcome to the 100m sprint training program” Output “Enter the number of sprints completed” Input numberOfSprints
Algorithms – recap If statement. The section below updates the fastestTime variable if the sprint time is a lower value. if sprintTime < fastestTime then fastestTime = sprintTime endif
Algorithms – recap If statement. Enter an if statement in the space below to update the slowestTime variable if the sprint time is a greater value.
Algorithms – recap Loops – Repeat Until. Or For i = 1 to 10 For i = 1 to numberOfSprints Output “Enter sprint time” Input sprintTime **additional code could be placed here ** Next for
Algorithms – recap Loops – Repeat Until. Or For i = 1 to 10 Repeat Output “Enter sprint time” Input sprintTime **additional code could be placed here ** Until NumberofSprints
Algorithms – recap Loop In the space below write a loop that asks the user the age of 5 pupils and outputs whether they may learn to drive a car (over the age of 16).
Calculations Calculations are very similar if not identical in an algorithm when compared to code in a high level language such as Python. e.g. totalTime = totalTime + sprintTime
Task 1 Write an algorithm to perform the following: Have a heading that states Bish Maths Test Enter 6 marks for a maths test. Use a loop For each mark state whether a Pass can be awarded (mark must be greater than 5). Assume mark is out of 10. Calculate and output the highest, lowest and average marks. #hint – you need to calculate highest, lowest and total within the loop as demonstrated on previous slides.
Task 1 - Solution
2016 Exam
2016 - Answer
2016 - Answer
Arrays (Lists) Lists can store multiple values, they are also known as arrays. Declare goalsScored array (1..99) of integer Declare matchgoal = 0 For i = 1 to 11 Output “Enter goals scored for player”, i Input matchgoal goalsScored[i] = goalsScored[i] + matchgoal Output “Your goals for the season are “, goalsScored[i] Next i
Task 2 Write an algorithm to perform the following: Have a heading that states Bish Computing Test Enter marks for four pupils who have completed three tests. Store their totals in an array. Calculate and output the average mark for each pupil.
Task 2 Solution
2015 Exam
2015 - Answer
2015 - Answer