O Level Computer science Pre Release Material 2018 Oct/Nov Solution (Visual Basic and Pseudocode)
Pre release Scenario
A junior park run event is hold every week on a Saturday morning in a local park over a distance of two kilometers Children between the ages of 4 and 14 inclusive can register to take part. Children register with their name and age. When they register, they are allocated a unique identification number of four digits, the last digit is a check digit. Once registered a child can take part in junior park run events for a year.
For each event, the organizers record the time each child takes to run two kilometers Their time is stored for every event they complete and the number of runs they have completed is updated by one. If their time is faster than their personal best (PB) time, their PB time is updated When a child has completed 11 runs, they are awarded a half-marathon wristband. When a child has completed 22 runs they are awarded a full-marathon wristband.
A program is required to update the children’s data, update PB times if necessary, and decide if a wristband is to be awarded. The program also needs to identify the fastest child at this event for each of the age ranges; 4 to 6, 7 to 10 and 11 to 14.
Write and test a program or programs for the park run organizer
- Your program or programs must include appropriate prompts tor the entry of data
- Error messages and other output need to be set out clearly and be understandable
- All variables, arrays, constants and other identifiers must have meaningful names
You will need to complete these three tasks. Each task must be fully tested.
TASK 1 – Registering to take part.
Write a program to set up arrays to store the data for 20 children. On registration, each child must be allocated a unique identification number of four digits; the last digit is a check digit. The unique identification number, age in years and name for each child is recorded and stored on registration. The PB time and the number of runs are initialized to zero and these values stored on registration. Their PB time is stored as minutes correct to two decimal places.
TASK 2 – Recording the times.
Extend your program to record the unique identification number and to input the start time and finish time for every child completing the junior park run event. Calculate and store the time each child took to complete the run. A registered child does not have to compete in each event. Only one time per child is recorded during an event.
TASK 3 – Updating the children’s data and identifying the fastest child for each age range
Extend your program to update the number of runs and the PB time if necessary for every child completing the junior park run event. Check if any half- or full-marathon wristbands need to be awarded. Output the names and the type of wristbands. Output the names and the times of the fastest child at this event for each of the age ranges 4 to 6, 7 to 10 and 11 to 14.
Solution
Task 1
Download Pseudocode :
Task 1
Visual Basic Console :
Dim Child_name(0 To 19) As String Dim Child_age(0 To 19) As Integer Dim reg_no(0 To 19) As Integer Dim No_of_runs(0 To 19) As Integer Dim Personal_best(0 To 19) As Decimal Dim constant As Integer = 123 Dim digit1 As Integer Dim digit2 As Integer Dim digit3 As Integer Dim temp1 As Integer Dim temp2 As Integer Dim check_digit As Integer For i = 0 To 19 Console.WriteLine("Enter Child Name :") Child_name(i) = Console.ReadLine() Do Console.WriteLine("Enter Child Age :") Child_age(i) = Console.ReadLine() If Child_age(i) < 4 Or Child_age(i) > 14 Then Console.WriteLine("Age Must be between the range of 4 to 14") End If Loop Until Child_age(i) >= 4 And Child_age(i) <= 14 digit1 = Int(constant / 100) temp1 = digit1 * 100 temp2 = constant - temp1 digit2 = Int(temp2 / 10) digit3 = Int(temp2) Mod 10 check_digit = ((digit1 * 3) + (digit2 * 2) + (digit3 * 1)) Mod 10 reg_no(i) = constant * 10 + check_digit constant = constant + 1 No_of_runs(i) = 0 Personal_best(i) = 0 Console.WriteLine(Child_name(i) & " Registered Successfully") Console.WriteLine("Registration No is " & reg_no(i)) Next
Expanding to Task 2 and Task 3
Dim Select_option As Integer Dim Child_name(0 To 19) As String Dim Child_age(0 To 19) As Integer Dim reg_no(0 To 19) As Integer Dim No_of_runs(0 To 19) As Integer Dim Personal_best(0 To 19) As Double Dim constant As Integer = 123 Dim Event_duration As Double Dim Array_position As Integer = 123 Dim search As Integer Dim start_time As Double Dim finish_time As Double Dim ch As Char Dim fastest1 As Integer Dim fastest2 As Integer Dim fastest3 As Integer Dim Child_array_position1 As Integer Dim Child_array_position2 As Integer Dim Child_array_position3 As Integer Dim digit1 As Integer Dim digit2 As Integer Dim digit3 As Integer Dim temp1 As Integer Dim temp2 As Integer Dim check_digit As Integer Sub main() Console.WriteLine("1. Register Students") Console.WriteLine("2. Update Childrens data and output Fastest child of each category") Select_option = Console.ReadLine If Select_option = 1 Then Call Task1() ElseIf Select_option = 2 Then Call Task2_3() Else Console.WriteLine("Wrong Option, Select again :") End If End Sub Sub Task1() For i = 0 To 19 Console.WriteLine("Enter Child Name :") Child_name(i) = Console.ReadLine() Do Console.WriteLine("Enter Child Age :") Child_age(i) = Console.ReadLine() If Child_age(i) < 4 Or Child_age(i) > 14 Then Console.WriteLine("Age Must be between the range of 4 to 14") End If Loop Until Child_age(i) >= 4 And Child_age(i) <= 14 digit1 = Int(constant / 100) temp1 = digit1 * 100 temp2 = constant - temp1 digit2 = Int(temp2 / 10) digit3 = Int(temp2) Mod 10 check_digit = ((digit1 * 3) + (digit2 * 2) + (digit3 * 1)) Mod 10 reg_no(i) = constant * 10 + check_digit constant = constant + 1 No_of_runs(i) = 0 Personal_best(i) = 0 Console.WriteLine(Child_name(i) & " Registered Successfully") Console.WriteLine("Registration No is " & reg_no(i)) Next End Sub Sub Task2_3() Do Console.WriteLine("Enter Child Register Number") search = Console.ReadLine 'To check if searched registere number is availible, if availible then save it,s array position in variable For x = 0 To 19 If reg_no(x) = search Then Array_position = reg_no(x) End If Next If Array_position <> 123 Then Console.WriteLine("Enter registration details of : " & reg_no(Array_position) & " : " & Child_name(Array_position)) Console.WriteLine("Enter Start time in Minutes : ") start_time = Console.ReadLine Console.WriteLine("Enter End time in Minutes : ") finish_time = Console.ReadLine() Event_duration = finish_time - start_time ' Updating Personal Best time If Event_duration < Personal_best(Array_position) Then Personal_best(Array_position) = Event_duration Console.WriteLine("New Personal Best time ") End If 'Updating Number of Runs No_of_runs(Array_position) = No_of_runs(Array_position) + 1 'To Check if a wrist band is awarded? If No_of_runs(Array_position) = 11 Then Console.WriteLine("Half-Marathon wrist Band Awarded for : " & Child_name(Array_position)) ElseIf No_of_runs(Array_position) = 11 Then Console.WriteLine("Full-Marathon wrist Band Awarded for : " & Child_name(Array_position)) End If 'Finding Fastest Cild in each Age Category If Child_age(Array_position) >= 4 And Child_age(Array_position) <= 6 Then Fastest1 = Event_duration Child_array_position1 = Array_position ElseIf Child_age(Array_position) >= 7 And Child_age(Array_position) <= 10 Then Fastest2 = Event_duration Child_array_position2 = Array_position ElseIf Child_age(Array_position) >= 11 And Child_age(Array_position) <= 14 Then Fastest3 = Event_duration Child_array_position3 = Array_position End If Console.WriteLine("For Age (4-6 )" & Child_name(Child_array_position1) & "came first (fastest ) with a time = " & fastest1) Console.WriteLine("For Age (7-10 )" & Child_name(Child_array_position2) & "came first (fastest ) with a time = " & fastest2) Console.WriteLine("For Age (11-14 )" & Child_name(Child_array_position3) & "came first (fastest ) with a time = " & fastest3) Else Console.WriteLine("Registration number wrong!") End If Console.WriteLine("Do you need to record more Childrens event details? (Y/N)") ch = Console.ReadLine Loop Until ch = "n" Or ch = "N" End Sub
This Solution Can be Further more improved if you want, I did not wanted to make the code more complex, as many students get confused.
Line 124 should be
ElseIf No_of_runs(Array_position) = 22 Then
I’m Sorry, I’ts my Mistake you are correct.
it is ok
every one makes mistakes
can you write the preleased in Psedocode
can you send it to me
do you have these tasks in python?
I will try to do it, when ever i get free, I will recommend you to give it a try by your self
sir i need a python solution.
I will try to do it, when ever i get free, I will recommend you to give it a try by your self
Do You Have Psedocode for task 2 and 3 plz i need that
I will try to do it, when ever i get free.
Could u please post python solution for this or task 2 and 3 in pseudo code ?
I will try to do it, when ever i get free, I will recommend you to give it a try by your self
bro what if the child age itself is not in the range.
you re asking the age again for the same child who has the same name.
if the child age is not in range , you better ask again the name and age which will have the same value of i. Correct your code or or you can tell me if i am wrong.
You are right, we can do that to improve our code, I have already mentioned this code can be further improved a lot, it just fulfills the Pre release material Tasks, but if you need this code in real life this is just full of Bugs.
hello sir, have u done these in python or pseudo code because that would really help. I tried doing it myself but i had to many mistakes.
The exams are in 6 days could you please find time and do the python code I am facing a lot of problems
Can you send me task 2 and 3 in psudocode
Why did you write in dim constant as integer = 123
What is the purpose of 123
We use the constant to create unique digits,
See line 62 to 72