ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2021 Question 7

15 marks · Data types and structures

The data from the file is imported into an array of records. Using a programming language of your choice, define a suitable data structure to store the data. The csv file contains 800 results. Using a programming language of your choice, declare a variable that can store the data for the 800 results. Your answer should include the data structure from part (i). In order to qualify for the javelin final, a competitor must throw a distance of 70 metres or more. The event organisers would like the program to create a file with the name and club of all the competitors who have qualified for the javelin final. Using a recognised design technique, design an algorithm that would create this file. The event organisers would like to be able to display the distance thrown by a competitor in a particular event. Using a programming language of your choice, write code that • asks for the name of a competitor and the event • displays the competitor name, distance and event, for example ‘J Smith threw 17.23 in the Shot Put’ or displays the message ‘Competitor not found’. Your answer should make use of the data structure defined in part (a). An athletics competition takes place between different clubs. The competition includes four throwing events which are shot put, discus, hammer and javelin. The result for each competitor is stored in a csv file. The file stores the competitor’s name, club, event name and distance thrown in metres. A program is required to read the data from the csv file and then process it. A sample of the data is shown below. F Dean,Rothesay Rovers,Discus,58.04 J Smith,Hawick Harriers,Shot Put,17.23 K Singh,Rothesay Rovers,Javelin,71.75 …

Marking scheme

• record structure with name • four fields specified 1 mark for each bullet Record structure could be Type, Structure, Class, Named Tuple, Record name IS Example Answers: SQARL RECORD competitorData IS ( STRING name, STRING club, STRING event, REAL distance) VB Private/Public/Structure Type competitorData name as string club as string event as string distance as single END TYPE Livecode Global CompetitorDATA Put empty into CompetitorData[1][name] Put empty into CompetitorData[1][club] Put empty into CompetitorData[1][event] Put empty into CompetitorData[1][distance] Python Class method class Competitor (): def __init__(self): self.name = "" self.club = "" self.event = "" self.distance = 0.0 Python Dataclass method Class Competitor: name: str = "" club: str = "" event: str = "" distance: float = 0.0 • array structure • using data type created in (i) 1 mark for each bullet Example Answers: Python competitors=[datatype_a() for x in range (800)] VB DIM competitors(799) AS datatype_a Livecode Set the data of EventData to CompetitorData • open and close file • loop traversing the array with termination • IF with condition event=“Javelin” • AND condition distance>=70 • writing name and club to file 1 mark for each bullet Open file Loop for all 800/to end of array If event=“Javelin” AND distance>=70 then Write name, club to file End if End loop Close file • ask for searchName/searchEvent and their use in the IF statement • loop that traverses correctly with termination IF condition with: • correct use of array variable • comparison of current name and event fields to targets • display if found with correctly concatenated message • display if not found using any suitable flag, for example -1 or found is false 1 mark for each bullet Candidates’ solutions will vary in terms of efficiency but marks are awarded for any correct implementation. Example answers: RECEIVE searchName FROM KEYBOARD RECEIVE searchEVENT FROM KEYBOARD DECLARE found INITIALLY false SET counter TO -1 REPEAT counter=counter+1 IF searchName=competitors[counter].name AND searchEvent=searchName=competitors[counter].event then SET found TO true END IF UNTIL found=true OR counter=799 IF found =true THEN SEND competitors[counter].name & " threw " &competitors[counter].distance & " in the " & competitors[counter].event TO DISPLAY ELSE SEND " Competitor not found " TO DISPLAY END IF Using a fixed loop: RECEIVE searchName FROM KEYBOARD RECEIVE searchEVENT FROM KEYBOARD DECLARE found INITIALLY false FOR index FROM 0 TO 799 DO IF searchName=competitors[index].name AND searchEvent=competitors[index].event then SEND competitors[index].name & " threw " & competitors[index].distance & " in the " & competitors[index].event TO DISPLAY SET found TO true END IF END FOR IF found =false THEN SEND ‘Competitor not found’ TO DISPLAY END IF

Previous question: Higher Computing Science 2021 Question 6

Next question: Higher Computing Science 2021 Question 8