Algorithm - An algorithm is a sequence of step by step instructions to solve a given problem. Common methods of defining algorithms include pseudo-code, flowcharts and structured English.
This is an algorithm which should have four outputs, a, b, c and d.
The algorithm does not work as intended.
The outputs that this algorithm will give are 0 and 1
This algorithm does not work as intended. The algorithm will not output c or d as they are undefined. This is because the scope of c and d lies within the function myFunction. C and D are local variables to myFunction.
The lifetime of the data stored in each variable end when myFunction ends. Variables c and d are not available to the main program.
global scope - lifetime entire program
local scope - only for that function/procedure
self documenting identifiers - An identifer, does just that it names/labels something to help identify it. We use idetifers to name for variables, constants and subroutines. e.g. calculateAge, name, area not CA, n or a.
Algorithm - An algorithm is a sequence of step by step instructions to solve a given problem. Common methods of defining algorithms include pseudo-code, flowcharts and structured English.
Pseudo Code - Provides a means of expressing algorithms without worrying about the syntax of a particular language. It is an intermediate stage between plain English and the programming language.
Flowchart - provide a diagrammatic visualisation of inputs, processes and outputs completed by the algorithm.
Structured English - Breaks down an algorithm into simple English words to help show a step by step solution.
Syntax - The syntax of a programming language is the exact way in which the program statements have to be written e.g. wall_area = length * height; When using a structured programming language the GOTO statement should be avoided as it can produce unstructured and messy code.
Subroutine - A sequence of program instructions that performs a specific task, packaged as a unit.
This unit can then be used in programs wherever that particular task needs to be performed. Subroutines may be defined within programs, or separately in libraries which can be used by many programs.
In different programming languages, a subroutine may be called a procedure, function, method, or subprogram.
Procedure - is a subroutine (see above), which does not return a value.
Ususally used when you carry out a task. e.g. output the players lives, score, name to the screen.
Function - is a subroutine which returns a value.
Usual used when you need a calculation. e.g. return the players current direction, movement score, name, etc.
Constant - A constant can declare an identifier whose value does not change throughout the program. An example of this could be VAT at 20%.
Option Explicit - The main purpose of using the statement 'Option Explicit' in the declaration section of VB code is to ensure you declare all variables used in the program.
Form_Load Procedure - The effect of placing some program statements (code) into a Form_Load Procedure in VB is that the code is executed immediately as the form loads onto the desktop.
Declare a variable to store a whole number e.g. DIM Number As Integer
Assign the value 73 to your variable e.g. Number = 73
Declare a variable to store a telephone number e.g. Dim TelNo As String
Assign the telephone number "02920 642037" to your variable e.g. TelNo="02920 642037"
Show below is part of a high level language program used to manage a telephone contact list:
It is good practise to have a stadardised why of programming. Program code must be written to be clear and understandable, so that it can be developed and maintained by others.
use a naming convention - e.g. camelCase is widely adopted where idetifiers start with a lowercaw letter and every new word a capital letter is used.
self documenting idetifiers - using variable names that describe what the variable contains is important. Poor variable names can make it difficult to work out what is going on in a program. Sub-program/ function names should describe what the function does. ‘Function2’ is not a suitable name for a function used to calculate an average score. ‘calcAverage’ would be more appropriate.
Indentation: moving parts of code that form the content of constructs such as loops or if statements to the right makes it easier to see the overall structure.
In some languages, (e.g. Python) indentation is mandatory, missing it out will result in syntax errors. It is also much easier to debug properly indented code.
White space should be used to separate different subprograms and functions so that it is easier to see each module (section) of code.
Internal comments - are comments added to program code, that are not translated when the program runs, can be used to add descriptions, or explanations.
This is useful when working as part of a team, as other programmers can get an idea of what the code is doing and why certain decisions have been made.
Modulatity - large programs are often broken down into smaller chunks known as modules or subroutines, procedures or functions (see above).
WJEC Knowlege Organisers:
https://resource.download.wjec.co.uk/vtc/2020-21/ko20-21_1-4/wjec_ko_as_9-1.pdf
https://resource.download.wjec.co.uk/vtc/2020-21/ko20-21_1-4/wjec_ko_as_9-2.pdf
https://resource.download.wjec.co.uk/vtc/2020-21/ko20-21_1-4/wjec_ko_as_9-3.pdf
https://resource.download.wjec.co.uk/vtc/2020-21/ko20-21_1-4/wjec_ko_as_9-4.pdf
https://resource.download.wjec.co.uk/vtc/2020-21/ko20-21_1-4/wjec_ko_as_9-5.pdf
Link to all: