ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
15 marks · Project planning
The organisers have reviewed feedback about the existing program and essential changes have been identified. Part of the outline plan for the development work is described below. The development aims to begin on Monday September 5, 2017, by identifying: • the user requirements • the business requirements • the scope and boundaries of the development These three tasks can be completed concurrently. Identification of the user requirements and the business requirements will each take 5 days whereas identification of the scope and boundaries will only take two days. The functional requirements can only be identified once the previous three tasks have been completed. This work will take three days. Create a Gantt chart to schedule the first four development tasks outlined in the description above. The aim of the competition is to throw the shot as far as possible. The competition has six rounds. The distance thrown in each round is recorded in metres. The winner in each category (Senior, Adult or Junior) is the competitor who throws the shot the furthest. Each competitor is given a unique ID. The competition data collected for competitor 12 is shown below. CompetitorID Name Category Throw 1 Throw 2 Throw 3 Throw 4 Throw 5 Throw 6 12 Davidson L Senior 11·0 14·3 14·8 17·4 16·7 17·1 Explain why an array of records would be more suitable than a 2-D array to store this competitor data. To retrieve the record for a particular competitor, the binary search algorithm will be applied to an array of records. The structure of the array of records used to store the competition data for the Senior category is defined using the following code: RECORD Competitor IS { INTEGER competitorID, STRING name, STRING category, ARRAY OF REAL throw } DECLARE seniorCompetitor AS ARRAY OF Competitor INITIALLY [ ] The code used to retrieve the correct competitor record is shown below. Line 1 PROCEDURE search(ARRAY OF Competitor seniorCompetitor, INTEGER requiredID, INTEGER low, INTEGER high) Line 2 IF low > high THEN Line 3 RETURN -1 Line 4 END IF Line 5 SET mid TO (low + high)/2 Line 6 IF (seniorCompetitor[mid] = requiredID) THEN Line 7 RETURN mid Line 8 ELSE IF (seniorCompetitor[mid] < requiredID) THEN Line 9 RETURN search(seniorCompetitor, requiredID, mid+1, high) Line 10 ELSE Line 11 RETURN search(seniorCompetitor, requiredID, low, mid-1) Line 12 END IF Line 13 END PROCEDURE Name the computational construct used in Line 9 and Line 11. A call stack is a stack data structure used to keep track of the active subprograms. Explain the role of a stack data structure in the execution of this search procedure. Explain the need for Lines 2 to 4. To work out the winner in the Senior category, the program calculates the longest throw for each competitor and places it, together with the matching competitorID, in an array of records called seniorLongest. This array of records is defined using the following code: RECORD Longest IS { REAL LongestThrow, INTEGER CompetitorID } DECLARE seniorLongest AS ARRAY OF Longest INITIALLY [ ] The program then uses a bubble sort algorithm to arrange the contents of the seniorLongest array into descending order of longest throw. A section of the code used for this purpose is shown below. Line 50 FOR counter FROM 0 TO LengthOfArray-2 DO Line 51 IF <adjacent items of seniorLongest array are in the wrong order> THEN Line 52 swap (seniorLongest, counter) Line 53 END IF Line 54 END FOR … Line 150 PROCEDURE swap(ARRAY OF Longest sLongest, INTEGER count) Line 151 SET temp TO sLongest[count] Line 152 ………………………… Line 153 ………………………… Line 154 END PROCEDURE Using a programming language with which you are familiar, write the code needed to complete Line 152 and Line 153 of the swap procedure. Your code should make use of the data structure and variables stated. A limit is set on the number of competitors who can participate in each category (Senior, Adult or Junior). Once this limit has been reached, a waiting list will be used to store the name and category of each additional person wishing to take part. If a competitor withdraws from the competition, they will be replaced by the next suitable person on the waiting list. A queue data structure is considered for the waiting list. Explain why a queue data structure would not be appropriate for this purpose. The organisers of the shot put competition use cloud-based services to record and process competition data. Describe one measure that providers of cloud-based services could take to ensure that their computer systems are environmentally friendly. An annual shot put competition is to take place in October. The program used each year to record and process competition data is being updated to allow participants to compete in three different categories: Senior, Adult or Junior.
Gantt chart should indicate: • correct list of tasks with duration in hours • concurrent Tasks 1 – 3 followed by Task 4 1 mark for correct list of tasks with correct duration in days 1 mark for concurrency of Tasks 1 – 3 followed by Task 4 A record structure would allow each attribute to be given an appropriate data type. (1 mark) This will make it easier to determine the winning distance for each category as no conversion of data type required (1 mark) 1 mark for individual data types 1 mark for importance/relevance in this example alternatively 1 mark for exemplification of use made of different data types based on scenario Recursion A stack is used by in the execution of the search procedure to allow the program to keep track of where it should return control to once a procedure has finished executing (1 mark) Whenever the search procedure is called, it is added to the call stack (1 mark) Each procedure call or recursion will have an active version in the stack (1 mark) Final call returns value to previous version in stack and terminates. This repeats until value displayed (1 mark) When the base case is reached, the last procedure call added to the stack is removed and control is passed to the previous procedure call. This repeats until the first procedure call is reached and a value is returned (1 mark) Award 1 mark description of a stack Award 1 mark for relevance in this situation This is used to terminate the recursion (1 mark) Without this, program tries to call itself indefinitely (or until memory runs out). (1 mark) Recursion will terminate when a value of -1 is returned (1 mark) 1 mark each for any two Award maximum of 2 marks for any 2 of the following: 1 mark for termination of recursion 1 mark for need to exit recursion 1 mark for termination value 1 mark for base case Line 152 SET sLongest [count] TO sLongest [count+1] Line 153 SET sLongest [count+1] TO temp 1 mark for correct use made of record structure 1 mark for correct use of temp variable to swap array[count] with array[count+1] A queue has a first in/first out principle (1 mark) As first on list may not be in the correct category may not provide correct record to add to competitors list (1 mark) 1 mark for FIFO/operation of queue 1 mark for explanation of issue arising in this example For example: Program could be executed using low carbon equipment (1 mark) This would reduce the amount of carbon emissions when the code is executed and would be an environmental friendly solution (1 mark) 1 mark for description of any appropriate solution 1 mark for justification in terms of environmental friendliness
Previous question: AH Computing Science 2016 Question 4 (CfE)