In: Computer Science
Case Study for Question 3 and 4
The Georgetown Heritage club is organizing a running
competition. All participants are
required to run 3 races: 400m, 200m, and 100m sprints. The sports
club requires a system to
record the performance times of all participants for each of the 3
running events. The sports
club also wants to record the registration number and the age of
each participant.
Requirement 1: The user must be prompted to input data for each
participant in the correct
format up to a maximum of 40 participants. If the format is
incorrect, the user must be asked
to re-enter the data. For reasons of simplicity you may assume that
all times are recorded as
whole numbers (number of seconds). The user must be able to
indicate when data entry for
the last participant has been completed.
Requirement 2: Based on the available data, the organizers want the system to identify:
The registration number of the fastest runner for each
race
For each race, the average time needed by all those participants
who are aged 60 and
above.
The algorithm must be able to perform these calculations and
inform the user of the
results.
Question 3
Write an algorithm based on the description above that satisfies
Requirement 1 and
Requirement 2.
Any interaction with the user should be represented as appropriate
display messages.
[25 marks]
Algorithm
Step 1: Declare MAX_SIZE = 40 and numOfEntries = 0
Step 2: Declare array for registrationNums with size MAX_SIZE
step 3: Declare four arrays for ages, scoresRace1, scoresReace2 and scoresRace3 with size MAX_SIZE
Step 4: Prompt to the user to enter registration number of participant and read it to registrationNumber
Step 5: Check the registrationNumber is valid or not. If not valid, print the error message "Registration number is not valid" and go to step 4.
Step 6: Prompt to the user to enter age of participant and read it to age
Step 7: Check the age is valid or not. If not valid, print the error message "Age is not valid" and go to step 6.
Step 8: Prompt to the user to enter time of race1 of participant and read it to race1
Step 9: Check the race1 is valid or not. If not valid, print the error message "Score is not valid" and go to step 8.
Step 10: Prompt to the user to enter time of race2 of participant and read it to race2
Step 11: Check the race2 is valid or not. If not valid, print the error message "Score is not valid" and go to step 10.
Step 12: Prompt to the user to enter time of race3 of participant and read it to race3
Step 13: Check the race3 is valid or not. If not valid, print the error message "Score is not valid" and go to step 12.
Step 14: registrationNums[numOfEntries] = registrationNumber
ages[numOfEntries] = age
scoresRace1[numOfEntries] = race1
scoresRace2[numOfEntries] = race2
scoresRace3[numOfEntries] = race3
numOfEntries = numOfEntries + 1
Step 15: if numOfEntries is equal to MAX_SIZE go to step 18
Step 16: Ask the user "Do you want to add another entery(Y/N)? and read the answer to answer.
Step 17: If the answer is 'Y', go to step 4. Else if the answer is not 'N' print error message "Invalid answer" and go to step 16.
Step 18: Make race1FastestRunner = race2FastestRunner = race3FastestRunner = 0
race1Sum = race2Sum = race3Sum = 0
count = 0
i = 0
Step 19: If i equal to numOfEntries go to Step 24.
Step 20: if race1[i] > race1[race1FastestRunner], make race1FastestRunner = i
Step 21: if race2[i] > race2[race2FastestRunner], make race2FastestRunner = i
Step 22: if race3[i] > race3[race1FastestRunner], make race3FastestRunner = i
Step 23: if ages[i] >= 60, then make
count = count+1
race1Sum = race1Sum+race1[i]
race2Sum = race2Sum+race2[i]
race3Sum = race3Sum+race3[i]
Step 23: Go to step 19
Step 24: If numOfEntries>0 then, print
The registration number of the fastest runner for race1 = registrationNums[race1FastestRunner]
The registration number of the fastest runner for race2 = registrationNums[race2FastestRunner]
The registration number of the fastest runner for race3 = registrationNums[race3FastestRunner]
The average time needed by participants aged 60 and above for race1 = race1Sum/count
The average time needed by participants aged 60 and above for race2 = race2Sum/count
The average time needed by participants aged 60 and above for race3 = race3Sum/count
Step 25: END