2017 /

Languages and Environments

Description of Low Level Languages

  • processor only carries out machine code instructions which are hard for humans to read and understand
  • one line of a low-level language program is converted into one line of machine code (binary)
  • instructions are processor or virtual machine specific
  • operations may include:-
  • moving/setting/loading register values
  • addition/subtraction between registers, values and/or memory
  • accessing memory locations
  • an instruction has two parts - opcode and operand(s) e.g.
  • e.g. MOV AL, 61h means “Load the register called AL with 97 decimal (61 hex)”
  • Typically LLL programs are written using assembly code or machine code:-
  • Assembly code –
  • groups of 1s and 0s are replaced with keywords to make the code easier to read e.g. MOV AL, 61h
  • needs to be converted to binary using an assembler
  • is architecture dependent (different codes exist for different types of processor)
  • not fully portable because of architecture dependence
  • Machine code:-
  • True machine code uses binary but programmer normally uses decimal, octal, or hexadecimal that are more readable
  • translated to binary by a program called a loader
  • hexadecimal notation :-
  • instructions written using base 16
  • uses 0, 1, 2, 3, 4, 5, 6, 7, 8,9, A, B,C, D, E, F
  • Reasons to use LLL:-
  • Optimisation of code – LLL programs use less RAM than high-level languages
  • Machine code program in binary does not require a translator to be in RAM
  • Greater control of hardware features than high-level languages (e.g. in small embedded computers such as home appliances)

Description of High Level Languages

  • Use English-like language so programs are easier to read, write and maintain than low-level language programs
  • Programs must be translated to machine code before a computer can use them
  • Translation carried out by interpreter or compiler
  • Wide variety with different areas of focus, e.g. web development, mobile app development or games development
  • Portable – can be used by many different computers – as long as a translator is available for the computer
  • Allow access to module libraries
  • Use data types and data structures, selection statements and repetition/iteration constructs
  • Use logic operators and functions that are built into the language e.g. >, <, = , etc
  • Compiler:-
  • Compiler saves the object code and so does not retranslate on each pass through the loop
  • Interpreter may retranslate on each pass through the loop using processor time
  • Interpreter resident in memory compiler doesn’t need to be in memory

Description of procedural languages

  • Programs consist of a sequence of commands that are executed in order– programmer dictates the order of execution
  • Code contained in procedures (subroutines) that each carry out one main task
  • Data passed between procedures using parameters
  • Allow access to module libraries
  • Use data types and data structures, selection statements and repetition/iteration constructs
  • Use logic operators and functions that are built into the language e.g. >, <, = , etc

Description of declarative languages

  • Often used by intelligent systems
  • Have fewer variable types and control structures than procedural languages
  • Describes what computation should be performed rather than how that computation should be carried out
  • Features:-
  • programmer creates a knowledge base containing a set of facts and rules to represent information, eg line 1 states that there is a direct flight from Glasgow to London

  • uses rules, eg line 6 or 7:-
  • uses capital letter to identify variables to allow for instantiation (so that values can be returned)
  • adds information based on other facts or rules
  • reduces need for repetition of facts / rules or improves efficiency by reducing code
  • facilitates queries
  • uses queries to interrogate the knowledge base
  • has an in-built search algorithm to pattern match/resolve queries
  • can edit their knowledge base (such as adding new facts) - self modifying code - which means they can “learn” from user interaction
  • uses recursion - when a rule calls itself over and over again until a simple base fact is identified e.g. the rules about ancestry:-


  • Examples:- PROLOG, Lisp

Description of object oriented languages

  • programs are designed round objects rather than sequences of instructions
  • Programs consist of items called classes
  • A class has a list of attributes and a list of methods
  • Each class can be used as the blueprint to create an object, for example the code in a class called Square could describe the attributes and methods of a square, and each square the program uses would be created as an object
  • Encapsulation - Objects are created within a class and will contain code and the data that the code requires i.e. data and code is not held separately
  • The design of the object determines which attributes and methods can be called from other parts of the program.
  • Inheritance –
  • Creating a subclass from an existing class i.e. each class can be used as the base code for another class, and the programmer can add on new attributes and methods
  • E.g. the Shape class could have two subclasses called Square and Triangle

Computational constructs

You should be able to describe, implement and exemplify these computational constructs.

Parameter passing (value and reference, formal and actual)

  • Parameters are items of data that can be passed between subprograms
  • Passing a parameter by value –
  • a copy of the variable is passed into a subprogram and used
  • the original variable is not changed
  • the copy is destroyed when the subprogram is finished execution
  • Passing a parameter by reference -
  • a reference (address in memory) of a variable is passed into a subprogram
  • the subprogram can change the original variable
  • Formal and actual parameters –
  • the name of a parameter used when the subprogram is called can be different from its name inside the subprogram so :-
  • subprograms can be re-used with different parameters
  • subprograms from module libraries need not be edited
  • different peoplecan write subprograms that work together
  • Actual parameter – the parameter when the subprogram is called
  • Formal parameter- the parameter within a subprogram

The scope of local and global variables

  • Local variables -
  • declared within a subprogram
  • can only be used by lines within the subprogram
  • only exist while the subprogram is being executed
  • Global variables –
  • declared outside of subprograms
  • accessible from any part of the program
  • exists throughout the execution of the entire program
  • dangerous for programmers as can be “seen” by the whole program and its name, e.g. total, may “overlap” with a variable elsewhere and cause confusion
  • Scope — the lines of the program in which a variable may be used
  • How to limit the scope of a variable :-
  • create a local variable that is declared inside a procedure/module ... or ...
  • create a formal parameter which is useable inside a procedure/module

Sub-programs/routines, defined by their name and arguments (inputs and outputs), including functions andprocedures

  • Subprogram -
  • a block of code (functions/procedures) in a program that carries out a particular task
  • can be re-used within a program or in another program to avoid code duplication
  • a module library contains subprograms that have been designed, coded and tested and are available to use in new programs to save development time
  • Function:-
  • a subprogram that returns a value i.e. one item of data
  • parameters are passed into the function to provide data to work on
  • pre-defined functions –
  • built into the programming language
  • already tested so the user knows that they work
  • User-defined functions –
  • Designed, written and tested by the programmer
  • Procedure:-
  • a block of code that can output no values, one value or many values
  • can use parameters to pass data in and/or out
  • Difference between a function and a procedure –
  • function - subprogram that outputs one value
  • procedure -subprogram that may output no values, one value or many values

Data types and structures

You should be able to describe, exemplify and implement these data types and structures

String

  • Represents text i.e. stores characters
  • Includes - lower case letters,UPPER CASE LETTERS, punctuation, alpha numeric data
  • Pre-defined string functions
  • Substring– extract part of a string to form a substring e.g.
  • mid$(forename, 1, 3), left$(forename,2)
  • right$(forename,3)
  • Ucase, Lcase, Asc, chr$
  • Concatenation – Joining strings together
  • E.g. forename = “Katie”
  • surname = “Forbes”
  • fullname = forename & surname fullname containsKatieForbes

Numeric

  • Integer:-
  • positive binary number stored using binary
  • positive and negative number stored using two’s complement
  • Real:-
  • number with a fractional part (or decimal place)
  • stored using a simple data type called a “floating point number
  • Floating point numbers can also use an extra bit called a signed bit to indicate whether a number is positive or negative

Boolean

  • a simple data type that is stored as either True or False

1-D Array (1 dimensional array)

  • Data structure containing values of the same type
  • when declaring an array the programmer defines -
  • the name of the array
  • the number of elements to be held in the array
  • a data type for the array
  • each individual element in the array can be accessed by using an index
  • Passed by reference to avoid duplication of array in memory
  • Advantages of array:-
  • multiple values can be created by one line inside a loop
  • each item can be accessed using a loop structure
  • makes code efficient (few lines)
  • Example using an array:-


Record

  • a data structure that contains a group of values of different types

  • a record structure must be defined e.g. a record of type Member could consist of a surname (string), forename (string), username (string) and password (integer)
  • Array of records – used to store multiple records within the same structure

Sequential files (open, create, read, write, close)

  • Programs can read/write data from files to suitable data structures (1-D array, record, arrays of records)
  • Operations include open, create, read, write and close
  • The process to open a file is the same in almost every programming language:-

Open a file

For each line in the file:

Read line from file

Close file

  • Programs can also write data to files:-

Open a file (create if file doesn’t exist)

For each item to be written to a file:

Write line to file

Close file

  • Multiple items can be read from each line, or written to one line of a file
  • Most files separate items using a comma (a Comma Separated Value file)

Testing and documenting solutions

Description and implementation of constructing a comprehensive a test plan

  • reasons for testing:-
  • to identify errors
  • to ensure that software is fit for purpose – does what the software specification said it should

Systematic testing:-

  • a test plan is created before testing begins
  • some of the plan may be created as early as the analysis stage
  • test plan contains –
  • complete and well chosen test data that is to be used
  • expected results
  • actual results
  • a comparison of the expected and actual results
  • test plan is followed in a logical order
  • involves testing of subprograms modules (subprograms) individually then together

Comprehensive testing

  • ensures that testing is as thorough as possible - tests every part of the program
  • set of test data should include:-
  • data in range (normal)
  • boundary data(extreme)
  • out of range data (exceptional)
  • covers every part of the program:-
  • test individual modules independently
  • test that the modules work together
  • carry out acceptance/beta/field testing
  • use an independent test group

Description and identification of syntax, execution and logic errors

  • Syntax error :-
  • is spotted by a translatorand causes the program not to translate
  • a line in a program is incorrectly formed e.g. -
  • error in a reserved word or variable name
  • missing symbols e.g. ( = “
  • missing keywords e.g. END IF
  • Execution error (run-time error):-
  • causes a program to crash/stop responding when the program is asked to do something that it cannot
  • includes e.g. –
  • a number outside the possible range of numbers in the HHL
  • dividing by zero
  • truncation error– calculation errors when anumber loses precision
  • out of bounds error–e.g. trying to access a position in an array that does not exist
  • file errors – e.g. using an incorrect path to file
  • Logic error:-
  • caused by the programmer making an error when writing the program
  • program runsto completion but does not produce the expected output
  • usually resolved by carrying out a dry run, using a trace table or setting breakpoints to identify the section of code that contains the logic error
  • common causes of logic errors –
  • incorrect formula e.g. SET factor TO counter * counter instead of SET factor TO counter * factor
  • incorrect use of conditions in IF statements
  • wrong algorithm

Description and exemplification of testing techniques (tools used when testing)

Dry run :-

  • paper-based analysis of code
  • a programmer-
  • looks at the program on the screen or a print out
  • uses a pen and paper and executes the program line by line in their head
  • notes down the changes to values of each variable in a trace table
  • checks that the variables are used and updated as expected
  • helps to find logic and execution errors
  • carried out during design, implementation, testing or maintenance
  • Trace table/tools :-
  • table of values showing the contents of several variables as each line stepped through
  • Breakpoint :-
  • pre-defined points that are set in a program that allows the execution of code to be stopped so the programmer can examine the values stored in variables at that time
  • Watchpoint:-
  • a special breakpoint that stops your program when the value of an expression changes

Note:-When debugging large programs :-

  • a trace table may be used to find out which value is not as it should be
  • the programmer can then set breakpoints to stop/pause program at defined points
  • the values of the variables are compared with the expected value in the trace table to see if they match

Algorithm specification

You should be able to nalyse, describe, exemplify and implement these standard algorithms and analyse other algorithms of similar complexity.

Linear search

  • checks an array for the presence of a particular item of data
  • the user is asked what they are searching for (a target)
  • each item in the array is compared to the target, and if the item is found, a message is displayed


This algorithm searches until the target is found or the entire array has been checked (used when the target will only appear once in the array e.g. to find a particular pupil):-


This algorithm searches through the entire array and displays a message each time the target is found (used when the target may appear more than once in the array)

Find the minimum

  • finds the smallest number in an array
  • a variable (e.g. called minimum) is used to store the smallest number (initially this is set to the first item in the array)

  • each number in the array is compared to this minimum, and if the number in the array is smaller than the minimum, then the minimum will be set to this new number

Find the maximum

  • finds the largest number in an array
  • a variable (e.g. called maximum) is used to store the largest number (initially this is set to the first item in the array)
  • each number in the array is compared to this maximum, and if the number in the array is larger than the maximum, then the maximum will be set to this new number


Example (from old exam) of finding minimum and maximum mark

Count occurrences

  • checks an array for the presence of a particular item of data and adds to a counter each time it is found
  • the user must be asked what they are searching for (a target)
  • a variable storing the number of times the item is found is set to zero
  • each item in the array will be compared to the target, and if the item matches the target then the total will be updated by one


Count occurrences - Example in scenario

The program must find how many of the 1000 readings are above zero and less than ten degrees.

Use pseudocodeto write an algorithm which would determine the number of readings in this range.


Low-level operations and computer architecture

Description of the uses of virtual machines

  • software that allows a computer to run a virtual Operating System (while using its own operating system)
  • reasons to use a virtual machine :-
  • to access an older operating system
  • to access open source operating systems such as Linux
  • for sandboxing :–
  • lets software be tested while protecting the computer from being accessed by the software directly(safer)
  • useful when deliberately running malicious software to determine its purpose and methods
  • used with Java, Python, JavaScript – so they run on various computers
  • to use a virtual server –
  • one physical server can house several virtual servers instead of having several different servers carrying out different tasks
  • reduces cost of hardware as only one machine is needed to perform a range of tasks

Description of the uses of emulators

  • similar to a virtual machine but this software simulates a different platform i.e. its hardware (processor and perhaps input devices)) and software (operating system)
  • reasons to use an emulator:-
  • to let a computer run machine code for a different processor than the one in the computer
  • useful when testing software for a different processor e.g. -
  • to test Android or iOS applications (running on ARM processors) on Intel computers (PC’s)
  • to run games for older games consoles, handheld gaming devices or arcade games

Use of binary to represent negative integers using two’s complement