Describe the difference between passing a parameter by value and by reference.
By reference the function receives the memory location of the data
By value the function receives a copy of the variable
By reference will make changes to the original variable
By value will make changes to the copy of the variable
By reference will overwrite data in the original variable
By value will not overwrite the data in the original variable
By reference will keep the changes after the function ends
By value will not keep the changes after the function ends
Give one benefit and one drawback of declaring the array as a global variable instead of a local variable.
Benefits:
Variable doesn’t need passing as a parameter (byref)
You don’t need to return a value
Can be accessed from any function / anywhere in the program
Drawback:
Increases memory usage (as it is used until full program execution is over)
Alterations within the function may have unwanted side effects elsewhere in the program
Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program
Write:
Auto-complete - Start typing an identifier/command and it fills in the rest
Test:
Breakpoints - Stop the program running at a set point to check variables
State why performance modelling is used to test a system.
Simulate/model behaviour of the system (before it is) used under load
Because it would be too expensive/unsafe/time critical to test the real system
State two features of any recursive algorithm
A function that calls itself and has a base case (that terminates the recursion)
State the purpose of the constructor.
To create an instance of an object from a class
Describe what is meant by inheritance
When the child subclass class takes on attributes/methods from parent/superclass
Identify the stage(s) and instruction(s) run during each pipeline
Interval 1
A is fetched
Interval 2
A is decoded
B is fetched
Interval 3
A is executed
B is decoded
C is fetched
Interval 4
B is executed
C is decoded
D is fetched
Explain why pipelining can improve the performance of the processor.
Reduces/removes latency
CPU is not idle while waiting for next instruction
Next instruction is fetched while current one is decoded/executed
All parts of the processor can be used at any instance in time.
Compare two differences between recursion and iteration
Recursion uses more memory
iteration uses less memory
Recursion declares new variables //variables are put onto the stack each time
iteration reuses the same variables • Recursive can run out of memory/stack space
while iteration cannot run out of memory
Recursion can express a problem more elegantly // in fewer lines of code
while iteration can take more lines of code // be harder to understand Recursion will be self-referential // will call itself… • … whereas iteration does not
Describe one difference between get methods and set methods.
A get method allows the attribute to be accessed / returned
A set method allows the attribute to be changed (with parameters)
Barney will use an Integrated Development Environment (IDE) to debug his program code.
Describe three features commonly found in IDEs that Barney could use to debug his program code.
Stepping Through The Code - to run one line at a time to see where the error is
Syntax Error Highlighting - to distinguish syntax errors in the program code
Setting breakpoints - to debug individual sections of code at a time
Variable watch window - To check that the variables are being updated corrected
Discuss the benefits of using different object-oriented techniques
Objects can be given a different identifier by the other programs.
Further subclasses may be used by other programs. These can therefore take on the attributes and methods from the base class. These can also be changed or overridden depending on the purpose of the other programs.
Encapsulation can be used by using set and get methods to ensure it is changed in a way that is intended.
OOP also allows programs to be easier to modify and maintain.
Evaluate the use of data mining
Extracting data from databases
Using large data sets
Looking for patterns/specific occurrences of data
Gathering data that can be analysed and used to inform decision
Can identify areas to focus attention
Save time and money by identifying areas that are not popular/used
New features targeted at specific groups could bring in new business e.g. advertising
But care would need to be applied to privacy issues / GDPR and potential impact on the user
Mabel has been told that true programmers write programs in a text editor, and do not use IDEs. Mabel does not agree with this statement.
Discuss the use of an IDE in the development of this program.
Tools to aid writing
Coloured font
Predictive text
Auto-correct
Tools to aid de-bugging
Stepping
Break points
Variable watch window
Can reduce spelling errors
Can use to fix errors that might occur
Increase speed of writing
Fewer mistakes
Increase speed of testing / finding errors
Collaborative team working facilitate
Explain the difference between branching and iteration.
Branching decides which code is run / only runs code once
Iteration repeatedly runs the same code in the same sequence
State whether the parameters should be passed by value, or by reference. Justify your answer
By Value - the original values do not need to be modified
byRef would not work / would cause the routine to crash
Describe the arithmetic operation of MOD. Use an example in your answer
Gives the remainder after division
E.g. 10 MOD 3 = 1
State one benefit and one drawback of using iteration instead of recursion
Benefit:
The program can/might run faster
Cannot run out of stack space/memory
Easier to trace/follow
Drawback:
Iteration can lead to lengthier code
Iteration can lead to code that looks more complex / is harder to understand
Some problems are more elegantly coded with a recursive solution
One sub-procedure will handle the user input.
Describe three other sub-procedures Mabel could create for the given game description.
Select character (name, gender) - Gives the user options for choosing a character
Choose level - Give the user the choice of level (easy, normal, challenging) and take the user input
Touch enemy - Called to determine if the character touches an enemy
Lose life - Remove a life, if <0 then game over
End level - Move onto next level
Describe the decision that the program will need to make within the user input sub-procedure and the result of this decision
Decision based on what the user has input
E.g. If they click left move the character left
if they click right move the character right
if they click space bar make the character jump
Define pipelining and give an example of how it could be applied in the program.
The result from one process / procedure feeds into the next
E.g. the result of detecting a character touching an enemy feeds into reducing the number of lives
Define the term ‘data mining’.
Turning large quantities of data into useful information / Finding patterns within large quantities of information
Mary plans to use data mining to generate information about OCRRetail’s customers. Mary will use this information to benefit the company.
Identify two pieces of information that data mining could provide OCRRetail about sales, and state how OCRRetail could make use of this information
Identify customer trends -To identify items to sell/offers to send customers
Identify which stores are making the most profit - To identify what the other stores are doing well
Which items are not selling well - To replace them with other items
Define the term ‘performance modelling’
Simulate/test the behaviour of the system before it is used
Identify one way performance modelling could be used to test the new system
Testing it with a large number of simultaneous orders (stress testing)
Testing it with a large number of customers/items/order
Identify two advantages of using a visualisation such as the one shown in Fig. 3.
Visualisations present the information in a simpler form to understand
Visualisations can best explain complex situations
The parameter, num1, is passed by value.
Explain why the parameter was passed by value instead of by reference.
If the value is sent by value, num1 will not be overridden / it is a copy of the parameter that is used and this will produce the correct output
if the parameter had been passed by reference it would not produce the correct result as num1 would be overridden / because it is a pointer to the address of the variable
Parameters can be used to reduce the use of global variables. Compare the use of parameters to global variables in recursive functions
Local variables can only be accessed within the scope of the sub-program it's defined within
If global, equivalent of by reference -value would be over-ridden
Global variable takes more memory than a local variable/parameter
In recursion, each call produces a new local variable for num1
Global would require altering the algorithm as the value would be over-ridden on each call
Parameter enables memory to be reallocated
Explain why a recursive algorithm uses more memory than the iterative algorithm
Each recursive call stores the current state on the stack creates new variables
Iteration reuses the same variables
Explain the similarities and differences between a record and a class.
Record is a data structure
A class is a template for making data structures (objects)
Class also has methods (which describes functionality)
Both store data of different types
Which can be accessed by their names
But classes can make them accessible via methods
Both can have multiple ‘instances’
Class can include visibility of properties / private
The attributes in itemQueue are all declared as private.
Explain how a private attribute improves the integrity of the data
Properties (are encapsulated) and can only be accessed through their methods
Enforce validation through the method
inappropriate data can be caught before entered
Cannot be changed/accessed accidentally
Describe two advantages of splitting the problem into sub-procedures
Procedures can be re-used
No need to reprogram/saves time
Program can be split between programmers - Can specialise in their area
Speed up completion time - As multiple procedures worked on concurrently
Easy to test/debug - As each module can be tested on its own then combined.