Presentation is loading. Please wait.

Presentation is loading. Please wait.

Higher Computing Science Answering programming questions in the exam.

Similar presentations


Presentation on theme: "Higher Computing Science Answering programming questions in the exam."— Presentation transcript:

1 Higher Computing Science Answering programming questions in the exam

2 The Haggis Reference language Programming code examples in the exam will always use the Haggis Reference language You need to be able to: Understand code written in Haggis Explain code written in Haggis You do not need to be able to: Write code written in Haggis

3 Programming constructs: Simple / Complex conditions IF studentScore > 50 THEN SET totalPass TO totalPass + 1 END IF IF age 60 = THEN SET concession TO concession + 1 ELSE SET fullFare TO fullFare + 1 END IF

4 Programming constructs: Fixed Loops SET minimumValue TO numbers[0] FOR counter FROM 1 TO 9 DO IF minimumValue > numbers[counter] THEN SET minimumValue TO numbers[counter] END IF END FOR

5 Programming constructs: Conditional Loop SET counter TO 0 REPEAT IF numbers[counter] = itemToFind THEN SET found TO true END IF SET counter TO counter + 1 UNTIL found OR counter > arraySize

6 Programming constructs: Conditional Loop WHILE userInput 100 DO SEND "Input must be between 1 and 100" TO DISPLAY RECEIVE userInput FROM KEYBOARD END WHILE

7 Logical operators: AND / OR REPEAT SEND "Please enter a value between 1 and 100" TO DISPLAY RECEIVE userInput FROM KEYBOARD UNTIL userInput > 0 AND userInput < 101 RECEIVE userInput FROM KEYBOARD WHILE userInput 100 DO SEND "Input must be between 1 and 100" TO DISPLAY RECEIVE userInput FROM KEYBOARD END WHILE

8 Simple Data Structures Data Type DefinitionExamples STRING Any set of characters from the keyboard An ARRAY of CHARACTER TD5 7EG Fred@mail.com %$£9*!aV SET name TO ["F","r","e","d"] INTEGER A number without a decimal point 3 978 -45 0 REAL A number with a decimal point 1.56 -34.6 0.03257 BOOLEAN A variable which can be either true or false True False

9 Complex Data Structures Data Type DefinitionExamples ARRAY A set of data items, all of the same data type identified using an index DECLARE names[10] AS ARRAY OF STRING DECLARE nums[10] AS ARRAY OF INTEGER RECORD A single set of values of different data types TYPE student IS RECORD {STRING forename, STRING surname, INTEGER score} SET studentA TO {forename="Jim", surname="Jonson", score=79} ARRAY OF RECORD A set of records identified using an index DECLARE s6Class[10 ] AS ARRAY OF student SET s6Class[0] TO {forename="Jim", surname="Jonson", score=79}

10 Functions and procedures A function returns a value A procedure performs a sequence of actions Functions return a value so need to be declared as returning a particular data type Function names are usually nouns, procedure names are usually verbs

11 validInteger function FUNCTION validInteger(lowerLimit, upperLimit)RETURNS INTEGER DECLARE userInput AS INTEGER INITIALLY 0 RECEIVE userInput FROM (INTEGER) KEYBOARD WHILE (userInput upperLimit) DO SEND "Input must be between" & lowerLimit "and" & upperLimit TO DISPLAY RECEIVE userInput FROM KEYBOARD END WHILE RETURN userInput END FUNCTION

12 stars procedure PROCEDURE stars (INTEGER numberOfStars) FOR counter FROM 1 TO numberOfStars DO SEND " * " TO DISPLAY END FOR END PROCEDURE

13 Formal and Actual Parameters Formal Parameters are variables which are declared when a sub-procedure or function is defined Actual parameters are used when a sub- procedure or function is called

14 PROCEDURE stars (INTEGER numberOfStars) FOR counter FROM 1 TO numberOfStars DO SEND " * " TO DISPLAY END FOR END PROCEDURE DECLARE totalStars AS INTEGER INITIALLY 0 SEND " How many stars wanted?" TO DISPLAY RECEIVE totalStars FROM KEYBOARD stars (totalStars) Actual parameter Formal parameter Formal and Actual Parameters

15 Value Parameters A value parameter is one which is passed into a procedure or function and whose value is used by that procedure When a sub procedure is called with a variable as a value parameter, a copy of that variable is made using its formal parameter while the procedure is running. The copy of the variable is destroyed when the procedure has completed, so the memory can be reused

16 Reference Parameters When a sub procedure is declared with a reference parameter then when it is called with an actual variable its value is changed by that sub procedure. When a variable is passed as a reference parameter, the reference is to the memory location of the variable itself. No copy is being made.

17 Reference Parameters The value of the variable changes as a result of calling the sub procedure with it as a parameter PROCEDURE swap (a, b) DECLARE temp AS INTEGER INITIALLY 0 SET temp TO a SET a TO b SET b TO temp END PROCEDURE

18 Standard Algorithms Input validation Finding the maximum / minimum value Linear Search Counting Occurrences

19 Input Validation Uses a conditional loop May need to check for more than one condition

20 Finding the maximum / minimum value Uses a fixed loop May use parallel arrays: e.g. given an array of pupil names and an array of their scores, find the name of the pupil with the highest mark

21 Linear Search Can use a conditional loop (find the first occurrence in the array) Uses a variable to store the index position when the target is found May use a Boolean variable to give an error message if not found Can use a fixed loop (find every occurrence in the array)

22 Counting Occurrences Uses a fixed loop to check through the array Uses a separate counter for the occurrences inside the loop May use a Boolean variable to give an error message if not found

23 Programming exam questions Writing code Debugging code Explaining code

24 Questions which ask you to write code Can be in pseudocode or a programming language of your choice Make sure that code inside loops or conditional statements is clearly delineated: IF … THEN … END IF IF ( … ) { … } FOR counter FROM 1 TO 10 DO … END FOR FOR (counter = 0, counter < 11, counter++) { … } WHILE … DO … END WHILE WHILE ( … ) { … }

25 Questions which ask you to debug code Read the question carefully Write down variable names and values for each line number Be methodical

26 Questions which ask you to explain or fix code Refer to line numbers Don’t miss out anything just because you think it is too obvious to mention Use correct terms for loops, conditions, data structures etc.

27 Links to specimen and past papers 2014 Exemplar Paper 2015 Specimen Paper 2015 Exam Paper It may be easier to follow if you can have these links open when specific questions are being discussed

28 Exemplar Paper Q 8 An algorithm will ask for a target score and then find all the (target) scores in the array and reduce them by 10. Using pseudocode, or a language with which you are familiar, complete the missing lines of code at lines 4 and 5. 1 SET scores TO [16,12,19,20,17,8,13,19] 2 RECEIVE target FROM (INTEGER) KEYBOARD 3 FOR counter FROM 0 TO 7 DO 4 IF.............. 5...................... 6 END IF 7 END FOR IF target = scores[counter] THEN SET Scores[counter] TO scores[counter]-10

29 Exemplar Paper Q9a A record data structure is used for the members’ details. RECORD Members IS {STRING surname, STRING forename, STRING username, INTEGER password} Describe how the website could store the information for five million members, using the record data structure above. DECLARE people [5000000] AS ARRAY OF Members

30 Exemplar Paper Q9b(i) When someone logs on, a search is performed using the Username that they entered. Using pseudocode, or a language with which you are familiar, write an algorithm that asks for a Username and then finds the position of that Username.

31 Exemplar Paper Q 9b(i) RECORD Members IS {STRING surname, STRING forename, STRING username, INTEGER password} DECLARE people AS ARRAY OF Members INITIALLY [] SET found TO false SET counter TO -1 RECEIVE targetname FROM (STRING) KEYBOARD REPEAT SET counter TO counter + 1 IF people[counter].username= targetname THEN SET found TO true SET position TO counter END IF UNTIL counter = 49999999 OR found= true

32 Exemplar Paper Q 10a All images on the website have been stored as bitmaps of integers, corresponding to the colour of each pixel. Explain whether this compression algorithm is lossy or lossless, by making reference to the line numbers in the algorithm Finest Fashions is an online fashion store. Customers can browse the company website, search for items of clothing and make online purchases. The screen shot below shows one page from the Finest Fashions website:

33 Exemplar Paper Q 10a 1 SET pixelPrev TO " " 2 SET runLength TO 0 3 SET counter TO 0 4 REPEAT 5 RECEIVE pixelColour[counter] FROM (INTEGER)file1 6 IF pixelPrev ≠ pixelColour[counter] THEN 7 SEND pixelColour[counter] TO file2 8 SEND runLength TO file2 9 SET pixelPrev TO pixelColour[counter] 10 SET runLength TO 0 11 END IF 12 SET counter TO counter + 1 13 SET runLength TO runLength + 1 15 UNTIL end of file1

34 Exemplar Paper Q 10a Lines 4, 5 and 6: Every pixel in the original file1 is processed. Line 13: Counts the number of consecutive pixels that are the same colour. Line 7: Sends the pixel colour to the compressed file2. Line 8: Sends the number of consecutive pixels of that colour to the compressed file2.

35 Exemplar Paper Q 10b

36 RECEIVE customerItemRating FROM WEBSITE SET itemRatings TO itemRatings + 1 SET totalRatings TO totalRatings + 1 SET averageRating TO totalRatings / itemRatings SEND averageRating TO WEBSITE

37 Exemplar Paper Q11 FUNCTION combinations (INTEGER number) RETURNS INTEGER SET factor TO 1 FOR counter FROM 1 TO number DO SET factor TO counter * factor END FOR RETURN factor END FUNCTION A program has two variables called items and permutations which contain the values 3 and 0 respectively. State the values contained in items and p ermutations after the execution of this line of code: SET permutations TO combinations(items) A function used to perform an arithmetical operation is shown below:

38 Exemplar Paper Q11 ItemsPermutationscounterfactornumber 30 113 22 36 36 SET permutations TO combinations(items)

39 Specimen Paper Q2 1 SET check TO 0 2 SET counter TO 1 3 RECEIVE registration FROM KEYBOARD 4 REPEAT 5 IF cars[counter] = registration THEN 6 SET check TO 1 7 END IF 8 SET counter TO counter + 1 9 UNTIL check = 1 OR counter = 101 Clare has just started programming and has created an algorithm to search the array cars which holds one hundred car registration numbers. Clare wishes to search for a specific registration number each time she uses the program. Clare’s algorithm is shown below.

40 Specimen Paper Section1 Q2 1 SET found TO false 2 SET counter TO 1 3 RECEIVE registration FROM KEYBOARD 4 REPEAT 5 IF cars[counter] = registration THEN 6 SET found TO true 7 END IF 8 SET counter TO counter + 1 9 UNTIL found = true OR counter = 101 Clare could have used a Boolean variable called “found” as part of this algorithm. She alters line 1 to read: 1 SET found TO false. With reference to the line numbers shown, state the other changes that Clare would need to make if she wished to use this Boolean variable.

41 Specimen Paper Section 2 Q8b 1 SET source TO [71,76,66,67,89,72] 2 SET position TO 1 3 FOR counter FROM 2 TO 6 4 IF source[counter] > source[position] THEN 5 SET counter TO position 6 END IF 7 END FOR A program has been written to find the position of the maximum value in a list, however the program stops responding. The algorithm responsible is shown below.

42 Specimen Paper Section 2 Q8b LineSourcePositionCounter 1[77,66,88,67,89,72] 2 3 5 Complete the information in the table above, recording the value assigned to the variable for line numbers 2, 3 and 5.

43 Specimen Paper Section 2 Q8b LineSourcePositionCounter 1[77,66,88,67,89,72] 2 1 3 5

44 Specimen Paper Section 2 Q8b LineSourcePositionCounter 1[77,66,88,67,89,72] 2 1 3 2 5

45 Specimen Paper Section 2 Q8b LineSourcePositionCounter 1[77,66,88,67,89,72] 2 1 3 2 5 1 (ii) Explain why the loop never terminates. (iii) Describe how the algorithm should be corrected.

46 Specimen Paper Section 2 Q8b(iii) The Counter goes back to 1 on every time the loop goes round so the terminating condition of the loop is never met 1 SET source TO [71,76,66,67,89,72] 2 SET position TO 1 3 FOR counter FROM 2 TO 6 4 IF source[counter] > source[position] THEN 5 SET position TO counter 6 END IF 7 END FOR

47 Specimen Paper Section 2 Q9a 1 SET taxCode TO “Z” 2 SET salary TO (income1 + income2) 3 IF salary < 9000 THEN 4 SET taxCode TO “A” 5 END IF 6 IF salary > 9000 AND salary < 43000 THEN 7 SET taxCode TO “B” 8 END IF 9 IF salary > 43000 AND salary < 60000 THEN 10 SET taxCode TO “C” 11 END IF 12 IF salary > 60000 THEN 13 SET taxCode TO “D” 14 END IF 15 RETURN taxCode Explain why this algorithm would return an incorrect taxCode if income1 is 30000 and income2 is 30000. This TaxCode function returns a string value from two inputs: Income1 and Income2

48 Specimen Paper Section 2 Q9b Using pseudocode or a language with which you are familiar, rewrite the algorithm to correct the logic error and make the code more efficient. SET taxCode TO “Z” SET salary TO (income1 + income2) IF salary < 9000 THEN SET taxCode TO “A” ELSE IF salary >= 9000 AND salary < 43000 THEN SET taxCode TO “B” ELSE IF salary >= 43000 AND salary < 60000 THEN SET taxCode TO “C” ELSE IF salary >= 60000 THEN SET taxCode TO “D” END IF RETURN taxCode

49 Specimen Paper Section 2 Q9c Using pseudocode or a language with which you are familiar, write an algorithm for a subroutine that will: Ask the user for the values for variables salary and bonus Use the function to assign the variable code Display code on screen RECEIVE salary FROM KEYBOARD RECEIVE bonus FROM KEYBOARD code = taxcode (salary, bonus) SEND code TO DISPLAY

50 Specimen Paper Section 2 Q10a

51 SET frequency TO 0 FOR counter FROM 1 TO 30 IF rainfall[counter]=0 AND lowtemp[counter]<0 THEN SET frequency TO frequency+1 END IF END FOR OPEN drydays SEND frequency TO drydays CLOSE drydays

52 Specimen Paper Section 2 Q10b The algorithm used to count the number of dry days below freezing is implemented as a subroutine. Describe how the subroutine could make this value available to other parts of the program. Declare it as a parameter whose value is changed by the subroutine and can then be passed to subsequent routines

53 Specimen Paper Section 2 Q11d When registering, the user must enter a valid e-mail address. This validation process is carried out by code written in a scripting language. In the language used, the syntax for an IF statement is: and the OR comparator is written using the symbol || The following code is used to validate the e-mail address: In the code above The variable length stores the number of characters in the e-mail address The variable atpos stores the position of the @ character The variable dotpos stores the position of the last dot if (expression) { command(s) } if (atpos =length){ alert(“Not a valid e-mail address”); return false; }

54 Specimen Paper Section 2 Q11d For example, if the e-mail address is myname@sqa.com then length = 14, atpos = 7 and dotpos = 11 Explain how the code above would process the validation of the e-mail address: my.name@netmy.name@net alert(“Not a valid e-mail address”); return false; expressionvalue atpos < 2false dotpos < atpos+2true dotpos + 2 >= lengthfalse atpos = 8 dotpos = 3 length = 11

55 2015 Exam Paper Section1 Q3 Line 1 SET found TO false Line 2 RECEIVE search_name FROM (STRING) KEYBOARD Line 3 FOR counter FROM 0 TO DO Line 4 IF name[counter] = search_name THEN Line 5 SET found TO true Line 6 SEND name[counter] & counter TO DISPLAY Line 7 END IF Line 8 END FOR Line 9 IF found = false THEN Line 10 SEND “Name not found” TO DISPLAY Line 11 END IF An online company uses a computer program to display particular customer records. The algorithm of this program is shown below.

56 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

57 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

58 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 trueJimmy1Samina FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

59 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 trueJimmy1Samina trueJimmy2Kate FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

60 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 trueJimmy1Samina trueJimmy2Kate trueJimmy3 FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

61 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 trueJimmy1Samina trueJimmy2Kate trueJimmy3 trueJimmy3 Jimmy 3 FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

62 2015 Exam Paper Section1 Q3 The following data is stored in the name array: Jimmy, Samina, Kate, Jimmy, Adam State the output from the above program if Jimmy is entered at line 2 from the keyboard. foundsearch_namecountername[counter]DISPLAY falseJimmy0 trueJimmy0 Jimmy 0 trueJimmy1Samina trueJimmy2Kate trueJimmy3 trueJimmy3 Jimmy 3 trueJimmy4Adam FOR counter FROM 0 TO DO IF name[counter] = search_name THEN SET found TO true SEND name[counter] & counter TO DISPLAY END IF END FOR

63 2015 Exam Paper Section1 Q7 Craig has been asked to write an algorithm that will search for a target ID from a list of fifty receipts. Each receipt has a unique receipt ID. Part of the algorithm is shown below. Line 1 SET found TO false Line 2 SET counter TO −1 Line 3 RECEIVE target_id FROM (INTEGER) BARCODEREADER Line 4 REPEAT Line 5 SET counter TO counter + 1 Line 6 IF receipt_id [counter] = target_id THEN Line 7 SET found TO true Line 8 END IF Line 9 UNTIL ……………… Using pseudocode, or a language with which you are familiar, complete line 9 of the algorithm shown above.

64 2015 Exam Paper Section1 Q7 Line 1 SET found TO false Line 2 SET counter TO −1 Line 3 RECEIVE target_id FROM (INTEGER) BARCODEREADER Line 4 REPEAT Line 5 SET counter TO counter + 1 Line 6 IF receipt_id [counter] = target_id THEN Line 7 SET found TO true Line 8 END IF Line 9 UNTIL found = true OR counter = 49 Using pseudocode, or a language with which you are familiar, complete line 9 of the algorithm shown above.

65 2015 Exam Paper Section2 Q14b Rowena accidentally entered an invalid mobile phone number and an error message is displayed. A valid mobile phone number will consist of a string of 11 digits. Using pseudocode or a programming language of your choice, write the algorithm which would check that the mobile phone number is valid.

66 2015 Exam Paper Section2 Q14b FUNCTION checkPhone (STRING mobileNumber) RETURNS BOOLEAN SET valid TO true IF Length (mobileNumber) <> 11 THEN SET valid TO False ELSE FOR counter FROM 1 TO 11 DO IF (Mid(mobile_number, counter, 1) < "0") OR Mid(mobile_number, counter, 1) > "9") THEN SET valid TO false END IF END FOR END IF RETURN valid END FUNCTION

67 2015 Exam Paper Section2 Q14c An algorithm is implemented to validate the applicant’s data from the application form. There are two subprograms at lines two and three. The parameters for these subprograms are not shown. Line 1 REPEAT Line 2 Enter_applicant_data (…) Line 3 Validate_form_data (…) Line 4 UNTIL Name a parameter that should be passed at line 2, State the type of Parameter passing used and justify your answer. title, firstName, surname, gender, emailAddress, or mobilePhoneNumber. Passed by reference as it will be updated and returned for line 3 to process

68 2015 Exam Paper Section2 Q17a Chris wants a program to process information about each of the pupils in his class. Line1 RECORD Test_marks IS {STRING surname, INTEGER mark_1, INTEGER mark_2, INTEGER mark_3, STRING email} Line2 SET pupil[1] TO (“Smith”, 67, 89, 91, “john@doodle.co.uk”) Line3 SET pupil[2] TO (“Latif”, 42, 91, 84, “fatima@doodle.co.uk”) Line4 SEND pupil[1].mark_2 TO DISPLAY (i) Explain the purpose of line 2. (i)State the output from line 4.

69 2015 Exam Paper Section2 Q17a Chris wants a program to process information about each of the pupils in his class. Line1 RECORD Test_marks IS {STRING surname, INTEGER mark_1, INTEGER mark_2, INTEGER mark_3, STRING email} Line2 SET pupil[1] TO (“Smith”, 67, 89, 91, “john@doodle.co.uk”) Line3 SET pupil[2] TO (“Latif”, 42, 91, 84, “fatima@doodle.co.uk”) Line4 SEND pupil[1].mark_2 TO DISPLAY (i) Explain the purpose of line 2. It assigns values to element at position 1 in the array of Test_marks records (i)State the output from line 4. 89

70 2015 Exam Paper Section2 Q17a (iii) Chris wants to calculate the average for the first pupil. Using pseudocode, or a language with which you are familiar, write the line to calculate this average.

71 2015 Exam Paper Section2 Q17a (iii) Chris wants to calculate the average for the first pupil. Using pseudocode, or a language with which you are familiar, write the line to calculate this average. SET average TO (pupil[1].mark_1+ pupil[1].mark_2+ pupil[1].mark_3)/3

72 Chris calculates the average mark for each pupil and stores the average marks in an array. He writes the following pseudocode to count the number of grade A passes of 70 or more Line 1 SET list TO [74.33, 57.67, 73.33, 82.33] Line 2 SET amount TO 0 Line 3 FOR counter FROM 0 TO 2 DO Line 4 IF list[counter] >= 70 THEN Line 5 SET amount TO amount + 1 Line 6 END IF Line 7 END FOR Line 8 SEND amount TO DISPLAY 2015 Exam Paper Section2 Q17b

73 When Chris tests the program, it outputs the wrong number of A passes. (i) State the output from the code above. (ii) State the name of this type of error. (iii) Identify and correct the line of the algorithm which contains the error. amountcounterlist[counter] 0074.33 FOR counter FROM 0 TO 2 DO IF list[counter] >= 70 THEN SET amount TO amount + 1 END IF END FOR

74 2015 Exam Paper Section2 Q17b When Chris tests the program, it outputs the wrong number of A passes. (i) State the output from the code above. (ii) State the name of this type of error. (iii) Identify and correct the line of the algorithm which contains the error. amountcounterlist[counter] 0074.33 1157.67 FOR counter FROM 0 TO 2 DO IF list[counter] >= 70 THEN SET amount TO amount + 1 END IF END FOR

75 2015 Exam Paper Section2 Q17b When Chris tests the program, it outputs the wrong number of A passes. (i) State the output from the code above. (ii) State the name of this type of error. (iii) Identify and correct the line of the algorithm which contains the error. amountcounterlist[counter] 0074.33 1157.67 1273.33 FOR counter FROM 0 TO 2 DO IF list[counter] >= 70 THEN SET amount TO amount + 1 END IF END FOR

76 2015 Exam Paper Section2 Q17b When Chris tests the program, it outputs the wrong number of A passes. (i) State the output from the code above. (ii) State the name of this type of error. (iii) Identify and correct the line of the algorithm which contains the error. (ii) Logic Error (iii) Line 3 FOR counter FROM 0 TO 3 DO amountcounterlist[counter] 0074.33 1157.67 1273.33 2

77 2015 Exam Paper Section2 Q17b When Chris tests the program, it outputs the wrong number of A passes. (i) State the output from the code above. (ii) State the name of this type of error. (iii) Identify and correct the line of the algorithm which contains the error. (ii) Logic Error (iii) Line 3 FOR counter FROM 0 TO 3 DO amountcounterlist[counter] 0074.33 1157.67 1273.33 2

78 2015 Exam Paper Section2 Q17c Chris creates an algorithm that will search the array of average marks and return the smallest value present. Line 1 SET list TO [74.33, 57.67, 73.33, 87.33] Line 2 SET minimum TO list [0] Line 3 FOR counter FROM 1 TO 3 DO Line 4 IF minimum > list[counter] THEN Line 5 SET minimum TO list[counter] Line 6 END IF Line 7 END FOR return the smallest value present.

79 2015 Exam Paper Section2 Q17c A trace table is used to record the change to a variable at the corresponding line number. Part of the trace table is shown below. State the values missing from the trace table below at A, B and C. A – 74.33 B – 1 C – 57.67


Download ppt "Higher Computing Science Answering programming questions in the exam."

Similar presentations


Ads by Google