Shawlands Academy Computing Department

54
Shawlands Academy Computing Department Higher Computing Easter Study Class

description

Shawlands Academy Computing Department. Higher Computing Easter Study Class. Lesson Objectives. To examine the software development questions - from the past 4 years – which require coding to be written To practice answering questions which require coding to be written. Questions. - PowerPoint PPT Presentation

Transcript of Shawlands Academy Computing Department

Page 1: Shawlands Academy Computing Department

Shawlands AcademyComputing Department

Higher ComputingEaster Study Class

Page 2: Shawlands Academy Computing Department

Lesson Objectives

• To examine the software development questions - from the past 4 years – which require coding to be written

• To practice answering questions which require coding to be written

Page 3: Shawlands Academy Computing Department

Questions

• 2009 – Section 1 Q 12• 2009 – Section II Q 23• 2008 Section 1 Q 11• 2008 section 1 Q 12• 2008 section II Q16

• 2007 section 1 Q 14• 2007 section 1 Q 16• 2007 Section II Q20• 2010 Section 1 Q9• 2010 Section II Q 16• 2010 Section II Q 17

Page 4: Shawlands Academy Computing Department

2009 – Section 1 Q 12

• A program is being designed which generates a username using the following steps:– 1. get user initial and surname– 2. create username– 3. display the username

(a) Show how these steps could be represented using a graphical design notation.

Page 5: Shawlands Academy Computing Department

Generate User Name

get initial and surname

Create User Name

Display User Name

2 marksWARNING!!!!

Don’t confuse structure diagrams (design stage) with data flow diagrams (analysis stage)

ProcessInputs Ouput

Page 6: Shawlands Academy Computing Department

2009 – Section 1 Q 12

(b) The username is created by joining the initial to the end of the surname,

for example “CarrickE”.Name the string operation used to create the

username.

Concatenation (1 mark)

Page 7: Shawlands Academy Computing Department

2009 – Section II Q 23

A cinema ticket system allows customers to select and pay for their own tickets.

The top level algorithm is:1. Get ticket details2. Calculate cost3. Display cost and accept payment

Page 8: Shawlands Academy Computing Department

The module CalculateCost uses the number of tickets and the category of ticket to calculate the total payment due. It uses the parameters describedbelow.

Page 9: Shawlands Academy Computing Department

(a) State the most suitable data type for the parameter called Cost.

Real/single/currency (1 mark)Note: Integer is incorrect as cost is a decimal value.

Page 10: Shawlands Academy Computing Department

(b) Parameters can either be passed by value or by reference.(i)Identify one parameter that is passed by value to the module CalculateCost. Justify your answer.

•Amount or category (1 mark)•not to be changed by this module, so only current value passed in (1 mark)

Page 11: Shawlands Academy Computing Department

Parameters can either be passed by value or by reference.ii.Identify one parameter that is passed by reference to the module CalculateCost. Justify your answer.•Cost (1 mark)•This is calculated by the module and updated, the updated variable is passed back out (1 mark)

Page 12: Shawlands Academy Computing Department

(c) A program may use local variables and global variables.(i) What is the scope of a global variable?

A global variable can be used throughout the whole program - not restricted to any one subprogram (1 mark)

Page 13: Shawlands Academy Computing Department

2 from:•Increases modularity, reducing unexpected clashes between variable names•Increases portability, can re-use modules without changing variable names•Makes data flow clear, so improving readability / maintainablity(2 marks)

(ii) State two advantages of using parameter passing rather than global variables when programming.

Page 14: Shawlands Academy Computing Department

Greater range of hardware platforms means:• the larger the potential sales market• less risk of potential hardware/software conflicts• more able to deal with future upgrades by/for customers(1 mark)

(d) State one reason why portability of software is an important factor for developers to consider..

Page 15: Shawlands Academy Computing Department

(e) To calculate the total cost, the program must check the category of each ticket against the four possible categories. The programmer could use a series of IF statements or a nested IF as shown below.

Series of IF statements:IF category = ‘adult’ THEN Price=5.50IF category = ‘child’ THEN Price=3.50IF category = ‘student’ THEN Price=4.50IF category = ‘OAP’ THEN Price=4.00

Nested IF:If category = ‘adult’ THENPrice=5.50ELSE IF category = ‘child’ THENPrice=3.50ELSE IF category = ‘student’ THENPrice=4.50ELSE IF category = ‘OAP’ THENPrice=4.00END IF

(i) The programmer decides to use a nested IF. Explain why this is amore efficient method.

Each separate IF in the series will be checked even after the match is found (1 mark)Nested if will only be executed until a condition is true (then it will exit the statement) (1 mark)

Page 16: Shawlands Academy Computing Department

(ii) State one other multiple outcome selection statement that the programmer could have used.

CASE statement (1 mark)

(f) The program will make use of a 1-D array.

(i) When creating, or declaring, a 1-D array for use in a program, a name must be given to the array.State two other items that should be specified when the array is created.

•Data type•Number of elements/size of array (2 marks)

Page 17: Shawlands Academy Computing Department

(ii) Explain why it is a more efficient use of system resources to pass an array by reference rather than by value.

1 from:•Does not take up memory (1 mark) storing a second copy of the array (1 mark)OR•Does not waste processor time (1 mark) making a second copy of the array (1 mark)

You should know that when a parameter is passed by value, the subroutine makes a copy of the variable – which has to be stored in RAM

Page 18: Shawlands Academy Computing Department

2008 Section 1 Q 11A holiday booking website includes a currency converter which asks for the amount in pounds sterling and converts it to Euros. Here is the top-level algorithm, including data flow for steps 1 and 2.

1. get amount of pounds (out: pounds)2. calculate euros (in: pounds out: euros)3. display conversion ..................................

(a) State which design notation is being used.

Pseudocode (1 mark)

Page 19: Shawlands Academy Computing Department

1. get amount of pounds (out: pounds)2. calculate euros (in: pounds out: euros)3. display conversion ..................................

(b) Step 3 results in the following being displayed on screen:

State the data flow for step 3.

£500 converts to €600.

In: pounds In: euros (1 mark for each correct parameter)

Page 20: Shawlands Academy Computing Department

c) Identify whether the pounds variable in step 1 should be passed by value or passed by reference. Explain your answer.

By reference (1 mark) • the dataflow states that it is an out parameter (1 mark)

Page 21: Shawlands Academy Computing Department

2008 section 1 Q 12

12. Explain the purpose of a CASE statement in a high level language.

2 from :•Performs decision or selection • Involving two or more choices • Avoids the use of multiple or nested If statements • Increases clarity/readability

1 mark for each of two bullet points

Page 22: Shawlands Academy Computing Department

2008 section II Q16An international athletics competition between eight countries has a number of events. Here are the results for one race.

The stadium’s computer system has a program which processes and displaysthe results.(a) State two system requirements that would have been specified for theinstallation of the program.

Page 23: Shawlands Academy Computing Department

• 2 from• Amount of (available) RAM/memory • Minimum clock speed/powerful processor • Processor type • Version of OS • Identify peripherals required. • Sufficient storage capacity (2 marks)

Page 24: Shawlands Academy Computing Department

(b) The program is modular. State two benefits of creating modular code.

2 from: •Sections of code can be assigned to different programmers • Modules can be tested individually • Easier maintenance as more readable • Availability of module library • Individual modules can be amended/replaced(2 marks)

Page 25: Shawlands Academy Computing Department

(c) At the end of a race, messages are displayed. For example:

The winning country for a race is stored in a string variable called winner.Using code from a programming environment with which you are familiar, show how to extract the first three characters from the variable winner.

left(winner,3) OR winner[1:3]

1 mark for a correct function, 1 mark for correct range

Page 26: Shawlands Academy Computing Department

(d) The program stores the list of race times in a single data structure.(i) State the data structure and data type used to store the race times.

array (1 mark) of real/single (1 mark)

Page 27: Shawlands Academy Computing Department

(ii) The program must find the fastest time for a race. Use pseudocode to design an algorithm to find the fastest time

Set fastest to 1st item in array (1 mark) FOR index = 1 to 8 [for all array items] (1 mark, as long as loop is ended with next) If array(index)<fastest then (1 mark, as long as end if is used) Set fastest to array(index) (1 mark) End if End loop (4 marks )

Page 28: Shawlands Academy Computing Department

(iii) 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.

After the line “Set fastest to array(index) “ add “set position to index”

Page 29: Shawlands Academy Computing Department

2007 section 1 Q 14Programmers make use of different types of variables including Boolean.(a)Describe what is meant by a “Boolean” variable.

A variable which holds only 2 values, usually true or false ( 1 mark)

(b) Describe, using pseudocode, how a Boolean variable would be used.if item(index) = target then found = true (1 mark)

Page 30: Shawlands Academy Computing Department

2007 section 1 Q 16The string variable forename contains “Kathryn” and the variable surname contains “Barr”. The variable username is assigned the value “KatBar”using the first three characters of each name:

Use a language of your choice to show how substrings and concatenation would be used to assign the value “KatBar” to the variable username.

Page 31: Shawlands Academy Computing Department

Use a language of your choice to show how substrings and concatenation would be used to assign the value “KatBar” to the variable username.

The answer in Visual Basic would be LET username = mid(forename, 1,3)& mid(surname, 1,3) OR left(forename,3)&left(surname,3)

1 mark for assignment1 mark for concatenation, symbol (&)1 mark for both substrings in correct order

Page 32: Shawlands Academy Computing Department

2007 Section II Q20Scientists 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. Sample readings are shown below:

Page 33: Shawlands Academy Computing Department

A program has been written to perform some analysis on the data collected.(a) The temperature readings are stored in a 1-D array.(i)What is meant by a 1-D array?

• List (1 mark)• Of items of the same data type

(ii) Which data type is suitable for the array?•Real, single (“number” not aceptable )•Note: Integers are not suitable(1 mark)

Page 34: Shawlands Academy Computing Department

(b) 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 (1 mark)For counter = 1 to 1000(or for each item) (1 mark loop with termination)if temp(counter ) > 0 and temp(counter ) <10 then 2 marksAdd 1 to occurrences 1 markend ifNext

Page 35: Shawlands Academy Computing Department

2010 Section I Q9Most high level languages have several data types available a)State what is meant by a real variable.

A number with fractional part/floating point number/decimal number (1 mark)

Page 36: Shawlands Academy Computing Department

b) State the most suitable data structure and data type for storing the list called “valid” in the pseudocode shown below.

For each member of listIf gender(current) = “M” or gender(current) = “F” Then

Set valid(current) to trueElse

Set valid(current) to falseEnd If

End fixed loop

Array (1 mark) of boolean (1 mark).

Page 37: Shawlands Academy Computing Department

Mrs Laird sets her Higher Computing class the task of writing a program that will take in three items – day, month and year. These three variables will have the same data type. The program will then output a “DateofBirth” variable with six characters, as shown below.

a) State the only data type that the pupils can use for all three of the “day”,“month” and “year” variables. Justify your answer.

2010 Section II Q16

Page 38: Shawlands Academy Computing Department

String (1 mark) • “Jun” is text and must be a string • Number data types cannot accept text, text data types will accept numbers • String operations are to be carried out

1 mark for any bullet point

a) State the only data type that the pupils can use for all three of the “day”,“month” and “year” variables. Justify your answer.

Page 39: Shawlands Academy Computing Department

b) Name the operation used to extract the last two characters from the contents of the “year” variable.

Substring (1 mark)

Page 40: Shawlands Academy Computing Department

c) Part of the program will take the contents of month e.g. “Jun” and turn this into the corresponding two character value for that month e.g. “06”.

Mrs Laird tells the pupils they must not use IF statements to implement thispart of the program.

Use pseudocode to design an algorithm for this part of the program. You should show only the first two months in your algorithm.

Page 41: Shawlands Academy Computing Department

Case month ofWhen “Jan”

Set month to “01”When “Feb”

Set month to “02”

CASE must be used as the question clearly states that “IF” is not to be used.

1 mark Case statement, 1 mark for two conditions, 1 mark for both text results.

Page 42: Shawlands Academy Computing Department

d) Name the operation used to join the three values together to produce the six characters for “DateofBirth”.

Concatenation (1 mark)

e) The contents of the “DateofBirth” variable are to be held in memory in ASCII format. Calculate the minimum amount of memory required to store the contents of this variable.

8 bits per character (1 mark) = 8 * 6 = 48 bits or 6 bytes (1 mark)

Page 43: Shawlands Academy Computing Department

f) The pupils are using a procedural language to write their programs.

(i) State two features of procedural languages.

• Follows a sequence of instructions/defined start and end point • Use of subprograms/functions • Range of variable types • Program control using repetition and selection structures • Uses arithmetical and logical functions

Simplistic answers like needs to be translated, use of arrays, variables are not acceptable at this level. 1 mark for any valid, max of 2 marks

Page 44: Shawlands Academy Computing Department

f) The pupils are using a procedural language to write their programs.

(ii) State one feature of event-driven languages that is not commonly found in procedural languages. .

• Code activated/order of execution assigned to particular user action eg clicking on button • Routines/code for handling events • Predefined routines for the creation of buttons/windows/forms/etc

“No start and end point” without qualification insufficient on its own. 1 mark for any one valid.

Page 45: Shawlands Academy Computing Department

g) Mrs Laird tells the pupils that their programs must be easily maintainable.Describe two characteristics of a program that make it easily “maintainable”.

• Comment lines/internal documentation to describe code • Capitalise/highlight/embolden keywords to increase readability • Indentation/blank lines/white space to increase readability • Meaningful variable/subroutine/function names describes function of code • Modular code/use of procedures/functions • Use of parameter passing • Use of local variables

1 mark for each of two valid points, max of 2 marks Note: “Readable code” on its own is insufficient.

Page 46: Shawlands Academy Computing Department

h)Mrs Laird also tells the pupils that they must avoid the use of global variables in their programs where possible.

(i) State the meaning of the term “global variable”.

A variable that can be used/accessed/updated anywhere in a program (1 mark).

Page 47: Shawlands Academy Computing Department

(ii) Explain why the pupils have been asked to avoid the unnecessary use of global variables when programming.

• Unexpected changes to variables (1 mark) caused by variables with the same name interacting (1 mark) • Data flow is unclear (1 mark) which reduces readability (1 mark) • RAM assigned to local variables is reused (1 mark), so more efficient use of memory (1 mark) 1 mark for each part of any one bullet point, max of 2 marks

Page 48: Shawlands Academy Computing Department

2010 Section II Q 17Henry 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.

Page 49: Shawlands Academy Computing Department

a) Once the program has been written it must be translated. Describe clearly why using a compiler to translate the code produced from this algorithm would be more efficient in terms of processor usage than using an interpreter to translate the same code.

• Interpreter will translate the contents of the loops every time they are carried out • Compiler will translate the contents of the loops once only • Saving processor time by reducing the number of translations

1 mark for any two bullets. Accept other wording, but answer must relate to context for full marks.

Page 50: Shawlands Academy Computing Department

b) State one example of how text output from a program could be formatted.

Font, size, style, colour, columns/table/tab, alignment 1 mark for any valid response.

c)The company decide to include Henry’s code as a new function in their building management software.State the type of maintenance being carried out on the building management software by adding this section of code as a subprogram.

Perfective (1 mark).

Page 51: Shawlands Academy Computing Department

d) In order for Henry’s program to operate correctly for any office building two parameters would have to be passed to it.(i) State what these two parameters would be.

• Number of floors in the building (1 mark) • Number of rooms on each floor (1 mark) Accept possible names of parameters, such as floors or no_of_rooms etc but NOT floor_no or room_no

Page 52: Shawlands Academy Computing Department

(ii) State whether these parameters would be passed to the subprogram by value or by reference. Justify your answer.

• Passed by value (1 mark) • The subprogram only needs to use these values, it should not change them (1 mark)

Page 53: Shawlands Academy Computing Department

e) Another subprogram in the building management software is used to find therange 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.

Page 54: Shawlands Academy Computing Department

Set min to first temp in array Set max to first temp in array

1 mark for initialising both min and max to suitable values

For counter = 1 to no_in_list 1 mark for loop with termination

If temp(counter) > max then 1 mark for if…endif with correct max condition

Set max to temp(counter)End if

If temp(counter) <min then Set min to temp(counter) End If

1 mark for if…endif with correct min condition

Next counter 1 mark for assignment to both min and max