System: You are ChatGPT, a large language model trained by OpenAI.
User: I will send you a body of text, I will then state what you do next.
User: 224Subroutines, local and global variables LEARNING OBJECTIVESIn this chapter you will learn: •what a subroutine is and how they are used to create programs •how to create subroutines•what a function is and how to create them •what parameters and arguments are and how they are used withina func tion•what local and global variables are. A-level students will learn: •what an exception is and how a program should deal with it. INTRODUCTIONIn programming a subroutine  is a named block of programming code  that performs a speciﬁ  c task. All programs therefore are made up of a series of subroutines. They provide structure to programs in the same way that chapters provide structure to a book. Subroutines are also called procedures , subprograms  or routines . Subro utines use variables that can either be local or global. Local variab les are those that can only be used within that subroutine whereas global variables  are accessible throughout the program.SPECIFICATION COVERAGE 3.1.1.9 Exception handling 3.1.1.10 Subroutines (procedures/functions)3.1.1.11 Parameters of subroutines3.1.1.12 Returning a value/values from a subroutine3.1.1.13 Local variables in subroutines3.1.1.14 Global variables in a programming languageKEYWORDS Subroutine: a named block of code designed to carry out a specific task. Procedure: another term for a subroutine.Su bprogram: another term for a subroutine.Ro utine: another term for a subroutine. Local variable: a variable that is availa ble only in specified subroutines and functions.Global variable: a variable that is availa ble anywhere in the program.SUBROUTINES 23●SubroutinesA subroutine is self-contained and it carries out one or more related processes. These processes are sometimes called algorithms, which in turnare made up of lines of code. Subroutines must be given unique identifiersor names, which means that once they have been written they can be calledusing their name at any time while the program is being run.
 For example you may want to write a program to maintain the contents ofa file. You would need to write code to handle tasks such as adding a newrecord, amending existing details and deleting an old record. In this caseyou might have a subroutine to handle events  that are generated froma mai n men u and then each of the three tasks has its own subroutine.
 For example if the variable Selected  is set to Add then the procedure AddRecord  would be called.
 Subroutine MainMenuInput SelectedIf Selected = "Add" Then Subroutine AddRecordIf Selected = "Amend" Then Subroutine AmendRecordIf Selected = "Delete" Then Subroutine DeleteRecord End Subroutine: Subroutine AddRecord‘Code to add a new record to a fileEnd Subroutine: Subroutine AmendRecord‘Code to locate and amend an existing recordEnd Subroutine: Subroutine DeleteRecord‘Code to delete an existing recordEnd SubroutineBreaking up a program into manageable blocks like this has many benefits: ●They can be called at any time using the subroutine’s unique name.
 ●They allow you to gain an overview about how the program is putogether. ●You can use a top-down approach to develop the whole project. ●The program is easier to test and debug because each subroutine is self-conta ined.
 ●Very large projects can be developed by more than one programmer.Vis ual Basic forces you to work with subroutines. In Visual Basic as soon as you try to write code that is connected to a control, Visual Basic creates a subroutine for you. Object-oriented programming takes this concept KEYWORDEvent: something that happens when a program is being run. 4 Subroutines, local and global variables 24one stage further by putting all the code and the relevant data in the same module  and the modules are put together to form the overall program. In this context a module is one part of a program that may contain several  subroutines. See Chapter 6 for more details. ●Functions Functions  are similar to subroutines but return a value. For example, mostmodern pocket calculators have a large range of functions. The most basic are probably the square and square root keys. The idea is that you entera number, press the function key you want and the calculator gives you aresult based on that number.A function in a computer program performs much the same task as the buttons on a calculator. The user supplies the function with data and thefunction returns a value. For example you could create a function thatcalculates the volume of a cylinder – you supply the height and radius andthe function returns the volume. This process is not limited to numeric data; for example, you could createa function to count the number of times the letter ‘h’ occurs in a givenblock of text, or to check to see if a file has read/write or read-only accessrestrictions in place.
 There are two benefits of using functions in a program: ●Some processes are very complex and involve many lines of code, but in thend they p roduce a single result. Including all those lines of complex codein the middle of your program will probably make it harder to understand,so instead you could put the code in a function and put the function itselfsomewhere else in the program, away from the main body of the program.This also means that if you want to alter the function it is easier to find. Italso makes the main body of the code easier to work through. ●If you have to carry out the same process in lots of different places in the program, then instead of having to rewrite the same code over and over again, you would create the code once as a function and call it fromthe various places through the program. This has the benefit of keepingprograms smaller, and if you need to alter the way the function works,you only have to alter one version of it.
 Functional programming  is a method of programming that only uses funct ions. There is more on this in Chapters 46 and 47.
 ●Parameters and argumentsIn order for a subroutine or function to operate efficiently you need a way tocontrol the data that it takes in. This is usually done by using parameters and arg uments. A parameter works like a variable in that it identifies the data that you want a subroutine to take in and use. The argument  is theactual va lue being passed to the subroutine.
 The way that this is implemented varies depending on the programminglanguage being used. As the subroutine being called is external to thecurrent subroutine, there needs to be a mechanism for ensuring that theprogram knows how to handle the subroutine that has been called. It doesthis using a block interface , which is essentially a block of code thatspecif ies the type and characteristics of the data being passed.KEYWORDModule: a number of subroutines that form part of a program.
 KEYWORD Function: a subroutine that returns a v alue.
 KEYWORDFunctional programming: a programming paradigm that uses functions to create programs. KEYWORDSParameter: data being passed into a subroutine. Argument: an item of data being passed to a subroutine. Block interface: code that describes the data being passed from one subroutine to another.Figure 4.1 Function keys on a calculatorLOCAL AND GLOBAL VARIABLES 25●Local and global variablesAs we have seen, it is highly likely that your program will be split up into lots of subroutines and functions. If you do this then you have to decide onthe scope of any variables created. This means you have to construct yourprogram in a way that either: ●limits the existence of the variable to the subroutine or function in whichit was declared – a local variable, or ●allows the variable to be used anywhere in the program – a global variable. The value of a variable is constantly changing throughout the program and as you have seen, values may be passed around between subroutines. If the subroutine changes the value stored in the variable, this may be passed back to the original subroutine or on to another subroutine. An important aspect of programming is keeping track of the state of variables and one of the main causes of program errors is when the value of a variable is changed within one subroutine, that then has an impact on another subroutine. This is known as a side effect.It is good practice to use local variables wherever possible and using them  has a number of advantages: ●You cannot inadvertently change the value being stored somewhere elsein the program. ●You could use the same variable name in different sections, and each could be treated as a separate variable.
 ●You free up memory as each time a local variable is finished with, it is removed from memory. You should only use a global variable where it needs to be available throughout the whole program. For example, you might store the password to a program as a global variable if you wanted to make a password accessible to different sections of your code.
 When programming, different syntax is required to indicate whether the variable is local or global. For example in Visual Basic: ●Local variables are declared using the Dim  statement: Dim Age As Integer  declares a local variable called Age. ●Global variables are described as public: Pub lic Password As Text  declares a global variable calledPassword .In Python all variables are assumed to be local when they are defined. If you want a variable to be global you must tell Python to make it global by using the global  keyword, which actually declares functions not local variables. ●global Password  cr eates a global variable called Password●Password = "password"  cr eates a local variable called Password .In some programming languages if you declare a variable in your code and it is not inside a subroutine or function, then it is assumed to be global. Therefore you need to be careful when declaring variables. The following extract of code shows how you might set Password as a global variable and then other variables as local in Visual Basic: 4 Subroutines, local and global variables 26Public Password As String Private Sub CalculateMathsGradeDim Score As IntegerDim Grade As StringIf Score > 50 then Grade = "Pass"Else Grade = "Fail"End SubPrivate Sub CalculateEnglishGrade Dim Score As IntegerDim Grade As StringIf Score > 50 thenGrade = "Pass" ElseGrade = "Fail" End subThere are two subroutines: CalculateMathsGrade  and CalculateEnglishGrade.  The variable Password  is a global variable and therefore is accessible from either of the two subroutines. The Score and Grade  variables are local to each subroutine. This means that although they have the same names in both, they are actually different variables containing different values, a bit like having two people called John Smith with different characteristics.
 ●Exception handlingThere are many situations where a subroutine has to stop because of anexceptional circumstance that causes an error. This is not necessarily anunexpected event, just one that causes the current subroutine to stop. Anexample would be a division by 0 error, where the subroutine is expecting anumber, but instead gets an undefined value caused by the division. Whenthis happens, the subroutine has been ‘thrown’ an error, which it must dealwith. If it is unable to ‘catch’ the error, the program could produce a fatalerror, causing the program to stop running completely.In the same way that subroutines are triggered by events, there need to be blocks of code that handle errors that are triggered whenever the erroroccurs. These are often referred to as catch blocks, which are specific blocksof code that are triggered in response to specific errors.
 The normal procedure when this happens is: ●an error is thrown so the current subroutine stops or is paused●the current state of the subroutine is saved ●the exception handling code (or catch block) is executed to take care ofthe error ●the normal subroutine can then be run again, picking up from where it was saved.KEYWORD Exception handling: the process of dealing w ith events that cause the current subroutine to stop.A level onlyEXCEPTION HANDLING 27Exceptionunexpected ExceptionexpectedNormal program flow Exception handlerException Fatal program err orFigure 4.2 The exception handling process Practice questions can be found at the end of the section on pages 46 and 47. TASKS1 Define the following terms and explain the difference between the two: a) subroutine b) function.
 2 Give examples of in-built functions that you might find in a  programming language.3 Why is it good practice to construct programs using subroutines?4 What is the advantage of using functions? 5 Define the following terms and explain the difference between the two: a) algorithm b) code.
 6 What is a module and how does it differ from a subroutine?7 Explain how parameters and arguments are used to pass values and variables into subroutines.8 What is a block interface? 9 Why is it good practice to use local variables whenever possible?10  Give an example of where you might use a global variable. 11  Explain how an exception handler works.
 STUDY / RESEARCH TASKS1 Write a program that calculates the square and square root of any given number. Try to include the following features: a)a subroutineb)a function c)a subroutine or function calld)a parameter or argument e)a local variablef)a global variable.2 Extend your program to include other common mathematical functions. 3 Write a program that takes in a set of numbers and then calculates the  mean, median and range using either in-built or user-deﬁned functions.4 Find examples of typical events that would require exception handling code.KEY POINTS •Subroutines or proceduresare a way of breaking up code into manageable blocks ofcode, each of which performsa speciﬁc task. •Subroutines are likely to haveother related subroutines. •Breaking a program up intosubroutines is beneficial for several reasons, mainlyrelated to being easier tomanage and maintain theprogram.•A function is a type ofsubr outine that returns a setvalue, for example, the squareroot function. •Parameters and argumentsare the data that are passed into the function on which itperforms its computations.
 •Local variables can only beused within the subroutine in which they were created.
 •Global variables can be usedanywhere in a program. •Exception handling is the wayin which the program deals with events that may cause itto stop.
User: Make the following text more clear.
Format it properly.
Do NOT change the meaning of the words or methods used to obtain the answer or anything like that.
This is for AQA A(S)-Level Computer Science. I repeat, do not alter the words as it could have an effect on the marks acquired from the marking scheme.
However, remove any redundant information or USELESS examples that are not needed for a student to know, or simplify unnecessary information (if it has a definition or keywords, it is not unnecessary).
If you can, use different values for the examples.
For things that will not score a mark or are generally useless, for example, "we will cover" or a fun fact, change the wording. This is for AS Level, do not include information about topics that are ONLY A-Level Content (if it says it is)
Link the 'sections' of your answer to the following spec-points (by title):
e.g. "**Topic** (Spec Points: a.b.c. Whatever)
3.1.1.9 Exception handling
Content
Additional information
Be familiar with the concept of exception handling.
Know how to use exception handling in a programming language with which students are familiar.

3.1.1.13 Local variables in subroutines
Content
Additional information
Know that subroutines may declare their own variables, called local variables, and that local variables:
exist only while the subroutine is executing
are accessible only within the subroutine.
Be able to use local variables and explain why it is good practice to do so.

3.1.1.14 Global variables in a programming language
Content
Additional information
Be familiar with and be able to use:
addition
subtraction
multiplication
real/float division
integer division, including remainders
exponentiation
rounding
truncation.

3.1.1.12 Returning a value/values from a subroutine
Content
Additional information
Be able to use subroutines that return values to the calling routine.

3.1.1.11 Parameters of subroutines
Content
Additional information
Be able to describe the use of parameters to pass data within programs.
Be able to use subroutines with interfaces.

3.1.1.10 Subroutines (procedures/functions)
Content
Additional information
Be familiar with subroutines and their uses.
Know that a subroutine is a named ‘out of line’ block of code that may be executed (called) by simply writing its name in a program statement.
Be able to explain the advantages of using subroutines in programs.


You MUST make sure they are ALL met. Everything it says on there you should meet.
SOMETIMES the specification does not always mention everything. If you encounter something from the body of text that is not necessarily mentioned on the specification point, still try to include it but condense it. Do not make the notes unecessary or useless.

I already provided the available exam questions you MAY choose to add on to the notes, with 'des' explaining what it's about, and 'fil' meaning the Question ID.
The content, too. Delivered in the form 'fil', JSON
Ignore exam questions that contain 'Skeleton Program'. Do not only put like 2 exam questions, try to put more!
For the exam questions, in the original text, there is a label named 'Tasks'. Those (usually) six questions are NOT the exa questions. The exam questions are the ones that were given in JSON form to you, do NOT do the 'Tasks'. Do the exam questions that contain HTML in JSON!

In the markscheme, a ';' typically means that a mark was gained.
When mentioning exam questions, you *must* answer them, according to the markscheme, scoring full marks. No 'do it yourself'.

Include ALL definitions (KEYWORDS) from the original text I sent in your notes. When I mean all, I mean ALL.

If necessary for scoring marks, try to embed the exam-questions into your notes, sometimes without even referencing the fact that it is an exam question. For example, if an exam question is a definition or benefits, use the answer in your notes.
Remember. DO NOT ADD USELESS STUFF. Your task is to create the MOST EFFICIENT (SHORTEST [for an explanation] BUT STILL SCORES ALL MARKS) possible notes resource, which will score all marks easily, so its wording has to be mostly like that of the exam questions. By any means, if necessary, please include examples and exam questions! At the end you can have a 'try these exam questions' thing.
At the end of your answer, you will give a 'breakdown'/'summary' of each thing you covered which will tell the most concise FULLY MARK-SCORING explanation possible.

In summary, your answer must:

* Be efficient, useful
* For topics in an exam that may require some form of mathematical working, always show an example of a question.
* Be clear – provide clear, step-by-step examples/instructions when needed.
* Follow the entire specification and everything it says.
* Link your section to a spec point. E.g. **Topic** (Spec Points: a.b.c Whatever)
* Score ALL marks.
* Include ALL exam questions S at the end (except ones that contain 'Skeleton Program'), with the same wording as the original ones in the JSONs sent to you – and INCLUDE THE QUESTION CONTENT, AND THE ANSWERS/MARK SCHEME. Only the ones that I provided to you, include Question IDs.
* Remove redundant, unnecessary and useless information that would not be brought up in an exam answer.
* Be helpful to the reader
* Provide the full notes, covering ALL spec-points (and showing the spec-points covered in each section).
* Include ALL definitions (KEYWORDS, usually represented explicitly and specifically in the original text as Keyword: Definition), do not change the wording (unless that definition is an exam question). MAKE ALL THE DEFINITIONS FULL (yet consice, as they can sometimes even be 2 marks). Incorporate the definitons into the notes.
* Include a seperate section named 'Definitions' that covers the keywords and their simplest definition that scores all marks. These are (usually) found in the original text.
* Include a summary at the end (after definitions) that goes through everything you need to score all marks.

At the end of the formatted text, after everything is done, fill out the JSON:
Remove the type clarification.
{
"chapter": (int),
"page": (int),
"chapter_name": (str),
"topics": (list)
}

User: And these are the available exam questions, with 'des' explaining what it's about, and 'fil' meaning the Question ID.
{'S1$.1.i': [{'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '3$', 'index4': 'S1$.1.a | S1$.1.i | S1$.1.j | S1$.1.l', 'index5': '|1$|', 'index6': 'Q23S1B06', 'qid': 'Q23S1B06', 'des': 'Data type; Boolean; integer; subroutine; return value; character; exception handling; error handling', 'index7': '', 'marks': '4 marks', 'time': '5', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q23S1B06', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2023_AS_SectionB_resources.html', 'flag1': 0}, {'index1': '|D.A$|D.C$|H.B$|K$|', 'index2': '|2$|', 'index3': '1$', 'index4': 'S1$.1.a | S1$.1.b | S1$.1.d | S1$.1.i | S3$.1.d | S4$.1.a', 'index5': '|1$|', 'index6': 'Q23S1C13', 'qid': 'Q23S1C13', 'des': 'Validation; range check; type check', 'index7': '', 'marks': '6 marks', 'time': '8', 'ttext': 'Programming concepts | Practical programming | Testing | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q23S1C13', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2023_AS_SectionC_resources.html', 'flag1': 0}, {'index1': '|D.A$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.i', 'index5': '|', 'index6': 'Q22S1B10p1', 'qid': 'Q22S1B10p1', 'des': 'Explain what exception handling is used for', 'index7': '', 'marks': '2 marks', 'time': '3', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'Q22S1B10P1', 'year': 2023, 'res': '', 'flag1': None}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.i', 'index5': '|19$|', 'index6': 'Q22S1B10p2', 'qid': 'Q22S1B10p2', 'des': 'State identifier of subroutine that performs exception handling and give exception example', 'index7': '', 'marks': '2 marks', 'time': '3', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q22S1B10P2', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2022_AS_SectionB_resources.html', 'flag1': None}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.i | S2$.1.c', 'index5': '|12$|', 'index6': 'Q20S1B07', 'qid': 'Q20S1B07', 'des': 'Describe two possible file errors that could cause exception in Skeleton Program', 'index7': '', 'marks': '2 marks', 'time': '2', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q20S1B07', 'year': 2020, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Section_B_Summer2020.html', 'flag1': None}, {'index1': '|D.A$|D.C$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.i', 'index5': '|2$|', 'index6': 'QS19S1B06', 'qid': 'QS19S1B06', 'des': 'Exception handling', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts | Practical programming | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS19S1B06', 'year': 2019, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2019.html', 'flag1': 1}], 'S1$.1.m': [{'index1': '|D.A$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.m | S1$.1.n', 'index5': '|', 'index6': 'Q23S1A03', 'qid': 'Q23S1A03', 'des': 'Local variable; global variable', 'index7': '', 'marks': '2 marks', 'time': '3', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'Q23S1A03', 'year': 2023, 'res': '', 'flag1': 0}, {'index1': '|D.A$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.m | S1$.1.n', 'index5': '|', 'index6': 'QS19S1A01', 'qid': 'QS19S1A01', 'des': 'Compare global and local variables; scope', 'index7': '', 'marks': '3 marks', 'time': '4', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'QS19S1A01', 'year': 2019, 'res': '', 'flag1': 1}, {'index1': '|D.A$|D.C$|K$|', 'index2': '|1$|', 'index3': '2$', 'index4': 'S1$.1.m', 'index5': '|16$|', 'index6': 'QS18S1B06', 'qid': 'QS18S1B06', 'des': 'Local variables; global variables', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts | Practical programming | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS18S1B06', 'year': 2018, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2018.html', 'flag1': 1}], 'S1$.1.n': [], 'S1$.1.l': [{'index1': '|D.A$|D.C$|K$|', 'index2': '|1$|', 'index3': '2$', 'index4': 'S1$.1.a | S1$.1.b | S1$.1.f | S1$.1.l', 'index5': '|16$|', 'index6': 'QS18S1B04', 'qid': 'QS18S1B04', 'des': 'Variable type; subroutine return value', 'index7': '', 'marks': '2 marks', 'time': '2', 'ttext': 'Programming concepts | Practical programming | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS18S1B04', 'year': 2018, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2018.html', 'flag1': 1}, {'index1': '|D.D$|', 'index2': '|3$|', 'index3': '3$', 'index4': 'S1$.1.b | S1$.1.l | S2$.1.b | S4$.1.b | S4$.1.c | L1$.1.b | L1$.1.l | L2$.1.b | L2$.1.d | L4$.1.b | L4$.1.c', 'index5': '|', 'index6': 'QS03406', 'qid': 'QS03406', 'des': 'Heads/ tails of lists; speed of access', 'index7': '', 'marks': '5 marks', 'time': '8', 'ttext': 'Data structures', 'fld': 'AA_COM', 'fil': 'QS03406', 'year': 2003, 'res': '', 'flag1': 0}], 'S1$.1.k': [{'index1': '|D.A$|D.C$|D.D$|H.B$|K$|', 'index2': '|2$|', 'index3': '1$', 'index4': 'S1$.1.b | S1$.1.k | S1$.1.l | S2$.1.b | S3$.1.d | S4$.1.a', 'index5': '|1$|', 'index6': 'Q23S1C12', 'qid': 'Q23S1C12', 'des': 'Accumulator; parameter; subroutine', 'index7': '', 'marks': '5 marks', 'time': '7', 'ttext': 'Programming concepts | Practical programming | Data structures | Testing | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q23S1C12', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2023_AS_SectionC_resources.html', 'flag1': 0}, {'index1': '|D.A$|D.C$|D.D$|H.B$|K$|', 'index2': '|2$|', 'index3': '1$', 'index4': 'S1$.1.a | S1$.1.b | S1$.1.c | S1$.1.d | S1$.1.e | S1$.1.k | S2$.1.b | S3$.1.d | S4$.1.a', 'index5': '|1$|', 'index6': 'Q23S1C14', 'qid': 'Q23S1C14', 'des': 'Modify code for ExecuteJSR; return address; parameter; subroutine; array', 'index7': '', 'marks': '5 marks', 'time': '7', 'ttext': 'Programming concepts | Practical programming | Data structures | Testing | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q23S1C14', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2023_AS_SectionC_resources.html', 'flag1': 0}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '3$', 'index4': 'S1$.1.g | S1$.1.k | S2$.1.c', 'index5': '|12$|', 'index6': 'Q20S1B09', 'qid': 'Q20S1B09', 'des': 'State purpose of a parameter and describe how data processed in Skeleton Program', 'index7': '', 'marks': '4 marks', 'time': '5', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q20S1B09', 'year': 2020, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Section_B_Summer2020.html', 'flag1': None}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '3$', 'index4': 'S1$.1.k | S2$.1.b | S2$.1.c', 'index5': '|12$|', 'index6': 'Q20S1B11', 'qid': 'Q20S1B11', 'des': 'Explain the effect of modifying a file when loading it into the Skeleton Program', 'index7': '', 'marks': '6 marks', 'time': '7', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q20S1B11', 'year': 2020, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Section_B_Summer2020.html', 'flag1': None}, {'index1': '|D.A$|D.C$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.k', 'index5': '|2$|', 'index6': 'QS19S1B07', 'qid': 'QS19S1B07', 'des': 'Parameters of a subroutine', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts | Practical programming | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS19S1B07', 'year': 2019, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2019.html', 'flag1': 1}, {'index1': '|D.A$|D.B$|D.C$|H.A$|K$|', 'index2': '|2$|', 'index3': '1$', 'index4': 'S1$.1.k | S1$.1.l | S1$.1.n | S1$.2.a', 'index5': '|20$|', 'index6': 'QS17S1B06', 'qid': 'QS17S1B06', 'des': 'Hierarchy chart; structure chart; subroutine interface', 'index7': '', 'marks': '5 marks', 'time': '4', 'ttext': 'Programming concepts | Algorithms | Practical programming | Stages in life cycle | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS17S1B06', 'year': 2017, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2017.html', 'flag1': 1}, {'index1': '|D.A$|', 'index2': '|1$|', 'index3': '3$', 'index4': 'S1$.1.k | S1$.1.n | L1$.1.k | L1$.1.n', 'index5': '|', 'index6': 'QS00N103', 'qid': 'QS00N103', 'des': 'Parameters/global variables', 'index7': '', 'marks': '3 marks', 'time': '5', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'QS00N103', 'year': 0, 'res': '', 'flag1': 0}], 'S1$.1.j': [{'index1': '|D.A$|D.B$|D.D$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1 | S1$.1.b | S1$.1.c | S1$.1.j | S1$.1.l | S2$.1.b | S4$.1.b', 'index5': '|', 'index6': 'Q22S1A01', 'qid': 'Q22S1A01', 'des': 'Complete trace table for algorithm that uses data in a list and DIV; list; array', 'index7': '', 'marks': '5 marks', 'time': '7', 'ttext': 'Programming concepts | Algorithms | Data structures', 'fld': 'AA_COM', 'fil': 'Q22S1A01', 'year': 2023, 'res': '', 'flag1': None}, {'index1': '|D.A$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.j', 'index5': '|', 'index6': 'Q22S1B11p1', 'qid': 'Q22S1B11p1', 'des': 'What is a subroutine?; function; procedure', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'Q22S1B11P1', 'year': 2023, 'res': '', 'flag1': None}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.j', 'index5': '|19$|', 'index6': 'Q22S1B11p2', 'qid': 'Q22S1B11p2', 'des': 'Give an example of re-use of a subroutine in the skeleton program; function; procedure', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q22S1B11P2', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2022_AS_SectionB_resources.html', 'flag1': None}, {'index1': '|D.A$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.j', 'index5': '|', 'index6': 'Q22S1B11p3', 'qid': 'Q22S1B11p3', 'des': 'Describe advantage of re-using subroutines; function; procedure', 'index7': '', 'marks': '1 marks', 'time': '1', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'Q22S1B11P3', 'year': 2023, 'res': '', 'flag1': None}, {'index1': '|D.A$|K$|', 'index2': '|2$|', 'index3': '3$', 'index4': 'S1$.1 | S1$.1.a | S1$.1.b | S1$.1.j | S1$.1.l', 'index5': '|12$|', 'index6': 'Q20S1B04', 'qid': 'Q20S1B04', 'des': 'State identifiers of variables and subroutines in the Skeleton Program; Boolean; string', 'index7': '', 'marks': '3 marks', 'time': '4', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q20S1B04', 'year': 2020, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Section_B_Summer2020.html', 'flag1': None}, {'index1': '|D.A$|D.C$|K$|', 'index2': '|2$|', 'index3': '2$', 'index4': 'S1$.1.a | S1$.1.b | S1$.1.f | S1$.1.j | S1$.1.l', 'index5': '|2$|', 'index6': 'QS19S1B04', 'qid': 'QS19S1B04', 'des': 'Boolean variables and subroutines', 'index7': '', 'marks': '2 marks', 'time': '2', 'ttext': 'Programming concepts | Practical programming | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS19S1B04', 'year': 2019, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2019.html', 'flag1': 1}, {'index1': '|D.A$|D.C$|D.D$|K$|', 'index2': '|2$|', 'index3': '1$', 'index4': 'S1$.1.a | S1$.1.b | S1$.1.j | S1$.1.l | S1$.1.m | S2$.1.b', 'index5': '|20$|', 'index6': 'QS17S1B04', 'qid': 'QS17S1B04', 'des': 'Identifier; name', 'index7': '', 'marks': '4 marks', 'time': '3', 'ttext': 'Programming concepts | Practical programming | Data structures | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS17S1B04', 'year': 2017, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2017.html', 'flag1': 1}, {'index1': '|D.A$|D.D$|', 'index2': '|1$|', 'index3': '3$', 'index4': 'S1$.1.b | S1$.1.j | S1$.1.k | S1$.1.l | S1$.2 | L1$.1.b | L1$.1.j | L1$.1.k | L1$.1.l | L1$.2.b', 'index5': '|', 'index6': 'QS07102', 'qid': 'QS07102', 'des': 'Structured programming; ', 'index7': '', 'marks': '6 marks', 'time': '8', 'ttext': 'Programming concepts | Data structures', 'fld': 'AA_COM', 'fil': 'QS07102', 'year': 2007, 'res': '', 'flag1': 0}, {'index1': '|D.A$|', 'index2': '|1$|', 'index3': '3$', 'index4': 'S1$.1.f | S1$.1.j | S1$.1.n | L1$.1.f | L1$.1.j | L1$.1.n', 'index5': '|', 'index6': 'QS0516B', 'qid': 'QS0516B', 'des': 'Variables; self-contained functions', 'index7': '', 'marks': '2 marks', 'time': '3', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'QS0516B', 'year': 2005, 'res': '', 'flag1': 0}, {'index1': '|D.A$|', 'index2': '|1$|', 'index3': '3$', 'index4': 'S1$.1.b | S1$.1.j | S1$.1.k | L1$.1.b | L1$.1.j | L1$.1.k', 'index5': '|', 'index6': 'QS02106', 'qid': 'QS02106', 'des': 'Reasons for procedures; parameters', 'index7': '', 'marks': '3 marks', 'time': '5', 'ttext': 'Programming concepts', 'fld': 'AA_COM', 'fil': 'QS02106', 'year': 2002, 'res': '', 'flag1': 0}]}

User: These are the content of said exam questions, these are the ONLY exam questions, you will use these later, delivered in form 'fil', JSON: {'Q23S1B06': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the identifier for:</p>\r\n<p class="indent1">(a)&emsp;&nbsp;a variable that is used to store a Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;a user-defined subroutine that returns only <b>one</b> value that is <b>an integer</b>.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&emsp;&nbsp;a user-defined subroutine that returns only <b>one</b> value that is <b>a single character</b>.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(d)&emsp;&nbsp;a user-defined subroutine that contains exception handling.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 4 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new indentright"><span class="comp-top">FileExists / Finished;</span></p>\r\n<p class="indent2new indentright"><b>A.</b> <span class="comp">OpCodeExists, Found</span> (Pascal only)</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new indentright"><span class="comp">ConvertToDecimal;</span></p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(c)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new indentright"><span class="comp-top">GetMenuOption;</span></p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(d)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new indentright"><span class="comp-top">LoadFile / PassTwo;</span></p>\r\n<p class="indent2new indentright"><b>A.</b> <span class="comp">Readline</span> (Java only)</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[4]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">For each of the four question parts, most students gained the mark. Here, students were required to identify a variable and three subroutines. The most common way in which marks could not be awarded was by the inclusion of additional code, such as parentheses alongside subroutine identifiers.</p></h5>', 'notes': '', 'resources': ''}, 'Q23S1C13': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question adds validation to the <b>Skeleton Program</b>. The subroutine <span class="comp">EditSourceCode</span> asks the user to enter a line number. The line number must be an integer and the number of an existing line in the file containing the program.</p>\r\n<p class="indent1new">For example, the last line (line 11) of <span class="comp">prog2.txt</span> is:</p>\r\n<p class="indent2new m-t-0"><span class="comp">FINAL:&emsp;&emsp;&emsp;&emsp;0</span></p>\r\n<p class="indent1new">Therefore, a valid line number for <span class="comp">prog2.txt</span> would be an integer between 1 and 11 inclusive.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>What you need to do:</b></p>\r\n<p class="indent1new"><b>Task 1</b></p>\r\n<p class="indent1new m-t-0">Amend the subroutine <span class="comp">EditSourceCode</span> to check that the line number entered by the user is a valid existing line number. If an invalid value is entered the subroutine should output an appropriate error message. The program must not continue until a valid line number has been entered.</p>\r\n<p class="indent1new"><b>Task 2</b></p>\r\n<p class="indent1new m-t-0">Test that the changes you have made work by conducting the following test:</p>\r\n<p class="indent1">&#8226;&emsp;&emsp;&nbsp;run your amended <b>Skeleton Program</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">L</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;load <b>prog2</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">E</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">Q</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">22</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">0</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">2</span></p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>Evidence that you need to provide</b></p>\r\n<p class="indent1">(a)&emsp;&nbsp;Your PROGRAM SOURCE CODE for the entire subroutine <span class="comp">EditSourceCode</span>.</p>\r\n<p class="mark">(5)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;SCREEN CAPTURE(S) showing the requested test described in <b>Task 2</b>.</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 6 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>5 marks for AO3 (programming)</b></p>\r\n<p class="indent2new indentright"><b>Mark as follows:</b></p>\r\n<p class="indent2 indentright">1)&emsp;&ensp;&nbsp;Check for non-integer input;</p>\r\n<p class="indent2 indentright m-t-0">2)&emsp;&ensp;&nbsp;Check within valid lower boundary;</p>\r\n<p class="indent2 indentright m-t-0">3)&emsp;&ensp;&nbsp;Check within valid upper boundary;</p>\r\n<p class="indent2 indentright m-t-0">4)&emsp;&ensp;&nbsp;At least 2 correct checks will be repeated until valid data is input at which point the loop exits;</p>\r\n<p class="indent2 indentright m-t-0">5)&emsp;&ensp;&nbsp;Output suitable error message(s) under appropriate circumstances based upon at least 2 correct checks; <b>R.</b> if message is displayed when it should not be</p>\r\n<p class="indent2new indentright"><b>Max 4</b> if any errors</p>\r\n<p class="levelms">5</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO3 (evaluate)</b></p>\r\n<p class="indent2new indentright"><b>&#42;&#42;&#42;&#42; SCREEN CAPTURE &#42;&#42;&#42;&#42;</b></p>\r\n<p class="indent2new indentright">Must match code from <b>(a)</b>, including prompts on screen capture matching those in code.</p>\r\n<p class="indent2new indentright m-t-0">Code for <b>(a)</b> must be sensible.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new indentright">Screen capture showing:</p>\r\n<p class="indent2new indentright comp-top">Enter your choice: E</p>\r\n<p class="indent2new indentright comp">Enter line number of code to edit: Q</p>\r\n<p class="indent2new indentright comp">Not a valid number</p>\r\n<p class="indent2new indentright comp">Enter line number of code to edit: 22</p>\r\n<p class="indent2new indentright comp">Not a valid line number</p>\r\n<p class="indent2new indentright comp">Enter line number of code to edit: 0</p>\r\n<p class="indent2new indentright comp">Not a valid line number</p>\r\n<p class="indent2new indentright comp">Enter line number of code to edit: 2</p>\r\n<p class="indent3new indentright comp">&nbsp;&nbsp;&nbsp;&nbsp;SUB NUM1</p>\r\n<p class="indent2new indentright comp">E - Edit this line</p>\r\n<p class="indent2new indentright comp">C - Cancel edit</p>\r\n<p class="indent2new indentright comp">Enter your choice:</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>VB.Net</b></p>\r\n<p class="indent2new comp-top">Sub EditSourceCode(ByRef SourceCode() As String)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim Choice As String = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim LineNumber As Integer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Do</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&quot;Enter line number of code to edit: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>Dim Temp As String = Console.ReadLine</b>&nbsp;&nbsp;\' <b>MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>If Not Integer.TryParse(Temp, LineNumber) Then</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>LineNumber = -1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Console.WriteLine(&quot;Not a valid number&quot;)</b>&nbsp;&nbsp;\' <b>MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>End If</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Loop Until LineNumber &gt; 0 And LineNumber &lt;= Convert.ToInt32(SourceCode(0))</b>&nbsp;&nbsp;\' <b>MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp-top">&nbsp;&nbsp;Console.WriteLine(SourceCode(LineNumber))</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;While Choice &lt;&gt; &quot;C&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;While Choice &lt;&gt; &quot;E&quot; And Choice &lt;&gt; &quot;C&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;E - Edit this line&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;C - Cancel edit&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&quot;Enter your choice: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choice = Console.ReadLine()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;End While</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;If Choice = &quot;E&quot; Then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&quot;Enter the new line: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceCode(LineNumber) = Console.ReadLine()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;End If</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;End While</p>\r\n<p class="indent2new comp">End Sub</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 3</b></p>\r\n<p class="indent2new comp-top">def EditSourceCode(SourceCode):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>LineNumber = 0</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>NumberOfLines = int(SourceCode[0])</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while LineNumber not in range(1, NumberOfLines + 1):</b>&nbsp;&nbsp;<b># MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>try:</b>&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LineNumber = int(input(&quot;Enter line number of code to edit: &quot;))</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>if LineNumber not in range(1, NumberOfLines + 1):</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print(&quot;Not a valid line number&quot;)</b>&nbsp;&nbsp;<b># MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>except:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print(&quot;Not a valid number&quot;)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print(SourceCode[LineNumber])</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while Choice != &quot;E&quot; and Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;E - Edit this line&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;C - Cancel edit&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choice = input(&quot;Enter your choice: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Choice == &quot;E&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceCode[LineNumber] = input(&quot;Enter the new line:&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return SourceCode</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">def EditSourceCode(SourceCode):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>LineNumberStr =</b> input(&quot;Enter line number of code to edit: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Valid = False</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while not Valid:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>if LineNumberStr.isdigit() and int(LineNumberStr) &gt; 0 and int(LineNumberStr) &lt;= int(SourceCode[0]):</b>&nbsp;&nbsp;<b># MP1, MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Valid = True</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>LineNumber = int(LineNumberStr)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>else:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print(&quot;Not a valid line number&quot;)</b>&nbsp;&nbsp;<b># MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>LineNumberStr =</b> input(&quot;Enter line number of code to edit: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print(SourceCode [LineNumber])</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while Choice != &quot;E&quot; and Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;E - Edit this line&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;C - Cancel edit&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choice = input(&quot;Enter your choice: &quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Choice == &quot;E&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceCode[LineNumber] = input(&quot;Enter the new line:&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return SourceCode</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 2</b></p>\r\n<p class="indent2new comp-top">def EditSourceCode(SourceCode):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>LineNumber = 0</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>NumberOfLines = int(SourceCode[0])</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while LineNumber not in range(1, NumberOfLines + 1):</b>&nbsp;&nbsp;<b># MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>try:</b>&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LineNumber = int(raw_input(&quot;Enter line number of code to edit: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;))</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>if LineNumber not in range(1, NumberOfLines + 1):</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print &quot;Not a valid line number&quot;</b>&nbsp;&nbsp;<b># MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>except:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print &quot;Not a valid number&quot;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print SourceCode[LineNumber]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while Choice != &quot;E&quot; and Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;E - Edit this line&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;C - Cancel edit&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choice = raw_input(&quot;Enter your choice: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Choice == &quot;E&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceCode[LineNumber] = raw_input(&quot;Enter the new line: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return SourceCode</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">def EditSourceCode(SourceCode):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;LineNumberStr = raw_input(&quot;Enter line number of code to edit: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Valid = False</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while not Valid:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>if LineNumberStr.isdigit() and int(LineNumberStr) &gt; 0 and int(LineNumberStr) &lt;= int(SourceCode[0]):</b>&nbsp;&nbsp;<b># MP1, MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Valid = True</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>LineNumber = int(LineNumberStr)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>else:</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>print &quot;Not a valid line number&quot;</b>&nbsp;&nbsp;<b># MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>LineNumberStr = raw_input(&quot;Enter line number of code to edit: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print SourceCode [LineNumber]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice = EMPTY_STRING</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while Choice != &quot;E&quot; and Choice != &quot;C&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;E - Edit this line&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;C - Cancel edit&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choice = raw_input(&quot;Enter your choice: &quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Choice == &quot;E&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceCode[LineNumber] = raw_input(&quot;Enter the new line:&quot;) .replace(&quot;\\r&quot;, &quot;&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return SourceCode</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Pascal</b></p>\r\n<p class="indent2new comp-top">procedure EditSourceCode(var SourceCode: TSourceCode);</p>\r\n<p class="indent2new comp">var</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;LineNumber, <b>NumberOfLines</b>: integer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice: string;</p>\r\n<p class="indent2new comp">begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>LineNumber := 0;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>NumberOfLines := StrToInt(SourceCode[0]);</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while (LineNumber &lt; 1) or (LineNumber &gt;= NumberOfLines) do</b>&nbsp;&nbsp;<b>// MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>begin</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>try</b>&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>write(\'Enter line number of code to edit: \');</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>readln(LineNumber);</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>if (LineNumber &lt; 1) or (LineNumber &gt;= NumberOfLines)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>then</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>writeln(\'Not a valid line number\');</b>&nbsp;&nbsp;<b>// MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>except</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>writeln(\'Not a valid number\');</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>end;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>end;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;writeln(SourceCode[LineNumber]);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Choice := EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while Choice &lt;&gt; \'C\' do</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Choice := EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (Choice &lt;&gt; \'E\') and (Choice &lt;&gt; \'C\') do</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln(\'E - Edit this line\');</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln(\'C - Cancel edit\');</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write(\'Enter your choice: \');</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readln(Choice);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Choice = \'E\'</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln(\'Enter the new line:\');</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readln(SourceCode[LineNumber]);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(SourceCode);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">end;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>C#</b></p>\r\n<p class="indent2new comp-top">private static void EditSourceCode(string[] sourceCode)</p>\r\n<p class="indent2new comp">{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int lineNumber = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>int numberOfLines = Convert.ToInt32(sourceCode[0]);</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>while (lineNumber &lt; 1 || lineNumber &gt;= numberOfLines)</b> <b>// MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>Try</b> <b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&quot;Enter line number of code to edit: &quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineNumber = Convert.ToInt32(Console.ReadLine());</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>if (lineNumber &lt; 1 || lineNumber &gt;= numberOfLines)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Console.WriteLine(&quot;Not a valid line number&quot;);</b> <b>// MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>catch (Exception)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Console.WriteLine(&quot;Not a valid number&quot;);</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Console.WriteLine(sourceCode[lineNumber]);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;string choice = EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while (choice != &quot;C&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;choice = EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (choice != &quot;E&quot; &amp;&amp; choice != &quot;C&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;E - Edit this line&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;C - Cancel edit&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&quot;Enter your choice: &quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;choice = Console.ReadLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if (choice == &quot;E&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;Enter the new line:&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceCode[lineNumber] = Console.ReadLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplaySourceCode(sourceCode);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">}</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Java</b></p>\r\n<p class="indent2new comp-top">void editSourceCode(String[] sourceCode) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>int lineNumber;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>do {</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.print(&quot;Enter line number of code to edit: &quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>try {</b>&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>lineNumber = Integer.parseInt(Console.readLine());</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>} catch (Exception e) {</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>lineNumber = 0;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>if (lineNumber &lt; 1 || lineNumber &gt; sourceCode.length + 1)</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Console.println(&quot;Invalid line number please try again.&quot;);</b>&nbsp;&nbsp;<b>// MP5</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>} while (lineNumber &lt; 1 || lineNumber &gt; sourceCode.length + 1);</b>&nbsp;&nbsp;<b>// MP2, MP3, MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Console.println(sourceCode[lineNumber]);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;String choice = EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while (!choice.equals(&quot;C&quot;)) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;choice = EMPTY_STRING;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (!choice.equals(&quot;E&quot;) &amp;&amp; !choice.equals(&quot;C&quot;)) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.println(&quot;E - Edit this line&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.println(&quot;C - Cancel edit&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.print(&quot;Enter your choice: &quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;choice = Console.readLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if (choice.equals(&quot;E&quot;)) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.print(&quot;Enter the new line: &quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sourceCode[lineNumber] = Console.readLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displaySourceCode(sourceCode);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">}</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[6]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question required addition of validation code; the requirement was that any specified line number should exist within the assembly program. Although the lower bound was generally correct, since it would always be 1, the upper bound was commonly hard-coded rather than determined using a variable. Since the length of the assembly program could vary, hard-coding was not enough for the mark.</p>\r\n<p class="indent1new">Approximately half of the students secured either full marks or four out of five for part (a), although very few students were awarded two or three marks. That indicates that this question marks the beginning of the stage in which individual programming marks were cherry-picked due to constraints of time or understanding.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1B10P1': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Explain what exception handling is used for.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>2 marks for AO1 (understand)</b></p>\r\n<p class="indent1new indentright">To stop a program from crashing;</p>\r\n<p class="indent1new indentright m-t-0">To deal with (an anticipated) <u>run-time</u> error&emsp;<b>A.</b> clear description of an example of a run-time error;</p>\r\n<p class="indent1new indentright m-t-0">To avoid structure of code becoming too complex as a result of trying to check for potential errors before they might occur;</p>\r\n<p class="indent1new indentright"><b>Max 2</b></p>\r\n<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Most students secured the first mark of this question by identifying that an exception stops a program from crashing. Many fewer students recognised that exception handling is relevant to run time errors. &#x0027;Errors&#x0027;, in isolation, did not demonstrate a sufficient level of understanding.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1B10P2': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the identifier of a subroutine in the <b>Skeleton Program</b> that performs exception handling <b>and</b> give an example of a circumstance that might cause an exception within that subroutine.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>2 marks for AO2 (analyse)</b> <b> <BR></b><b>1 mark for identifier and 1 mark for exception</b></p>\r\n<p class="indent1new indentright"><span class="comp">LoadPuzzleFile</span> &#x2013; file does not exist // index error if more lines in file than <span class="comp">Puzzle</span> can accommodate;</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">LoadSolution</span> &#x2013; file does not exist // not enough lines in file;</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">TransferPuzzleIntoGrid</span> &#x2013; input conversion error // index error if string length &lt; 3;</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">LoadPartSolvedPuzzle</span> &#x2013; file does not exist // index error if more lines in file than</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">Answer</span> can accommodate;</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">SolvePuzzle</span> &#x2013; row/column/1<sup class="xsmall">st</sup> character/2<sup class="xsmall">nd</sup> character entered not a digit/number/integer // input conversion error;</p>\r\n<p class="indent1new indentright"><b>A.</b> <span class="comp">KeepPuzzle</span> &#x2013; file does not exist (Java only)</p>\r\n<p class="indent1new indentright m-t-0"><b>A.</b> <span class="comp-top">readLine</span> &#x2013; end of file (Java only)</p>\r\n<p class="indent1new indentright"><b>A.</b> other exceptions that could occur</p>\r\n<p class="indent1new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent1new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent1new indentright m-t-0"><b>I.</b> case and spacing</p>\r\n<p class="indent1new indentright"><b>Max 2</b></p>\r\n<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The majority of students were able to identify a subroutine that performed exception handling, as required by this question. Of those who correctly identified the subroutine, most were able to identify a relevant circumstance that might cause an exception.</p>\r\n<p class="indent1new">The most common reason for dropping a mark on this question was to give more than just the subroutine&#x0027;s name. For example, <span class="comp">LoadPuzzleFile</span> was creditworthy, whereas <span class="comp">def LoadPuzzleFile</span> or <span class="comp">LoadPuzzleFile(PuzzleName, Puzzle)</span> was not.</p></h5>', 'notes': '', 'resources': ''}, 'Q20S1B07': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question refers to the subroutine <span class="comp">LoadGreyScaleImage</span></p>\r\n<p class="indent1new">Describe <b>two</b> possible errors that could cause an exception in this subroutine.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>All marks for AO2 (analyse)</b> </p>\r\n<p class="indent1new indentright"><span class="comp">NextPixel</span> is not (a string that can be converted to) an integer;</p>\r\n<p class="indent1new indentright m-t-0">File no longer available; <b>R.</b> file could not be opened as already open</p>\r\n<p class="indent1new indentright m-t-0">Pixel data stored in wrong format, <b>R.</b> file does not have .txt extension;</p>\r\n<p class="indent1new indentright m-t-0">Not enough lines in the file <b>N.E.</b> Empty file<b>;</b> </p>\r\n<p class="indent1new indentright m-t-0">Not enough characters in a line;</p>\r\n<p class="indent1new indentright m-t-0"><b>A.</b> Not enough data in file for given size of image; if neither of the 2 points above have been given</p>\r\n<p class="indent1new indentright m-t-0"><u>Header</u> height larger than <span class="comp">MAX_HEIGHT</span>, <b>A.</b> larger than 100;</p>\r\n<p class="indent1new indentright m-t-0"><u>Header</u> width larger than <span class="comp">MAX_WIDTH</span>, <b>A.</b> larger than 100;</p>\r\n<p class="indent1new indentright"><b>Max 2</b></p>\r\n<p class="mark">[2]</p></h5>', 'examinerreport': '', 'notes': '', 'resources': ''}, 'QS19S1B06': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">What is the specific purpose of the exception handling construct in the subroutine <span class="comp">SetUpBoard</b>?</span></p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent1new">catch any <u>file</u> errors // stop program crashing if <u>file doesn’t exist</u>;</p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Many students’ answers were very vague as to the reasons for using exception handling in the subroutine <span class="comp">SetUpBoard</span>. Answers that were given credit included stating that this would avoid a program crash in case of file errors.</p></h5>', 'notes': '', 'resources': ''}, 'Q23S1A03': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Describe <b>one</b> difference between a global variable and a local variable.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>2 marks for AO1 (knowledge)</b></p>\r\n<p class="indent1new">Global variable can be used anywhere in program // global variable is declared in outmost block / outside subroutines;</p>\r\n<p class="indent1new m-t-0">Local variable can only be used in the block / subroutine in which it is declared;</p>\r\n<p class="indent1new"><i><b>Alternative answer 1:</b> </i></p>\r\n<p class="indent1new">Local variables only use memory when the program block they are in is executing; global variables use memory the entire time the program is executing;</p>\r\n<p class="indent1new"><i><b>Alternative answer 2:</b></i></p>\r\n<p class="indent1new">Local variables only exist when the program block they are in is executing; global variables exist the entire time the program is running;</p>\r\n<p class="indent1new"><b>A.</b> local variables are stored on a stack / in a stack frame; global variables are generally stored elsewhere in the memory;</p>\r\n<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question required students to describe a difference between a global and a local variable, and fewer than half of students succeeded in providing a description that secured both marks. Although there was an understanding that the scope of a local variable is more limited, this was often phrased too vaguely to be fully creditworthy.</p></h5>', 'notes': '', 'resources': ''}, 'QS19S1A01': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State <b>one</b> difference between local and global variables and give <b>two</b> reasons why it is good practice to use local variables.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 3 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>All marks for AO1 (knowledge)</b></p>\r\n<p class="indent1new">Difference:</p>\r\n<p class="indent1 indentright m-t-0">global variables accessible to all parts of the program</p>\r\n<p class="indent1 indentright m-t-0">// declared in main program block</p>\r\n<p class="indent1 indentright m-t-0">// local variables declared in subroutine</p>\r\n<p class="indent1 indentright m-t-0">// accessible only in the program block/subroutine in which it was declared;</p>\r\n<p class="indent1new">Reason:</p>\r\n<p class="indent1 indentright m-t-0">memory allocated to local variables can be reused when subroutine not in use;</p>\r\n<p class="indent1 indentright m-t-0">local variable only exists while the program block/subroutine is executing;</p>\r\n<p class="indent1 indentright m-t-0">using local variables makes subroutines self-contained;</p>\r\n<p class="indent1 indentright m-t-0"><b>A.</b> prevents accidental changes;</font></p>\r\n<p class="indent1 indentright m-t-0"><b>A.</b> easier debugging/maintenance;</font></p>\r\n<p class="indent1 indentright m-t-0"><b>Max 2</b></p>\r\n<p class="mark">[3]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Many vague answers were given for the difference between local and global variables. Regardless of how the student’s chosen programming language requires local / global variables to be declared, students need to be aware that a global variable is accessible to all parts of the program, whereas a local variable is accessible only in the program block in which it was declared. Many students’ answers were very vague as to the reasons for using local variables. Some were able to state that memory used to store local variables is released when the subroutine terminates, but very few mentioned that local variables make a subroutine self-contained and therefore it is easier to re-use such subroutines in other programs.</p></h5>', 'notes': '', 'resources': ''}, 'QS18S1B06': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Several subroutines use a variable <span class="comp">TransmissionLength</span>. It could have been declared as a global variable instead of locally in each subroutine.</p>\r\n<p class="indent1new">Why is it good practice to use local variables?</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question indentright"><b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent1 indentright indentright">1.&emsp;&ensp;&nbsp;makes a subroutine self-contained;</p>\r\n<p class="indent1 m-t-0 indentright">2.&emsp;&ensp;&nbsp;releases storage when subroutine terminates;</p>\r\n<p class="indent1 m-t-0 indentright">3.&emsp;&ensp;&nbsp;able to test / debug subroutine independently;</p>\r\n<p class="indent1 m-t-0 indentright">4.&emsp;&ensp;&nbsp;easier to re-use subroutine in another program;</p>\r\n<p class="indent1 m-t-0 indentright">5.&emsp;&ensp;&nbsp;local variable values cannot be inadvertently/accidentally altered by a subroutine call from the subroutine;</p>\r\n<p class="indent1new indentright"><b>Max 1</b></p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Many students’ answers were very vague as to the reasons for using local variables. Some were able to state that memory used to store local variables is released when the subroutine terminates, but very few mentioned that local variables make a subroutine self-contained and therefore it is easier to re-use a subroutine in another program.</p></h5>', 'notes': '', 'resources': ''}, 'QS18S1B04': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the name of an identifier for:</p>\r\n<p class="indent1">(a)&emsp;&nbsp;a variable that is used to store a Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;a user-defined subroutine that returns a single character.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona indentright">(a)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new comp-top indentright">LetterEnd // ProgramEnd ;</p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new m-t-0 indentright"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new indentright"><span class="comp-top">GetMenuOption // Decode ;</span> <b>A.</b> <span class="comp-top">GetNextSymbol</span></p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new m-t-0 indentright"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p> \r\n<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The majority of students secured both of the marks for this question. A few students copied across more than just the identifier for each part and therefore did not gain the mark as it was not clear which part of the copied code they believed the identifier to be.</p></h5>', 'notes': '', 'resources': ''}, 'QS03406': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The list <b>Days </b>contains the following representation of the days of the week.</p>  \r<p class="indent1new">[Sun, Mon, Tue, Wed, Thu, Fri, Sat]</p>  \r<p class="indent1new">The table below shows some functions which take a list as their single argument and return a result which is either an element of a list, another list, or a Boolean value.</p>  \r<p class="bottom">&nbsp;</p>  \r<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=5 style=\'margin-left:30pt;border-collapse:collapse\'>  \r\t<tr>     \r\t\t<td width=753 valign=top style=\'width:451.9pt;border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box align=left style=\'text-align:left\'><b>Head(list)</b> - returns the   element at the head of <b>list</b> (e.g. Head(Days)<span style=\'font-family:   Symbol\'>®</span> Sun) if <b>list</b> is non empty otherwise it reports an   error.</p></td>  \r\t</tr>  \r\t<tr>    \r\t\t<td width=753 valign=top style=\'width:451.9pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box align=left style=\'text-align:left\'><b>Tail(list)</b> - returns a   new list containing all but the first element of the original list (e.g.   Tail(Days) <span style=\'font-family:Symbol\'>®</span> [Mon, Tue, Wed, Thu,   Fri, Sat]) if <b>list</b> is non-empty otherwise it reports an error.</p></td>  \r\t</tr>  \r\t<tr>    \r\t\t<td width=753 valign=top style=\'width:451.9pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box align=left style=\'text-align:left\'><b>Empty(list)</b> - returns   True if <b>list</b> is the empty list or False otherwise. The empty list is   denoted by[]</p></td>  \r\t</tr> \r</table></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(a)&nbsp;&nbsp;&nbsp;&nbsp; What result is returned when the following function calls are made?</p>  \r<p class="indent2new">(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Head (Tail(Days))<span  "answer-toggle">________________________________________________</span></p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new">(ii)&nbsp;&nbsp;&nbsp;&nbsp; Tail ([(Head(Days)])<span  "answer-toggle">______________________________________________</span></p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new">(iii)&nbsp;&nbsp;&nbsp;&nbsp; Empty(Tail(Tail(Tail(Days))))<span  "answer-toggle">_______________________________________</span></p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; Explain why it is faster to access these elements if the above data is stored as a one dimensional array.</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(2)</p>  \r<p class="mark">(Total 5 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1 indentright m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; Head (Tail ( Days)) = Mon <br> <b>R </b>[Mon], MON (1)</p>  \r<p class="indent2new indentright">Tail([Head(Days)]) = [ ] (1)</p>  \r<p class="indent2new indentright">Empty(Tail(Tail(Tail(Days))))=False (1)</p>  \r<p class="levelms">3</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&nbsp;&nbsp;&nbsp;&nbsp; Elements in a list can only be <u>accessed sequentially</u>;</p>  \r<p class="indent2new indentright m-t-0">elements in an array can be accessed <u>directly;</u></p>  \r<p class="indent2new indentright m-t-0">using the subscript;</p>  \r<p class="indent2new indentright"><i>Any 2 points</i></p>\r<p class="levelms">2</p>  \r<p class="mark">[5]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Parts (a) (i) and (a) (iii) were answered correctly by most candidates as Mon and False respectively, (not [Mon]). However, in (a) (ii) [Head(Days)} is the list [Sun] and the tail of this list is the empty set [ ].&nbsp; Had these data been stored in a one dimensional array, instead of in a list, each element could have been accessed directly using the subscript, rather than having to be found through a sequential search or using the Head / Tail functions defined.</p></h5>', 'notes': '', 'resources': ''}, 'Q23S1C12': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question extends the functionality of the <b>Skeleton Program</b>.</p>\r\n<p class="indent1new">The functionality of the <span class="comp">SKP</span> opcode is to be changed so that it increments the value stored in the accumulator by 1</p>\r\n<p class="indent1new">For example, if the accumulator contained 4, then executing the instruction</p>\r\n<p class="indent2new m-t-0"><span class="comp">SKP</span></p>\r\n<p class="indent1new m-t-s">would change the value in the accumulator to 5</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>What you need to do:</b></p>\r\n<p class="indent1new"><b>Task 1</b></p>\r\n<p class="indent1new m-t-0">Amend the subroutine <span class="comp">ExecuteSKP</span> so that it adds 1 to the accumulator and then updates the status register if required. The <span class="comp">Registers</span> data structure should be passed as a parameter.</p>\r\n<p class="indent1new"><b>Task 2</b></p>\r\n<p class="indent1new m-t-0">Amend the call to <span class="comp">ExecuteSKP</span> in the <span class="comp">Execute</span> subroutine as required.</p>\r\n<p class="indent1new"><b>Task 3</b></p>\r\n<p class="indent1new m-t-0">Test that the changes you have made work by conducting the following test:</p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;run your amended <b>Skeleton Program</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">L</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;load <b>prog2</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">A</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">R</span></p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>Evidence that you need to provide</b></p>\r\n<p class="indent1">(a)&emsp;&nbsp;Your PROGRAM SOURCE CODE for the entire subroutine <span class="comp">ExecuteSKP</span> and the entire subroutine <span class="comp">Execute</span>.</p>\r\n<p class="mark">(4)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;SCREEN CAPTURE(S) showing the requested test described in <b>Task 3</b>.</p>\r\n<p class="indent2new">The SCREEN CAPTURE(S) only need to show all of Frame 0 and all of the final frame.</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 5 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>4 marks for AO3 (programming)</b></p>\r\n<p class="indent2new indentright"><b>Mark as follows:</b></p>\r\n<p class="indent2 indentright">1)&emsp;&ensp;&nbsp;Add required parameter to subroutine call in <span class="comp">Execute</span>;</p>\r\n<p class="indent2 indentright m-t-0">2)&emsp;&ensp;&nbsp;Add required parameter to <span class="comp">ExecuteSKP</span> definition;</p>\r\n<p class="indent2 indentright m-t-0">3)&emsp;&ensp;&nbsp;Add <span class="comp">1</span> to <span class="comp">Registers[ACC];</span></p>\r\n<p class="indent2 indentright m-t-0">4)&emsp;&ensp;&nbsp;Update status register (by calling <span class="comp">SetFlags</span> with correct parameters);</p>\r\n<p class="indent2new indentright"><b>Max 3</b> if any errors</p>\r\n<p class="levelms">4</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO3 (evaluate)</b></p>\r\n<p class="indent2new indentright"><b>&#42;&#42;&#42;&#42; SCREEN CAPTURE &#42;&#42;&#42;&#42;</b></p>\r\n<p class="indent2new indentright m-t-0">Must match code from <b>(a)</b>, including prompts on screen capture matching those in code.</p>\r\n<p class="indent2new indentright m-t-0">Code for <b>(a)</b> must be sensible.</p>\r\n<p class="indent2new indentright">Screen capture showing (values changing from Frame 0 to Frame 5 shown highlighted):</p>\r\n<p class="indent2new"><img src="AA_COM/M23S1C12_files_M/img01.jpg"/>&nbsp;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>VB.Net</b></p>\r\n<p class="indent2new comp-top">Sub ExecuteSKP(<b>Registers() As Integer</b>)&nbsp;&nbsp;\' MP2</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers(ACC) += 1</b>&nbsp;&nbsp;\'MP3</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>SetFlags(Registers(ACC), Registers)</b>&nbsp;&nbsp;\'MP4</p>\r\n<p class="indent2new comp">End Sub</p>\r\n<p class="indent2new comp-top">Sub Execute(ByVal SourceCode() As String, ByVal Memory() As AssemblerInstruction)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim Registers() As Integer = {0, 0, 0, 0, 0}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;SetFlags(Registers(ACC), Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers(PC) = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers(TOS) = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim FrameNumber As Integer = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim OpCode As String = Memory(Registers(PC)).OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;While OpCode &lt;&gt; &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Dim Operand As Integer = Memory(Registers(PC)).OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;* Current Instruction Register: {OpCode} {Operand}&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers(PC) += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Select Case OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;LDA&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;STA&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;LDA#&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;ADD&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;JMP&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;JSR&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJSR(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;CMP#&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;BEQ&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;SUB&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;SKP&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP(<b>Registers</b>)&nbsp;&nbsp;\'MP1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;RTN&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;End Select</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;If Registers(ERR) = 0 Then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory(Registers(PC)).OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;End If</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;End While</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Console.WriteLine(&quot;Execution terminated&quot;)</p>\r\n<p class="indent2new comp">End Sub</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 3</b></p>\r\n<p class="indent2new comp-top">def ExecuteSKP(<b>Registers</b>):&nbsp;&nbsp;<b># MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers[ACC] = Registers[ACC] + 1</b>&nbsp;&nbsp;<b># MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers = SetFlags(Registers[ACC], Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp-top">def Execute(SourceCode, Memory):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = [0, 0, 0, 0, 0]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = SetFlags(Registers[ACC], Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode != &quot;HLT&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Operand = Memory[Registers[PC]].OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;* Current Instruction Register: &quot;, OpCode, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Registers[PC] + 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if OpCode == &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory = ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory, Registers = ExecuteJSR(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP(<b>Registers</b>)&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] == 0:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;else:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print(&quot;Execution terminated&quot;)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 2</b></p>\r\n<p class="indent2new comp-top">def ExecuteSKP(<b>Registers</b>)<b>:</b>&nbsp;&nbsp;<b># MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers[ACC] = Registers[ACC] + 1</b>&nbsp;&nbsp;<b># MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers = SetFlags(Registers[ACC], Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp-top">def Execute(SourceCode, Memory):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = [0, 0, 0, 0, 0]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = SetFlags(Registers[ACC], Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode != &quot;HLT&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Operand = Memory[Registers[PC]].OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print &quot;* Current Instruction Register: &quot;, OpCode, Operand</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Registers[PC] + 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if OpCode == &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory = ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory, Registers = ExecuteJSR(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP(<b>Registers</b>)&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] == 0:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;else:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print &quot;Execution terminated&quot;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Pascal</b></p>\r\n<p class="indent2new comp-top">procedure ExecuteSKP<b>(var Registers: TRegisters);</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Registers[ACC] := Registers[ACC] + 1;</b>&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>SetFlags(Registers[ACC], Registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">end;</p>\r\n<p class="indent2new comp-top">procedure Execute(var SourceCode: TSourceCode; var Memory: TMemory);</p>\r\n<p class="indent2new comp">var</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers: TRegisters;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode: string;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Operand, FrameNumber: integer;</p>\r\n<p class="indent2new comp">begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers := TRegisters.create(0, 0, 0, 0, 0);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;SetFlags(Registers[ACC], Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] := 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] := HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber := 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode := Memory[Registers[PC]].OpCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode &lt;&gt; \'HLT\' do</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber := FrameNumber + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Operand := Memory[Registers[PC]].OperandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln(\'* Current Instruction Register: \', OpCode, \' \', Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] := Registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'LDA\' then ExecuteLDA(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'STA\' then ExecuteSTA(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'LDA#\' then ExecuteLDAimm(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'ADD\' then ExecuteADD(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'JMP\' then ExecuteJMP(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'JSR\' then ExecuteJSR(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'CMP#\' then ExecuteCMPimm( Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'BEQ\' then ExecuteBEQ(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'SUB\' then ExecuteSUB(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'SKP\' then ExecuteSKP(<b>Registers</b>);&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'RTN\' then ExecuteRTN(Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode := Memory[Registers[PC]].OpCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode := \'HLT\';</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;writeln(\'Execution terminated\');</p>\r\n<p class="indent2new comp">end;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>C#</b></p>\r\n<p class="indent2new comp-top">private static void ExecuteSKP(<b>int[] registers</b>)&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>registers[ACC] = registers[ACC] + 1;</b>&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>SetFlags(registers[ACC], registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">}</p>\r\n<p class="indent2new comp-top">private static void Execute(string[] sourceCode, AssemblerInstruction[] memory)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int[] registers = new int[] { 0, 0, 0, 0, 0 };</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int frameNumber = 0, operand = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;SetFlags(registers[ACC], registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;string opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (opCode != &quot;HLT&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frameNumber++;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand = memory[registers[PC]].operandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;* Current Instruction Register: {opCode} {operand}&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (opCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSTA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDAimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteADD(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJMP(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJSR(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteCMPimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteBEQ(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSUB(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP(<b>registers</b>); break;&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteRTN(memory, registers); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (registers[ERR] == 0)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = &quot;HLT&quot;;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;Execution terminated&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Java</b></p>\r\n<p class="indent2new comp-top">void executeSKP(<b>int[] registers</b>) {&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>registers[ACC] = registers[ACC] + 1;</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>setFlags(registers[ACC], registers);</b>&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">}</p>\r\n<p class="indent2new comp-top">void execute(String[] sourceCode, AssemblerInstruction[] memory)</p>\r\n<p class="indent2new comp-top">{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int[] registers = {0, 0, 0, 0, 0} ;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;setFlags(registers[ACC], registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;registers[PC] = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;registers[TOS] = HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int frameNumber = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;displayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;displayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;String opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while (!opCode.equals(&quot;HLT&quot;)) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;frameNumber += 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.println();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;displayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int operand = memory[registers[PC]].operandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.println(&quot;* Current instruction Register: &quot; + opCode + &quot; &quot; + operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;switch (opCode) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeLDA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSTA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeLDAimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeADD(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeJMP(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeJSR(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeCMPimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeBEQ(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSUB(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSKP(<b>registers</b>); break;&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeRTN(memory, registers); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if (registers[ERR] == 0) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;} else {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = &quot;HLT&quot;;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Console.println(&quot;Execution terminated&quot;);</p>\r\n<p class="indent2new comp">}</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[5]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question was the first that required changes to be made to the skeleton program, and answers were of a good quality, with around seventy percent of students securing either full marks or three out of four on part (a).</p>\r\n<p class="indent1new">Where a mark was dropped in an otherwise correct response, it was that awarded for updating the status register, which was missed out rather than being attempted incorrectly.</p></h5>', 'notes': '', 'resources': ''}, 'Q23S1C14': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question adds a memory address check to the <b>Skeleton Program</b>.</p>\r\n<p class="indent1new">Each time a <span class="comp">JSR</span> opcode is executed the return address is stored in memory. The memory location used for this could already contain an instruction or data.</p>\r\n<p class="indent1new">If storing a return address will overwrite an instruction or data, then an appropriate error message should be output using the <span class="comp">ReportRunTimeError</span> subroutine. The original code in the <span class="comp">ExecuteJSR</span> subroutine should only be carried out if there is no error.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>What you need to do:</b></p>\r\n<p class="indent1new"><b>Task 1</b></p>\r\n<p class="indent1new m-t-0">Amend the <span class="comp">ExecuteJSR</span> subroutine. If storing a return address would overwrite an instruction or data, the <span class="comp">ReportRunTimeError</span> subroutine should be called with an appropriate error message.</p>\r\n<p class="indent1new">One method of completing this task would require the addition of extra parameter(s) to the <span class="comp">ExecuteJSR</span> subroutine.</p>\r\n<p class="indent1new"><b>Task 2</b></p>\r\n<p class="indent1new m-t-0">If your solution requires additional parameter(s) for the <span class="comp">ExecuteJSR</span> subroutine amend the call to <span class="comp">ExecuteJSR</span> in the <span class="comp">Execute</span> subroutine.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>Task 3</b></p>\r\n<p class="indent1new m-t-0">Test that the changes you have made work by conducting the following test:</p>\r\n<p class="indent1">&#8226;&emsp;&emsp;&nbsp;run your amended <b>Skeleton Program</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">L</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;load <b>prog3</b></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">A</span></p>\r\n<p class="indent1 m-t-0">&#8226;&emsp;&emsp;&nbsp;enter <span class="comp">R</span></p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new"><b>Evidence that you need to provide</b></p>\r\n<p class="indent1">(a)&emsp;&nbsp;Your PROGRAM SOURCE CODE for the entire subroutine <span class="comp">ExecuteJSR</span> and the entire subroutine <span class="comp">Execute</span> if you have made changes in <b>Task 2</b>.</p>\r\n<p class="mark">(4)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;SCREEN CAPTURE(S) showing the requested test described in <b>Task 3</b>.</p>\r\n<p class="indent2new">The SCREEN CAPTURE(S) only need to show the final frame and the contents of the stack before execution terminates.</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 5 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>2 marks for AO3 (design) and 2 marks for AO3 (programming)</b></p>\r\n<p class="indent2new indentright"><b>Marking guidance:</b></p>\r\n<p class="indent2new indentright"><b>Evidence of AO3 design &#x2013; 2 points:</b></p>\r\n<p class="indent2new indentright">Evidence of design to look for in response:</p>\r\n<p class="indent2 indentright">1)&emsp;&ensp;&nbsp;Check in <span class="comp-top">ExecuteJSR</span> that stack does not overwrite instruction / data;</p>\r\n<p class="indent2 indentright m-t-0">2)&emsp;&ensp;&nbsp;Recognise that instructions for <span class="comp">JSR</span> should only be executed if no error;</p>\r\n<p class="indent2new indentright"><b>Note:</b> AO3 (design) points are for selecting appropriate techniques to use to solve the problem, so should be credited whether the syntax of programming language statements is correct or not and regardless of whether the solution works.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new indentright"><b>Evidence of AO3 programming &#x2013; 2 points:</b></p>\r\n<p class="indent2new indentright">Evidence of programming to look for in response:</p>\r\n<p class="indent2 indentright">3)&emsp;&ensp;&nbsp;Correct value for number of program lines passed into subroutine // check that memory location pointed to by <span class="comp-top">TOS</span> is empty;</p>\r\n<p class="indent2 indentright m-t-0">4)&emsp;&ensp;&nbsp;<span class="comp">ReportRunTimeError</span> called with suitable message in appropriate place;</p>\r\n<p class="indent2new indentright"><b>Max 3</b> if code does not function correctly</p>\r\n<p class="levelms">4</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO3 (evaluate)</b></p>\r\n<p class="indent2new indentright"><b>&#42;&#42;&#42;&#42; SCREEN CAPTURE &#42;&#42;&#42;&#42;</b></p>\r\n<p class="indent2new indentright">Must match code from <b>(a)</b>, including prompts on screen capture matching those in code.</p>\r\n<p class="indent2new indentright m-t-0">Code for <b>(a)</b> must be sensible.</p>\r\n<p class="indent2new indentright comp-top">****** Frame 7 ***********************************************</p>\r\n<p class="indent2new indentright comp">* Current Instruction Register: JSR 7</p>\r\n<p class="indent2new indentright comp">Run time error: Memory Address Error</p>\r\n<p class="indent2new indentright comp">Stack contents:</p>\r\n<p class="indent2new indentright comp">&nbsp;----</p>\r\n<p class="indent2new indentright comp">|&nbsp;&nbsp;3 |</p>\r\n<p class="indent2new indentright comp">| 14 |</p>\r\n<p class="indent2new indentright comp">&nbsp;----</p>\r\n<p class="indent2new indentright comp">Execution terminated</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>VB.Net</b></p>\r\n<p class="indent2new comp-top">Sub ExecuteJSR(ByRef Memory() As AssemblerInstruction, ByRef Registers() As Integer, ByVal Address As Integer, <b>ByVal MaxLines As Integer</b>)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Dim StackPointer As Integer = Registers(TOS) - 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>If StackPointer &lt;= MaxLines Then</b>&nbsp;&nbsp;\'MP1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, Registers)</b>&nbsp;&nbsp;\'MP4</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>Else</b>&nbsp;&nbsp;\'MP2</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Memory(StackPointer).OperandValue = Registers(PC)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers(PC) = Address</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers(TOS) = StackPointer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>End If</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">End Sub</p>\r\n<p class="indent2new comp-top">&nbsp;&nbsp;Sub Execute(ByVal SourceCode() As String, ByVal Memory() As AssemblerInstruction)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Dim Registers() As Integer = {0, 0, 0, 0, 0}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;SetFlags(Registers(ACC), Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers(PC) = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers(TOS) = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Dim FrameNumber As Integer = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Dim OpCode As String = Memory(Registers(PC)).OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;While OpCode &lt;&gt; &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim Operand As Integer = Memory(Registers(PC)).OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;* Current Instruction Register: {OpCode} {Operand}&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers(PC) += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select Case OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;LDA&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;STA&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;LDA#&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;ADD&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;JMP&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;JSR&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJSR(Memory, Registers, Operand, <b>Int(SourceCode(0))</b>)&nbsp;&nbsp;\'MP3</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;CMP#&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;BEQ&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;SUB&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;SKP&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &quot;RTN&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End Select</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Registers(ERR) = 0 Then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory(Registers(PC)).OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;End While</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;Execution terminated&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;End Sub</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 3</b></p>\r\n<p class="indent2new comp-top">def ExecuteJSR(Memory, Registers, Address<b>, MaxLines</b>):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;StackPointer = Registers[TOS] - 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if StackPointer &lt;= MaxLines:</b>&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else:</b>&nbsp;&nbsp;<b># MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue = Registers[PC]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Address</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] = StackPointer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return Memory, Registers</p>\r\n<p class="indent2new comp-top">def Execute(SourceCode, Memory):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = [0, 0, 0, 0, 0]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = SetFlags(Registers[ACC], Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode != &quot;HLT&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Operand = Memory[Registers[PC]].OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;* Current Instruction Register: &quot;, OpCode, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Registers[PC] + 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if OpCode == &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory = ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory, Registers = ExecuteJSR(Memory, Registers, Operand<b>, int(SourceCode[0])</b>)&nbsp;&nbsp;<b># MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] == 0:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;else:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print(&quot;Execution terminated&quot;)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">def ExecuteJSR(Memory, Registers, Address):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;StackPointer = Registers[TOS] - 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if Memory[StackPointer].OperandString != &quot;&quot; or Memory[StackPointer].OpCode != &quot;&quot;:</b>&nbsp;&nbsp;<b># MP1, MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else:</b>&nbsp;&nbsp;<b>#MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue = Registers[PC]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Address</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] = StackPointer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return Memory, Registers</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Python 2</b></p>\r\n<p class="indent2new comp-top">def ExecuteJSR(Memory, Registers, Address<b>, MaxLines</b>):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;StackPointer = Registers[TOS] - 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if StackPointer &lt;= MaxLines:</b>&nbsp;&nbsp;<b># MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else:</b>&nbsp;&nbsp;<b># MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue = Registers[PC]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Address</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] = StackPointer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return Memory, Registers</p>\r\n<p class="indent2new comp-top">def Execute(SourceCode, Memory):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = [0, 0, 0, 0, 0]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers = SetFlags(Registers[ACC], Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] = HI_MEM</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode != &quot;HLT&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber += 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Operand = Memory[Registers[PC]].OperandValue</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;print &quot;* Current Instruction Register: &quot;, OpCode, Operand</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Registers[PC] + 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if OpCode == &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory = ExecuteSTA(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteLDAimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteADD(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteJMP(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory, Registers = ExecuteJSR(Memory, Registers, Operand, <b>int(SourceCode[0])</b>)&nbsp;&nbsp;<b># MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteCMPimm(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteBEQ(Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteSUB(Memory, Registers, Operand)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP()</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;elif OpCode == &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers = ExecuteRTN(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] == 0:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = Memory[Registers[PC]].OpCode</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;else:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode = &quot;HLT&quot;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;print &quot;Execution terminated&quot;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">def ExecuteJSR(Memory, Registers, Address):</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;StackPointer = Registers[TOS] - 1</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if Memory[StackPointer].OperandString != &quot;&quot; or Memory[StackPointer].OpCode != &quot;&quot;:</b>&nbsp;&nbsp;<b># MP1, MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, Registers)</b>&nbsp;&nbsp;<b># MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else:</b>&nbsp;&nbsp;<b>#MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue = Registers[PC]</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] = Address</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] = StackPointer</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;return Memory, Registers</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Pascal</b></p>\r\n<p class="indent2new comp-top">procedure ExecuteJSR(var Memory: TMemory; var Registers: TRegisters; Address: integer<b>; MaxLines: integer</b>);</p>\r\n<p class="indent2new comp"><b>var</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>StackPointer: integer;</b></p>\r\n<p class="indent2new comp"><b>begin</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>StackPointer := Registers[TOS] - 1;</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if StackPointer &lt;= MaxLines</b>&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>then</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(\'Memory Address Error\', Registers)</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue := Registers[PC];</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] := Address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] := StackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">end;</p>\r\n<p class="indent2new comp-top">procedure Execute(var SourceCode: TSourceCode; var Memory: TMemory);</p>\r\n<p class="indent2new comp">var</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers: TRegisters;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode: string;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Operand, FrameNumber: integer;</p>\r\n<p class="indent2new comp">begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers := TRegisters.create(0, 0, 0, 0, 0);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;SetFlags(Registers[ACC], Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[PC] := 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;Registers[TOS] := HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;FrameNumber := 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;OpCode := Memory[Registers[PC]].OpCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;while OpCode &lt;&gt; \'HLT\' do</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameNumber := FrameNumber + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(FrameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Operand := Memory[Registers[PC]].OperandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writeln(\'* Current Instruction Register: \', OpCode, \' \', Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] := Registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'LDA\' then ExecuteLDA(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'STA\' then ExecuteSTA(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'LDA#\' then ExecuteLDAimm(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'ADD\' then ExecuteADD(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'JMP\' then ExecuteJMP(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'JSR\' then ExecuteJSR(Memory, Registers, Operand, <b>StrToInt(SourceCode[0])</b>);&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'CMP#\' then ExecuteCMPimm( Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'BEQ\' then ExecuteBEQ(Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'SUB\' then ExecuteSUB(Memory, Registers, Operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'SKP\' then ExecuteSKP();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if OpCode = \'RTN\' then ExecuteRTN(Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if Registers[ERR] = 0</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode := Memory[Registers[PC]].OpCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(SourceCode, Memory, Registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpCode := \'HLT\';</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;writeln(\'Execution terminated\');</p>\r\n<p class="indent2new comp">end;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">procedure ExecuteJSR(var Memory: TMemory; var Registers: TRegisters; Address: integer);</p>\r\n<p class="indent2new comp">var</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;StackPointer: integer;</p>\r\n<p class="indent2new comp">begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;StackPointer := Registers[TOS] - 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if (Memory[StackPointer].OperandString &lt;&gt; EMPTY_STRING) or Memory[StackPointer].OpCode &lt;&gt; EMPTY_STRING</b>&nbsp;&nbsp;<b>// MP1, MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>then</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(\'Memory Address Error\', Registers)</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;begin</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory[StackPointer].OperandValue := Registers[PC];</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[PC] := Address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registers[TOS] := StackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;end;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayStack(Memory, Registers)</p>\r\n<p class="indent2new comp">end;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>C#</b></p>\r\n<p class="indent2new comp-top">private static void ExecuteJSR(AssemblerInstruction[] memory, int[] registers, int address<b>, int maxLines</b>)</p>\r\n<p class="indent2new comp">{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int stackPointer = registers[TOS] - 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if (stackPointer &lt;= maxLines)</b>&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;memory[stackPointer].operandValue = registers[PC];</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = stackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(memory, registers);</p>\r\n<p class="indent2new comp">}</p>\r\n<p class="indent2new comp-top">&nbsp;&nbsp;private static void Execute(string[] sourceCode, AssemblerInstruction[] memory)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int[] registers = new int[] { 0, 0, 0, 0, 0 };</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int frameNumber = 0, operand = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;SetFlags(registers[ACC], registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;string opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (opCode != &quot;HLT&quot;)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frameNumber++;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;operand = memory[registers[PC]].operandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;* Current Instruction Register: {opCode} {operand}&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (opCode)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSTA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteLDAimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteADD(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJMP(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteJSR(memory, registers, operand<b>, Convert.ToInt32(sourceCode[0])</b>); break;&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteCMPimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteBEQ(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSUB(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteSKP(); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecuteRTN(memory, registers); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (registers[ERR] == 0)</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DisplayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = &quot;HLT&quot;;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;Execution terminated&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative method:</b></p>\r\n<p class="indent2new comp-top">private static void ExecuteJSR(AssemblerInstruction[] memory, int[] registers, int address)</p>\r\n<p class="indent2new comp">{</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int stackPointer = registers[TOS] - 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if (memory[stackPointer].operandString != &quot;&quot;)</b>&nbsp;&nbsp;<b>// MP1, MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>ReportRunTimeError(&quot;Memory Address Error&quot;, registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>else</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;memory[stackPointer].operandValue = registers[PC];</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = stackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;DisplayStack(memory, registers);</p>\r\n<p class="indent2new comp">}</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new"><b>Java</b></p>\r\n<p class="indent2new comp-top">void executeJSR(AssemblerInstruction[] memory, int[] registers, int address, <b>int maxLines</b>) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int stackPointer = registers[TOS] - 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if (stackPointer &lt;= maxLines) {</b>&nbsp;&nbsp;<b>// MP1</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>reportRunTimeError(&quot;Memory Address Error&quot;, registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>} else {</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;memory[stackPointer].operandValue = registers[PC] ;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = stackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;displayStack(memory, registers);</p>\r\n<p class="indent2new comp-top">}</p>\r\n<p class="indent2new comp-top">&nbsp;&nbsp;void execute(String[] sourceCode, AssemblerInstruction[] memory) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int[] registers = {0, 0, 0, 0, 0} ;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;setFlags(registers[ACC], registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = HI_MEM;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;int frameNumber = 0;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;displayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;displayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;String opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;while (!opCode.equals(&quot;HLT&quot;)) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frameNumber += 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.println();</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayFrameDelimiter(frameNumber);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int operand = memory[registers[PC]].operandValue;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.println(&quot;* Current instruction Register: &quot; + opCode + &quot; &quot; + operand);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = registers[PC] + 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (opCode) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeLDA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;STA&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSTA(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;LDA#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeLDAimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;ADD&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeADD(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JMP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeJMP(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;JSR&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeJSR(memory, registers, operand, <b>Integer.parseInt(sourceCode[0])</b>);&nbsp;&nbsp;<b>// MP3</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;CMP#&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeCMPimm(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;BEQ&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeBEQ(registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SUB&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSUB(memory, registers, operand); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;SKP&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeSKP(); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;RTN&quot;:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executeRTN(memory, registers); break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (registers[ERR] == 0) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = memory[registers[PC]].opCode;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayCurrentState(sourceCode, memory, registers);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opCode = &quot;HLT&quot;;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;}</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;Console.println(&quot;Execution terminated&quot;);</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;}</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new m-t-1"><b>Alternative Answer:</b></p>\r\n<p class="indent2new comp-top">void executeJSR(AssemblerInstruction[] memory, int[] registers, int address) {</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;int stackPointer = registers[TOS] - 1;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>if</b></p>\r\n<p class="indent2new comp"><b>(!memory[stackPointer].operandString.equals(EMPTY_STRING)|| !memory[stackPointer].opCode.equals(EMPTY_STRING))</b>&nbsp;&nbsp;<b>// MP1, MP3</b><b>{</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;<b>reportRunTimeError(&quot;Memory Address Error&quot;, registers);</b>&nbsp;&nbsp;<b>// MP4</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>} else {</b>&nbsp;&nbsp;<b>// MP2</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;memory[stackPointer].operandValue = registers[PC] ;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[PC] = address;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;&nbsp;&nbsp;registers[TOS] = stackPointer;</p>\r\n<p class="indent2new comp">&nbsp;&nbsp;<b>}</b></p>\r\n<p class="indent2new comp">&nbsp;&nbsp;displayStack(memory, registers);</p>\r\n<p class="indent2new comp">}</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[5]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question was skipped more than any other question.</p>\r\n<p class="indent1new">Of those who made an attempt, three quarters secured either full marks or three out of four on part (a). A range of different approaches was taken, including some not anticipated by the mark scheme. These were always given credit, some obtaining full marks, and this underscores the fact that there are usually many correct answers to a programming question, not just one.</p></h5>', 'notes': '', 'resources': ''}, 'Q20S1B09': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question m-b-1">This question refers to the subroutines <span class="comp">Graphics</span> and <span class="comp">LoadFile</span></p>\r\n<p class="indent1">(a)&emsp;&nbsp;State what values are passed in the parameter <span class="comp-top">Header</span> to the subroutine <span class="comp">LoadFile</span> when <span class="comp">LoadFile</span> is called for the <b>first</b> time in the subroutine <span class="comp">Graphics</span></p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;Explain how the content of <span class="comp">HeaderLine</span> is processed after it has been assigned a value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(3)</p>\r\n<p class="mark">(Total 4 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>Mark is for AO2 (analyse)</b> </p>\r\n<p class="indent2new indentright">The default values of the file header;</p>\r\n<p class="indent2new indentright m-t-0">Empty string, <span class="comp">MAX_WIDTH, MAX_HEIGHT</span>, empty string;</p>\r\n<p class="indent2new indentright"><b>A.</b> \'\'\'\' / \'\' / <span class="comp">EMPTY_STRING</span> for empty string</p>\r\n<p class="indent2new indentright m-t-0"><b>A.</b> 100 for <span class="comp">MAX_WIDTH</span> and/or <span class="comp">MAX_HEIGHT</span></p>\r\n<p class="indent2new indentright"><b>Max 1</b></p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>3 marks for AO2 (analyse)</b> </p>\r\n<p class="indent2new indentright">The string is split into separate parts;</p>\r\n<p class="indent2new indentright m-t-0">Delimited by a comma;</p>\r\n<p class="indent2new indentright m-t-0">Each part is assigned to a field of the header record;</p>\r\n<p class="indent2new indentright m-t-0"><b>A.</b> File type is used to determine which subroutine is called;</p>\r\n<p class="indent2new indentright"><b>Max 3</b></p>\r\n<p class="levelms">3</p>\r\n<p class="mark">[4]</p></h5>', 'examinerreport': '', 'notes': '', 'resources': ''}, 'Q20S1B11': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question refers to the text file <span class="comp">image3.txt</span> and the subroutine <span class="comp">LoadAsciiImage</span></p>\r\n<p class="indent1new m-b-1">The first line of the text file <span class="comp">image3.txt</span> contains:</p>\r\n<p class="indent1new m-b-1"><span class="comp">Cat,59,25,A</span></p>\r\n<p class="indent1">(a)&emsp;&nbsp;Explain the effect of changing the first line to <span class="comp">Cat,25,59,A</span> and then calling <span class="comp">LoadAsciiImage</span></p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(2)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;Explain the effect of changing the first line to <span class="comp">Cat,59,59,A</span> and then calling <span class="comp">LoadAsciiImage</span></p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(2)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&emsp;&nbsp;Explain the effect of changing the first line to <span class="comp">Cat,59,10,A</span> and then calling <span class="comp">LoadAsciiImage</span></p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(2)</p>\r\n<p class="mark">(Total 6 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>2 marks for AO2 (analyse)</b> </p>\r\n<p class="indent2new indentright">When the image is displayed/loaded it will not be the intended image</p>\r\n<p class="indent2new indentright m-t-0">// the pixels will be misaligned;</p>\r\n<p class="indent2new indentright m-t-0">As the line breaks will now be in the wrong places // image width is shorter but length is longer;</p>\r\n<p class="indent2new indentright m-t-0"><b>A.</b> there will be no error message / exception;</p>\r\n<p class="indent2new indentright"><b>Max 2</b></p>\r\n<p class="levelms">2</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>2 marks for AO2 (analyse)</b> </p>\r\n<p class="indent2new indentright">The image is now a larger dimension;</p>\r\n<p class="indent2new indentright m-t-0">There will not be enough data in the file;</p>\r\n<p class="indent2new indentright m-t-0">The bottom rows of the image will consist of dots;</p>\r\n<p class="indent2new indentright m-t-0">The code will cause an exception // &quot;<span class="comp">Error: Image data error</span>&quot; will be displayed;</p>\r\n<p class="indent2new indentright"><b>Max 2</b></p>\r\n<p class="levelms">2</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(c)&emsp;&nbsp;<b>2 marks for AO2 (analyse)</b> </p>\r\n<p class="indent2new indentright">The lower part of the picture will not be displayed/loaded // only the upper part of the picture will be displayed/loaded;</p>\r\n<p class="indent2new indentright m-t-0">Only the top 10 rows are displayed/loaded // the bottom 49 rows are not displayed/loaded // only the cat&#x2019;s head is displayed/loaded // the cat&#x2019;s body has been removed;</p>\r\n<p class="indent2new indentright"><b>Max 2</b></p>\r\n<p class="levelms">2</p>\r\n<p class="mark">[6]</p></h5>', 'examinerreport': '', 'notes': '', 'resources': ''}, 'QS19S1B07': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question refers to the subroutines <span class="comp">Game</span> and <span class="comp">ListPossibleMoves</span>.</p>\r\n<p class="indent1new">Describe what is contained in the parameter <span class="comp">PlayersPieces</span> when <span class="comp">ListPossibleMoves</span> is called for the first time in the subroutine <span class="comp">Game</span>.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Mark is for AO2 (analyse)</b></p>\r\n<p class="indent1new">positions of player A’s pieces;</p>\r\n<p class="indent1new indentright m-t-0"><b>A.</b> the contents of (the data structure/variable) <span class="comp">A //</span> pointer/address to <span class="comp">A // A;</span></p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Less able students stated that it was the player’s pieces that would be contained in the parameter. To earn this mark, a reference to the positions of player A’s pieces was required.</p></h5>', 'notes': '', 'resources': ''}, 'QS17S1B06': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Figure 1</b> shows an incomplete hierarchy chart for part of the <b>Skeleton Program</b>.</p>\r\n<p class="graph"><b>Figure 1</b></p>\r\n<p class="graph"><img src="AA_COM/QS17S1B06_files_Q/img01.jpg"/>&nbsp;</p>\r\n<p class="indent1new">With reference to the <b>Skeleton Program</b> and <b>Figure 1</b>, answer the questions below.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(a)&emsp;&nbsp;What should be written in box <b>(a)</b> in <b>Figure 1</b>?</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;What should be written in box <b>(b)</b> in <b>Figure 1</b>?</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&emsp;&nbsp;What should be written in box <b>(c)</b> in <b>Figure 1</b>?</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(d)&emsp;&nbsp;Explain how data is shared between the separate subroutines.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(2)</p>\r\n<p class="mark">(Total 5 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona indentright">(a)&emsp;&nbsp;<b>Mark is for AO2 (analyse)</b></p>\r\n<p class="indent2 indentright"><span class="comp">InitialiseField;</span></p>\r\n<p class="indent2 indentright"><b>I.</b> minor differences in case and spelling</p>\r\n<p class="indent2 indentright m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO2 (analyse)</b></p>\r\n<p class="indent2 indentright"><span class="comp">ReadFile;</span></p>\r\n<p class="indent2 indentright"><b>A.</b> <span class="comp">CreateNewField</span> if not given in part (c);</p>\r\n<p class="indent2 indentright m-t-0"><b>I.</b> minor differences in case and spelling</p>\r\n<p class="indent2 indentright m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(c)&emsp;&nbsp;<b>Mark is for AO2 (analyse)</b></p>\r\n<p class="indent2 indentright"><span class="comp">CreateNewField;</span></p>\r\n<p class="indent2 indentright"><b>A.</b> <span class="comp">ReadFile;</span> if not given in part (b)</p>\r\n<p class="indent2 indentright m-t-0"><b>I.</b> minor differences in case and spelling</p>\r\n<p class="indent2 indentright m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(d)&emsp;&nbsp;<b>All marks for AO1 (understanding)</b></p>\r\n<p class="indent2 indentright">1.&emsp;&ensp;&nbsp;Parameters/variables/values/data/arguments are passed;</p>\r\n<p class="indent2 indentright m-t-0">2.&emsp;&ensp;&nbsp;Values are returned from a subroutine;</p>\r\n<p class="indent2 indentright m-t-0">&emsp;&ensp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A.</b> reference parameters return updated values in Pascal;</p>\r\n<p class="indent2 indentright m-t-0">3.&emsp;&ensp;&nbsp;Constants are available to all subroutines // <b>A.</b> global variables in Python;</p>\r\n<p class="levelms">Max 2</p> \r\n<p class="mark">[5]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The hierarchy chart was well answered by the majority of students.</p>\r\n<p class="indent1new">Many students did not refer to the Skeleton Program when explaining how data is shared between the separate subroutines. The <span class="comp">Field</span> data structure, and other values, were passed as parameters and returned from subroutines. The term &#8216;parameter passing&#8217; did not appear to be familiar to some students.</p></h5>', 'notes': '', 'resources': ''}, 'QS00N103': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1a m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; What is meant by a <i>parameter</i> of a procedure?</p>  \r<p class="indent3new answer-toggle">______________________________________________________________</p>  \r<p class="indent3new answer-toggle">______________________________________________________________</p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2">(ii)&nbsp;&nbsp;&nbsp;&nbsp; What is meant by a <i>global variable</i>?</p>  \r<p class="indent3new answer-toggle">______________________________________________________________</p>  \r<p class="indent3new answer-toggle">______________________________________________________________</p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; When writing a procedure, why might a programmer prefer to use parameters rather than global variables?</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(1)</p>  \r<p class="mark">(Total 3 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1a indentright m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Value passed into, or out of, procedure from / to calling program</p>  \r<p class="levelms">1</p>  \r<p class="indent2 indentright">(ii)&nbsp;&nbsp;&nbsp;&nbsp; Variable defined outside any procedure and so in scope for whole program </p>  \r<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&nbsp;&nbsp;&nbsp;&nbsp; Saves memory since parameter takes no space when not in use</p>  \r<p class="indent2new indentright m-t-0">Enables portability of procedures / blackbox programming / incorporation of procedures into library</p>  \r<p class="indent2new indentright m-t-0">Enables re-using of variable / identifier names for formal parameters without interfering with other procedures </p>  \r<p class="indent2new indentright m-t-0">Passing by value prevents accidental alteration of a value having unexpected side-effects in other procedures<br><i>1 mark for a relevant point</i></p>\r<p class="levelms">1</p>  \r<p class="mark">[3]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Parameters are clearly widely misunderstood - many answers reflected the common misunderstanding of the word as “boundaries” rather than context-determining factors. Almost any answer about passing data to / from procedures or functions would do. Most, on the other hand, understood global variables. Answers to (b) were not encouraging, probably because parameters are misunderstood - the best answers were either the use of portable procedures and the ability to include them in libraries for re-use, or the saving of memory by discarding variables not currently in use. Another popular correct answer is the risk of a procedure accidentally altering a global and therefore having unexpected side effects in other procedures.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1A01': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The algorithm, represented using pseudo-code in the figure below, describes a method to access numbers in the data structure, <span class="comp">List</span>, shown in <b>Table 1</b>.</p>\r\n<p class="indent3new comp-top">SUBROUTINE A(S, X, Y)</p>\r\n<p class="indent3new comp">&emsp;&nbsp;P <span class="font18">&#8592;</span> -1</p>\r\n<p class="indent3new comp">&emsp;&nbsp;WHILE P = -1 AND X &lt;= Y</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;Z <span class="font18">&#8592;</span> (X + Y) DIV 2</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;IF List[Z] = S THEN</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;P <span class="font18">&#8592;</span> Z</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;ELSE</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;IF List[Z] &lt; S THEN</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;X <span class="font18">&#8592;</span> Z + 1</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;ELSE</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;Y <span class="font18">&#8592;</span> Z &#x2013; 1</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;&emsp;&nbsp;ENDIF</p>\r\n<p class="indent3new comp">&emsp;&nbsp;&emsp;&nbsp;ENDIF</p>\r\n<p class="indent3new comp">&emsp;&nbsp;ENDWHILE</p>\r\n<p class="indent3new comp">&emsp;&nbsp;RETURN P</p>\r\n<p class="indent3new comp">ENDSUBROUTINE</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new">The <span class="comp-top">DIV</span> operator calculates the whole number part resulting from an integer division, for example, <span class="comp-top">10 DIV 3 = 3</span></p>\r\n<p class="indent1new">Complete <b>Table 2</b> by hand-tracing the algorithm in the figure above when the following statement is executed.</p>\r\n<p class="graph comp-top">Result <span class="font18">&#8592;</span> A(38, 0, 18)</p>\r\n<p class="indent1new">You may not need to use all the rows in <b>Table 2</b>.</p>\r\n<p class="indent1new">The first row of <b>Table 2</b> has already been completed for you.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="bottom">&nbsp;</p>\r\n<table class="data-table left0">\r\n\t<tr>\r\n\t\t<td colspan="19" class="no-border"><p class="no-padding"><b>Table 1</b></p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td colspan="19" class="no-border"><p class="no-padding text-left comp"><b>List</b></p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[0]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[1]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[2]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[3]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[4]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[5]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[6]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[7]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[8]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[9]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[10]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[11]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[12]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[13]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[14]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[15]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[16]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[17]</p></td>\r\n\t\t<td class="col-1 no-border"><p class="no-padding comp">[18]</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">2</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">8</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">12</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">18</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">25</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">29</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">36</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">42</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">49</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">51</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">57</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">61</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">68</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">71</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">79</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">83</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">84</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">91</p></td>\r\n\t\t<td class="col-1"><p class="no-padding comp-top">97</p></td>\r\n\t</tr>\r\n</table>\r\n<p class="bottom">&nbsp;</p>\r\n<table class="data-table left3">\r\n<tr>\r\n\t\t<td colspan="14" class="no-border"><p class="no-padding"><b>Table 2</b><br/>&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top"><b>S</b></p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top"><b>X</b></p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top"><b>Y</b></p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top"><b>P</b></p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top"><b>Z</b></p></td>\r\n\t\t<td class="col-4 tablegrey2"><p class="padded comp-top"><b>List[Z]</b></p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top">38</p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top">0</p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top">18</p></td>\r\n\t\t<td class="col-2 tablegrey2"><p class="padded comp-top">&minus;1</p></td>\r\n\t\t<td class="col-2 tableblack"><p class="padded comp-top">&nbsp;</p></td>\r\n\t\t<td class="col-4 tableblack"><p class="padded comp-top">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-2"><p class="padded">&nbsp;</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td class="col-2" colspan="5"><p class="padded comp-top"><b>Result</b>:</p></td>\r\n\t\t<td class="col-4"><p class="padded">&nbsp;</p></td>\r\n\t</tr>\r\n</table>\r\n<p class="mark">(Total 5 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>5 marks for AO2 (apply)</b>  </p>\r\n<p class="graph"><img src="AA_COM/M22S1A01_files_M/img01.jpg"/>&nbsp;</p>\r\n<p class="indent1new indentright"><b>1 mark</b> for each correct set of values in the correct sequence (boxed in red);</p>\r\n<p class="indent1new indentright"><b>Max 4</b> if any errors</p>\r\n<p class="indent1new indentright"><b>A.</b> entries within a boxed area sharing a row (e.g. 9 and 8 on the same row).</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new indentright"><b>Alternative Answer Layout:</b></p>\r\n<p class="indent1new indentright m-t-0"><b>1 mark</b> for each correct set of values in the correct sequence (4 sets boxed in red, 1 set in disjointed boxes in green and shaded light grey);</p>\r\n<p class="graph"><img src="AA_COM/M22S1A01_files_M/img02.jpg"/>&nbsp;</p>\r\n<p class="mark">[5]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Most students were able to secure either four or five marks on the trace table question. Where students secured four marks, the mark that was dropped was the final mark. This required the result of the algorithm to be given.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1B11P1': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">What is a subroutine?</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Mark is for AO1 (knowledge)</b></p>\r\n<p class="indent1new indentright">Named / (reference to) identifier / callable &#8216;out of line&#8217; block of code (that may be called by simply writing its name in a program statement);</p>\r\n<p class="indent1new indentright"><b>A.</b> subroutine is used to give a block of code a name (and this name can be used to execute this group of statements)</p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Many students dropped the mark on this question by providing an incomplete answer. Only a very small number of answers were incorrect, but many more were incomplete. Stating only that a subroutine is a named section of code was insufficient on its own, and was a commonly-given answer.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1B11P2': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The use of subroutines promotes code re-use.</p>\r\n<p class="indent1new">Describe, with references to subroutine(s) in the <b>Skeleton Program</b>, an example of how a subroutine has been re-used.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Mark is for AO2 (analyse)</b></p>\r\n<p class="indent1new indentright"><span class="comp">LoadPuzzle</span> is called more than once (from <span class="comp">NumberPuzzle</span> and also from <span class="comp">LoadPartSolvedPuzzle</span>)</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">// DisplayGrid</span> is called more than once (from within <span class="comp">SolvePuzzle</span>)</p>\r\n<p class="indent1new indentright m-t-0"><span class="comp">//ResetDataStructures</span> is called more than once (from <span class="comp">NumberPuzzle</span> and twice from <span class="comp">LoadPuzzle</span>);</p>\r\n<p class="indent1new indentright"><b>A.</b> <span class="comp">readLine / print</span> is called more than once (Java only)</p>\r\n<p class="indent1new indentright m-t-0"><b>NE.</b> &#8216;called more than once&#8217; without an appropriate subroutine name</p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The majority of students secured the mark for this question.</p></h5>', 'notes': '', 'resources': ''}, 'Q22S1B11P3': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">Describe an advantage of re-using subroutines.</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="indent1new answer-toggle">_______________________________________________________________________</p>\r\n<p class="mark">(Total 1 mark)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question"><b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent1new indentright">Saves time as code can be written once and called in many places;</p>\r\n<p class="indent1new indentright m-t-0">Reduced storage space of (source) code;</p>\r\n<p class="indent1new indentright m-t-0">Reduces testing time as less code to test;</p>\r\n<p class="indent1new indentright m-t-0">Avoids errors because code cannot be written differently if it is used in multiple places; Program code will be easier to understand / maintain;</p>\r\n<p class="indent1new indentright"><b>MAX 1</b></p>\r\n<p class="mark">[1]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question was another question for which responses scoring zero were more likely to be incomplete than incorrect. Students were asked to describe rather than state, showing understanding rather than knowledge. As such, &#x0027;reduces testing time&#x0027; was insufficient, whereas &#x0027;reduces testing time due to less code to test&#x0027; secured the mark.</p></h5>', 'notes': '', 'resources': ''}, 'Q20S1B04': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the name of an identifier for:</p>\r\n<p class="indent1">(a)&emsp;&nbsp;a variable that is used to store a Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;a user-defined subroutine that returns only <b>one</b> value that <b>must</b> be a string.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&emsp;&nbsp;a user-defined subroutine that uses nested <b>indefinite</b> iteration.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 3 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b> </p>\r\n<p class="indent2new indentright comp-top">FileFound / FileTypeOK / ProgramEnd;</p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b> </p>\r\n<p class="indent2new indentright"><span class="comp">ConvertChar</span> //</p>\r\n<p class="indent2new indentright m-t-0"><span class="comp">GetMenuOption</span> (Python only);</p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(c)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new indentright comp-top">EditImage;</p>\r\n<p class="indent2new indentright"><b>R.</b> if any additional code</p>\r\n<p class="indent2new indentright m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new indentright m-t-0"><b>I.</b> case &amp; spacing</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[3]</p></h5>', 'examinerreport': '', 'notes': '', 'resources': ''}, 'QS19S1B04': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the name of an identifier for:</p>\r\n<p class="indent1new">(a)&emsp;&nbsp;a variable that is used to store a Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new">(b)&emsp;&nbsp;a user-defined subroutine that returns a single Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona">(a)&emsp;&nbsp;<b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new comp-top">Valid</p>\r\n<p class="indent2new comp">/ValidPiece</p>\r\n<p class="indent2new comp">/ValidMove</p>\r\n<p class="indent2new comp">/Found</p>\r\n<p class="indent2new comp">/EndOfList</p>\r\n<p class="indent2new comp">/Jumping</p>\r\n<p class="indent2new comp">/GameEnd</p>\r\n<p class="indent2new comp">/FileFound;</p>\r\n<p class="indent2new m-t-0"><b>A.</b> <span class="comp">CanJump;</span></p>\r\n<p class="indent2new"><b>R.</b> if any additional code</p>\r\n<p class="indent2new m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new m-t-0"><b>I.</b> case &#38; spacing</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1new">(b)&emsp; <b>Mark is for AO1 (understand)</b></p>\r\n<p class="indent2new comp-top">/ValidMove</p>\r\n<p class="indent2new comp">/ValidJump</p>\r\n<p class="indent2new comp">/ListEmpty;</p>\r\n<p class="indent2new"><b>A.</b> <span class="comp">setUpBoard</span> (for Java only)</p>\r\n<p class="indent2new m-t-0"><b>R.</b> if any additional code</p>\r\n<p class="indent2new m-t-0"><b>R.</b> if spelt incorrectly</p>\r\n<p class="indent2new m-t-0"><b>I.</b> case &#38; spacing</p>\r\n<p class="levelms">1</p>\r\n<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The majority of students secured both of the marks for this question. A few students copied across more than just the identifier for each part and therefore did not gain the mark as it was not clear which part of the copied code they believed the identifier to be.</p></h5>', 'notes': '', 'resources': ''}, 'QS17S1B04': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">State the name of an identifier for:</p>\r\n<p class="indent1">(a)&emsp;&nbsp;a variable that is used to store a Boolean value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&emsp;&nbsp;a user-defined subroutine that returns an integer value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&emsp;&nbsp;an array or list variable.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(d)&emsp;&nbsp;a local variable used to store a string value.</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="indent2new answer-toggle">___________________________________________________________________</p>\r\n<p class="mark">(1)</p>\r\n<p class="mark">(Total 4 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="questiona indentright">(a)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new comp-top indentright">Frost // Continuing;</p>\r\n<p class="indent2new indentright"><b>R</b>. if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>I</b>. minor differences in case and spelling</p>\r\n<p class="indent2new m-t-0 indentright"><b>R</b>. significant differences in case and spelling</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new comp-top indentright">GetHowLongToRun;</p>\r\n<p class="indent2new indentright"><b>R</b>. if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>I</b>. minor differences in case and spelling</p>\r\n<p class="indent2new m-t-0 indentright"><b>R</b>. significant differences in case and spelling</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(c)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new comp-top indentright">Field;</p>\r\n<p class="indent2new indentright"><b>R</b>. <span class="comp">FieldRow</span></p>\r\n<p class="indent2new m-t-0 indentright"><b>R</b>. if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>I</b>. minor differences in case and spelling</p>\r\n<p class="indent2new m-t-0 indentright"><b>R</b>. significant differences in case and spelling</p>\r\n<p class="levelms">1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(d)&emsp;&nbsp;<b>Mark is for AO1 (understanding)</b></p>\r\n<p class="indent2new comp-top indentright">Response // FileName // FieldRow;</p>\r\n<p class="indent2new indentright"><b>R</b>. if any additional code</p>\r\n<p class="indent2new m-t-0 indentright"><b>I</b>. minor differences in case and spelling</p>\r\n<p class="indent2new m-t-0 indentright"><b>R</b>. significant differences in case and spelling</p>\r\n<p class="levelms">1</p>  \r\n<p class="mark">[4]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The majority of students secured all of the marks for this question. A small number of students copied across more than just the identifier for each part and therefore did not gain the mark as it was not clear which part of the copied code they believed the identifier to be.</p></h5>', 'notes': '', 'resources': ''}, 'QS07102': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1 m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; Writing program code requires the programmer to use identifiers for variables and procedures.</p>  \r<p class="indent2">(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; State <b>two</b> other uses for identifiers.</p>  \r<p class="indent3new answer-toggle">1. ____________________________________________________________</p>  \r<p class="indent3new answer-toggle">2. ____________________________________________________________</p>  \r<p class="mark">(2)</p>  \r<p class="indent2">(ii)&nbsp;&nbsp;&nbsp;&nbsp; Most programming languages impose restrictions or rules about what is and is not allowed for identifier names. State <b>one</b> such rule.</p>  \r<p class="indent3new answer-toggle">______________________________________________________________</p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; Program code is often written with the use of procedures. Describe <b>one</b> reason why a programmer would decide to use procedures.</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(c)&nbsp;&nbsp;&nbsp;&nbsp; A programmer-written function <b><span style=\'font-family:"Times","serif"\'>SearchThisArray</span></b> is defined as follows.</p>  \r<p class="bottom">&nbsp;</p>  \r<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=5 style=\'margin-left:48pt;border-collapse:collapse\'>  \r\t<tr>       \r\t\t<td width=672 valign=top style=\'width:403.0pt;border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=table style=\'margin-top:1.0pt;margin-right:0cm;margin-bottom:1.0pt;   margin-left:0cm\'><span class="comp">SearchThisArray(ThisArray</span><span   style=\'font-size:10.0pt;font-family:"Courier New";font-weight:normal\'> :   Array[1..10] Of String;</span></p><p class=table align=right style=\'margin-top:1.0pt;margin-right:2.85pt;   margin-bottom:1.0pt;margin-left:0cm;text-align:right\'><span style=\'font-size:   10.0pt;font-family:"Courier New"\'>ThisString </span><span style=\'font-size:   10.0pt;font-family:"Courier New";font-weight:normal\'>: String) : Integer ;</span></p><p class=table style=\'margin-top:1.0pt;margin-right:0cm;margin-bottom:1.0pt;   margin-left:0cm\'><span class="comp"><br>   The function searches the array</span><span class="comp"> </span><span style=\'font-size:10.0pt;font-family:   "Courier New"\'>ThisArray</span><span style=\'font-size:11.0pt;font-family:   "Courier New";font-weight:normal\'> for the value </span><span   style=\'font-size:10.0pt;font-family:"Courier New"\'>ThisString</span><span class="comp">.<br>   <br>   If an exact match is found, the function returns the index position in </span><span   style=\'font-size:10.0pt;font-family:"Courier New";font-weight:normal\'>ThisArray</span><span class="comp">.<br>   If not found, the function returns -1.<br>   If the function’s arguments, ThisArray and ThisString are illegally formed,   the<br>   function returns -2</span></p></td>  \r\t</tr> \r</table></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2new">The function is used in a program with the statements shown below and uses the data shown in the <span style=\'font-size:10.0pt;font-family: Courier\'>Customer</span> array in the figure below.</p>  \r<p class="bottom">&nbsp;</p>  \r<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=5 style=\'margin-left:163.6pt;border-collapse:collapse\'>  \r\t<tr>       \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Index (Subscript)</p></td>   \r\t\t<td width=143 valign=bottom style=\'width:86.0pt;border:none;border-bottom:   solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Customer</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[1]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Weeks</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[2]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Adamson</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[3]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Patel</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[4]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Berkovic</p></td>  \r\t</tr>  \r\t<tr>    \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[5]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Ince</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[6]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Neale</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[7]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Williamson</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[8]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Collins</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[9]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Davis</p></td>  \r\t</tr>  \r\t<tr>     \r\t\t<td width=117 valign=top style=\'width:70.25pt;border:none;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>[10]</p></td>   \r\t\t<td width=143 valign=top style=\'width:86.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt\'><p class=box>Beckham</p></td>  \r\t</tr> \r</table>  \r<p class="indent2new">What is the value returned to variable <span class="comp">Result</span> in each case?</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2">(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="comp">Result := SearchThisArray(Customer, ’Beckham’)</span></p>  \r<p class="indent3new answer-toggle">Value of <span class="comp">Result</span> ________________________________________________</p>  \r<p class="mark">(1)</p>   \r<p class="indent2">(ii)&nbsp;&nbsp;&nbsp;&nbsp; <span class="comp">Result := SearchThisArray(Customer, ’Williams’)</span></p>  \r<p class="indent3new answer-toggle">Value of<span class="comp"> Result</span> ________________________________________________</p>  \r<p class="mark">(1)</p>  \r<p class="mark">(Total 6 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1a indentright m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (User defined) functions // program // object // class // data type // constant // record// label //control/component/ by example e.g. textbox ;</p>  \r<p class="levelms">Max 2</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent2 indentright">(ii)&nbsp;&nbsp;&nbsp;&nbsp; Maximum number of characters ;</p>  \r<p class="indent3new indentright m-t-0">No &lt;Space&gt; or other punctuation characters ;</p>  \r<p class="indent3new indentright m-t-0">No use of reserved words ;</p>  \r<p class="indent3new indentright m-t-0">Must not start with a digit character ;</p>  \r<p class="indent3new indentright m-t-0">Case sensitive / permitted case only ;</p>  \r<p class="indent3new indentright m-t-0">Cannot define the same identifier name more than once ;</p>  \r<p class="indent3new indentright m-t-0"><b>R</b> any reference to <u>file</u>names</p>  \r<p class="levelms">Max 1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&nbsp;&nbsp;&nbsp;&nbsp; Their use matches closely the (modular/structured) design ;</p>  \r<p class="indent2new indentright m-t-0">Code can be used <u>‘repeatedly’</u> within the same program ;</p>  \r<p class="indent2new indentright m-t-0">Code may originate from a program library/module ;</p>  \r<p class="indent2new indentright m-t-0">To make program debugging/testing/maintenance easier ;</p>  \r<p class="levelms">Max 1</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1a indentright" >(c)&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10 ;</p>  \r<p class="levelms">1</p>  \r<p class="indent2 indentright">(ii)&nbsp;&nbsp;&nbsp;&nbsp; -1 ;</p>  \r<p class="levelms">1</p>  \r<p class="mark">[6]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1a m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Well answered with the most popular answers being constants and functions.</p>  \r<p class="indent2">(ii)&nbsp;&nbsp;&nbsp;&nbsp; Many candidates then misunderstood what was wanted here and proceeded to give answers which generally described how programs were constructed with loops, selection statements, etc.</p>  \r<p class="indent2new">Due to the range of differences with different languages, a wide range of answers were considered acceptable; the most popular being ‘it must not contain any &lt;Space&gt; characters’ and ‘the use of reserved words is not permitted’. Some candidates confused what is allowed in a programming language with what is permitted by the operating system, proceeding to explain what was not allowed for filenames. Worse, was the suggested answer that ’names must be more than 6 characters long’ which suggested that the rules about the choice of passwords were being described.</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; No great detail was expected for the mark and most candidates were able to give an answer which mapped to those on the mark scheme. Use of language was an issue for some candidates who described ‘chunks of program code’! There were also answers which clearly were answering ‘last year’s question’ suggesting procedures may or may not return values, contrasting with functions which always return a value.</p>  \r<p class="indent1">(c)&nbsp;&nbsp;&nbsp;&nbsp; This was similar to questions which have previously been set and was well answered.</p></h5>', 'notes': '', 'resources': ''}, 'QS0516B': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The following code is part of a high level program</p>  \r<p class="indent1new">&nbsp;&nbsp;Var Name: String;</p>  \r<p class="indent1new m-t-0">&nbsp;&nbsp;Var Hours: Integer;</p>  \r<p class="indent1new m-t-0">&nbsp;&nbsp;Var RateOfPay: Real;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent1new m-t-0">Function CalculatePay(InHours: Integer; InRateOfPay: Real): Real;</p>  \r<p class="indent1new m-t-0">&nbsp;&nbsp;Var Total: Real;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent2new m-t-0">&#42;</p>  \r<p class="indent2new m-t-0">&#42;</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(a)&nbsp;&nbsp;&nbsp;&nbsp; Procedures and functions are often <i>self-contained</i>. What is meant by the term self-contained in this context?</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">&nbsp;(1)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; Give <b>one</b> reason why the use of global variables may introduce program bugs.</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(1)</p>  \r<p class="mark">(Total 2 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1 indentright m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; Do not use any global variables// use only local variables and/or parameters;</p>  \r<p class="indent2new indentright m-t-0"><b>A </b>Can be compiled independently // can be placed in a library</p>  \r<p class="levelms">1</p>  \r<p class="indent1 indentright">(b)&nbsp;&nbsp;&nbsp;&nbsp; Local and global variables with the same name can be misidentified//difficult to test individual procedures/ functions//</p>  \r<p class="indent2new indentright m-t-0">Not clear that as a side-effect of executing procedure/function a global variable could change its value;</p>  \r<p class="levelms">1</p>  \r<p class="mark">[2]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">This question showed that many candidates have not had sufficient exposure to programming techniques.</p>  \r<p class="indent1new">Parts (a) and (b) often showed up the candidates’ inability to express themselves clearly.</p>  \r<p class="indent1">(a)&nbsp;&nbsp;&nbsp;&nbsp; Many candidates described recursion. Those that didn’t often restated the question. Only the very best candidates were able give a satisfactory answer.</p>  \r<p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; The responses to this part were also very disappointing. Answers were often irrelevant and/or badly expressed.</p></h5>', 'notes': '', 'resources': ''}, 'QS02106': {'question': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The structured approach when writing programs uses functions and procedures.</p>  \r<p class="indent1">(a)&nbsp;&nbsp;&nbsp;&nbsp; Give two reasons why procedures are used.</p>  \r<p class="indent2new answer-toggle">1. _________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">2. _________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(2)</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1">(b)&nbsp;&nbsp;&nbsp;&nbsp; What are parameters used for in the context of procedures and functions?</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="indent2new answer-toggle">___________________________________________________________________</p>  \r<p class="mark">(1)</p>  \r<p class="mark">(Total 3 marks)</p></h5>', 'markscheme': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">&nbsp;</p>\r<p class="indent1 indentright m-t-0">(a)&nbsp;&nbsp;&nbsp;&nbsp; To give a set of statements a name;</p>  \r<p class="indent2new indentright m-t-0">To avoid repeating code; procedures can be called up many times; so a program may be developed by more than one programmer;</p>  \r<p class="indent2new indentright m-t-0">To enable top-down development;</p>  \r<p class="indent2new indentright m-t-0">To enable stub-testing; so libraries of code written by other programmers may be used;</p>  \r<p class="indent2new indentright m-t-0">For creating libraries of code;</p>  \r<p class="indent2new indentright m-t-0">Allows for modular programming; allows for modular testing;</p>  \r<p class="indent2new indentright m-t-0">To make program easier to debug / maintain / understand;</p>  \r<p class="levelms">Max 2</p></h5><h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="indent1 indentright">(b)&nbsp;&nbsp;&nbsp;&nbsp; To pass <u>data/value</u> within programs / to pass <u>data/value</u> in and out of procedures/functions;</p>  \r<p class="levelms">1</p>  \r<p class="mark">[3]</p></h5>', 'examinerreport': '<h5 class=\'contentSeparator\' style=\'page-break-inside: avoid;\'><div class=\'qnumber-hidden\'></div><p class="question">The few candidates who studied the topic had no difficulty answering this question. Those who had not, often assumed that ‘procedure’ was a method of programming, ‘parameters’ were a set of rules or limits beyond which the program could not go. It is important that candidates gain some experience of programming with functions and procedures and appreciate the role of parameters in passing data into / out of these subroutines. A creditworthy response was that the use of procedures avoided repeating code because a procedure could be called up many times from different parts of the program.</p></h5>', 'notes': '', 'resources': ''}}
User: Now, the user will ask questions after this message. Use everything I gave you and the knowledge you have acquired, and from the notes you made, to answer their question in a very concise way that WILL score ALL marks. Just like the notes. For this, your answer will not have the same structure as the revision notes. Think of it as answering an exam question: short, consice, useful, scores ALL marks. Just like the exam questions provided to you, you will not leave your response in a 'notes' manner. You are just answering an exam question: which means it has to be very short unless explicitly specified by the user that it must be long and detailed. So, keep it short, concise, and only a couple of sentences that score ALL marks. Remember, it is an A-Level exam question and you will style it as such: incredibly concise sentences (essentially like bullet points but without the bullet points) that score marks. Most sentences won't even have commas, this does not mean you can't use them. Also do not repeat the question in your answer, just do it. Score all marks, assume how many marks there are based on the question if it is not provided to you. Imagine that for every sentence you make, you score a mark (for simpler questions), for high (>5 mark) questions that may differ.
In summary, you must:
* Answer very concisely. Kind of like bullet points but as a short para. Most of the time, a sentence, or point, will be a mark.
* Do not repeat the question at the start.
* Don't over-do your answer. Please. 1 mark (e.g., usually, 'What' questions) is like one very short sentence usually. Remember the summary from the notes? Your answer will essentially be like that for most questions but a bit (a bit!) more developed. Remember, this is just A-Levels. Use some of the exam questions that I provided as an example of how you should model your answers.
* When you're listing examples, don't list every example in the universe.
* Score all marks. Be helpful.
User: Write the notes you made. For exam questions, include their number of marks, the whole question content and the answer. Make advantages and disadvantages in clear bullet-points
Assistant: