8
HIGHER COMPUTING SOFTWARE DEVELOPMENT CLASS QUESTIONS STANDARD ALGORITHMS 1. Scientists are interested in studying the possible effects of global warming. Devices are placed at various locations to record temperatures. Each device takes one thousand temperature readings per day. A program has been written to perform some analysis on the data collected. The program must find how many of the 1000 readings are above zero and less than ten degrees. Use pseudocode to write an algorithm which would determine the number of readings in this range. set occurrences to 0 loop 1000 times (or for each item) IF temp( ) > 0 AND temp( ) < 10 THEN increment occurrences END IF end loop 2. A university awards their students a grade of 1 to 4 for their performance in an examination. Two thousand students sit the examination. A program is to be written that will calculate the number of occurrences of each grade and will display this in a frequency table as shown below. The data items are: grades () : an array of 2000 integers occurrences () : an array of 4 integers The top level algorithm is: 1. get grades out ( grades () ) 2. count occurrences of each grade in ( grades () in/out, occurrences () ) 3. display frequency table in ( occurrences () ) Use pseudocode to design step 2 which counts the number of occurrences of each of the four grades. loop 2000 times SELECT CASE grade() CASE = 1 increment occurrences(1) CASE = 2 increment occurrences(2) END SELECT end loop Grade Frequency 1 301 2 689 3 585 4 425

HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

Embed Size (px)

Citation preview

Page 1: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

HIGHER COMPUTING SOFTWARE DEVELOPMENT

CLASS QUESTIONS

STANDARD ALGORITHMS 1. Scientists are interested in studying the possible effects of global warming. Devices are placed at various locations to record temperatures. Each device takes one thousand temperature readings per day. A program has been written to perform some analysis on the data collected. The program must find how many of the 1000 readings are above zero and less than ten degrees. Use pseudocode to write an algorithm which would determine the number of readings in this range. set occurrences to 0 loop 1000 times (or for each item) IF temp( ) > 0 AND temp( ) < 10 THEN increment occurrences END IF end loop 2. A university awards their students a grade of 1 to 4 for their performance in an examination. Two thousand students sit the examination. A program is to be written that will calculate the number of occurrences of each grade and will display this in a frequency table as shown below. The data items are: grades () : an array of 2000 integers occurrences () : an array of 4 integers The top level algorithm is: 1. get grades out ( grades () ) 2. count occurrences of each grade in ( grades () in/out, occurrences () ) 3. display frequency table in ( occurrences () ) Use pseudocode to design step 2 which counts the number of occurrences of each of the four grades. loop 2000 times SELECT CASE grade() CASE = 1 increment occurrences(1) CASE = 2 increment occurrences(2) END SELECT end loop

Grade Frequency 1 301 2 689 3 585 4 425

Page 2: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

3. A website has been created by a software house for a bank. A program has been written to count and record the number of times each page linked to the home page is visited or “hit”. The number of hits for each page is stored in an array. For example: Hits(1) = 1078. Using a design notation with which you are familiar, write an algorithm which would find the page with the maximum number of hits within the website. Max = 1 FOR Page=2 to total_no_of_pages IF hits(page) > hits(max) THEN Max= page End If NEXT 4. A program has been produced to store and process names and the times of competitors in a 100 metres sprint. The fastest runner has to be found. Which of the following algorithm would be used within the program in order to find the fastest runner? • Counting Occurences • Finding the maximum • Finding the minimum • Linear Search

Finding the minimum

5. A multimedia catalogue to help identify and record sightings of birds common to the UK is being constructed. Part of the program will ask the user for the name of a bird and search a list of names to see if it exists and display the position of the name in the list. For example, if the name is third in the list, the number 3 is displayed. If the name is not in the list a zero is displayed. Use pseudocode to show how this section of program will search the list and display the appropriate value on screen. set found to 0 FOR each member of the array IF target = array(current) THEN set found = current NEXT display found 6. A computer program to run the registration process at Dunwearie High School is being developed. Part of the program will take in a pupil’s surname and find the position of the pupil in a list. If the pupil is not found it reports this as an error. Using a design notation with which you are familiar, describe the part of the program that finds the position of the pupil in the list and reports an error if the pupil is not found. set found to zero FOR each item in list IF name$ = array(index) THEN set found to index END IF NEXT item IF found = 0 THEN display error

Page 3: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

7. A computer program analyses data by finding how may females responded responed to a survey. Which one of the following algorithms would be required to do this? • Finding maximum • Counting occurrences • Linear search • Finding minimum Counting occurrences

8. A billing program will calculate the cheapest fare and produce monthly accounts for each passenger. Which standard algorithm is most likely to be used in this billing program?

Finding minimum

9. The Scottish Tree Foundation has commissioned a piece of software to be written to gather information for a national survey of trees in Scotland. One module of the program will take a tree name from the user an will count all occurrences of that name in the current list of trees. The module will return the number of times the name appears in the list or zero if the name is not found. Using pseudocode or otherwise, write a detailed algorithm for this process.

Set occurrences to 0 FOR each item in the list IF tree() = target THEN increment occurrences END IF NEXT item Display occurences

10. A program holds a list of the names of all open application windows in an

appropriate data structure. When a window is selected, a software module finds the position of that window in the list. For example, when the user clicks on a window, the module checks the list and returns its position in the list. Use pseudocode to fully describe the process of identifying the position of the name in the list.

Set position to 0 Set current position to 1 Loop until end of list OR position > 0 IF name at current position = window name Set position to current position END IF Add 1 to current position

End loop

Page 4: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

11. A school library has just bought a program to record book loans. One of the program’s modules asks for the name of a book and returns the name of the pupil who borrowed it. Which standard algorithm is most likely to be used in this module? Linear search 12. A program is being written to analyse the number of road traffic accidents in six areas of Scotland. The names of the areas and the number of accidents are stored in two separate arrays. One of the program’s functions is to find the area with highest number of accidents. Using pseudocode describe an algorithm that will find the position of the maximum number in the accidents array. FOR current position 1 to 6 IF number at current position > position of current maximum THEN Set position of current maximum to current position END IF NEXT position 13. A list of medals won at the Olympic Games is stored in a computer. For each medal, details of the event, name and country of the winners are stored. A program was designed to work out how many medals overall each country won. Which standard algorithm would be needed in this program? Counting occurrences 14. A program is being written that will search for a value in a list of integers. The program will report whether the value has been found together with the position of the first occurrence of the value in the list of integers. An appropriate error message will be reported if the value is not present in the list of integers. The main algorithm steps are:

1. get search item 2. search list of numbers for search item 3. display findings The programmer has decided to modify this algorithm to store the positions

of all of the occurrences of the search item in the list of integers. (i) What change will be required in the loop in step 2? (ii) What additional data items will be required to store all of the

positions where the search item is found? (i) removal of the condition “item not found” (ii) require an array ofdata type integer to store list of positions.

Page 5: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

Require a counter of type integer to store the number of items found.

15. An international athletics competition between eight countries has a number

of events. Here are the results for one race.

(i) The stadium’s computer system has a program which processes and

displays the results. The program stores the list of race times in a single data structure. The program must find the fastest time for a race. Use pseudocode to design an algorithm to find the fastest time.

(ii) It is suggested that it would be preferable for the algorithm to find the

lane number of the fastest time rather than the fastest time. Explain how this could be achieved.

(i) Set fastest to 1 000 000 [number over range]

Loop 8 times for each array item If array(current)<fastest then

Set fastest to array(current) End if

End loop (ii) Each time the fastest is reassigned, set a position variable equal to the

loop counter (Set fastest to current) 16. NoTow would like the software to calculate the number of cars on a particular day

that spent more than three hours in the car park. The number of whole minutes each car is parked in the car park is stored in a list, as shown on the right.

Use pseudocode to design an algorithm to carry out this calculation.

Set over3 = 0

For each car that day If duration >180 then

Add one to over3 End if

End loop 1 mark for initialising

Lane Number Country Time 1 Ireland 40.23 2 Italy 41.05 3 England 42.88 4 France 39.89 5 Germany 40.55 6 Poland 40.01 7 Scotland 39.87 8 Wales 42.55

Page 6: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

1 mark loop with termination 1 mark for if..endif with correct condition 1 mark for keeping running total Note: End of if/loop may be implicit in clearly indented algorithm The value is in minutes so the condition is > 180

17. Henry works for a company that maintains office buildings. He decides to write a

program to print labels for the room keys in a new office block. The block has 38 floors, each with 25 rooms. The label will consist of the floor number and the room number. The design for the program is shown below alongside a sample section of output.

Another subprogram in the building management software is used to find the range of temperatures in a building in one day. The temperature is recorded every 15 minutes within a 24 hour period and stored in a list. Use pseudocode to design one algorithm to find both the highest and lowest temperatures in this list.

Set min to first temp in array

Set max to first temp in array For each temp()

If temp(current)>max then Set max to temp(current)

If temp(current)<min then Set min to temp(current)

End If Next temp()

1 mark for initialising both min and max to suitable values 1 mark loop with termination 1 mark for if…endif with correct max condition 1 mark for if…endif with correct min condition 1 mark for assignment to both min and max Note: nested Ifs may be used Note: if max and min algorithms are written separately award full marks Note: End If can only be omitted where indentation is unambiguous where if/loop ends

Page 7: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

18. RightIT, a software company, is currently developing a cash machine program for a bank. The cash machine will offer five options to customers.

The options selected during a day are stored in a list. The bank would like the software to calculate the number of times the mobile top-up option appears on this list. Use pseudocode to design an algorithm to carry out this calculation. Total=0 For each option() chosen that day

If option(current) = mobile top-up then add 1 to total

end if next transaction

19. Over the summer, a garden centre has been running a “tallest sunflower”

competition.

Entrants have completed an online entry form to provide their name and the height of their sunflower. These have been collated into two lists. Samples from these lists are shown below.

(a) Using pseudocode, design an algorithm to find and display the name of the person growing the tallest sunflower.

Page 8: HIGHER COMPUTING SOFTWARE DEVELOPMENT … COMPUTING SOFTWARE DEVELOPMENT . CLASS QUESTIONS . STANDARD ... Use pseudocode to design step 2 which counts the number of ... 1 301 2 689

(b) The garden centre wants to give a consolation prize to the grower of the shortest sunflower. A number of changes need to be made to the pseudocode you wrote in part (b).

(i) State one change that you would make to your pseudocode from part

(b).

• Change initial condition to smallest = height[1] • Change > to < OR ‘change greater than to less than’ • Change variable names to eg tallest to smallest / max to min (as

appropriate to candidate answer in (b)) • Change output line

(ii) Explain why this change is necessary.

• Change initial condition to smallest = height[1] which can be reset when

a lower value is found • Change > to < since looking for smaller values than the current one • Change variable names to eg tallest to smallest/max to min to reflect

meaningful variable names • Change output line to reflect change in variable name/new context if

name is in descriptive text • Accept responses referring to the fact that “find min”, rather than “find

max”, is required as these are not named in the question