software design and development –higher · web viewexamples:- prolog, lisp. description of. ......

33
L Forbes Lesmahagow High School Software Design and Development –Higher Computing Science

Upload: trinhkhue

Post on 07-May-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

L Forbes

Lesmahagow High School

Software Design and Development –Higher Computing Science

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:-

o moving/setting/loading register valueso addition/subtraction between registers, values and/or memoryo accessing memory locations

an instruction has two parts - opcode and operand(s) e.g.o 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:-o 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

o 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:-o Optimisation of code – LLL programs use less RAM than high-level languageso Machine code program in binary does not require a translator to be in RAMo Greater control of hardware features than high-level languages (e.g. in small

embedded computers such as home appliances)

2

Languages and Environments

2017

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:-

o 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

3

Languages and Environments

2017

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:-

o 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

o 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

o uses queries to interrogate the knowledge baseo has an in-built search algorithm to pattern match/resolve querieso can edit their knowledge base (such as adding new facts) - self modifying

code - which means they can “learn” from user interactiono 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

4

ancestor_of(X,Y):- parent_of(X,Z), ancestor_of(Z,Y)ancestor_of(X,Y):- parent_of(X,Y)

Languages and Environments

direct(glasgow, london).direct(london, paris).direct(paris, rome).direct(paris, seville).direct(rome, berlin).

fly_direct(P,Q) :- direct(P, Q).one_stop(X, Y) :- fly_direct(X, Z), fly_direct(Z, Y).

2017

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 – o 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

o E.g. the Shape class could have two subclasses called Square and Triangle

5

Languages and Environments

2017

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 –

o a copy of the variable is passed into a subprogram and usedo the original variable is not changedo the copy is destroyed when the subprogram is finished execution

Passing a parameter by reference - o a reference (address in memory) of a variable is passed into a subprogramo the subprogram can change the original variable

Formal and actual parameters –o 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 people can write subprograms that work together

o Actual parameter – the parameter when the subprogram is calledo Formal parameter- the parameter within a subprogram

6

Example of the pseudocode for a function call to show an actual parameter:-SET permutations TO combinations(items)

Example of the pseudocode for a function to show a formal parameter:-FUNCTION combinations (INTEGER number) RETURNS INTEGER

SET factor TO 1FOR counter FROM 1 TO number DO

SET factor TO counter * factorEND FORRETURN factor

END FUNCTIONThe formal parameter in this example is number. The actual parameter is items which contains the value to be used in the function which is passed to the formal parameter number.

Computational Constructs

You should be able to:-o Use parameter passing including passing by value and by referenceo explain the terms formal and actual parameter in the context of a program

2017

The scope of local and global variables

Local variables - o declared within a subprogramo can only be used by lines within the subprogramo only exist while the subprogram is being executed

Global variables – o declared outside of subprogramso accessible from any part of the program o exists throughout the execution of the entire programo 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 :-

o create a local variable that is declared inside a procedure/module ... or ...o 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 and procedures

Subprogram - o a block of code (functions/procedures) in a program that carries out a particular tasko can be re-used within a program or in another program to avoid code duplicationo 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:-

o a subprogram that returns a value i.e. one item of datao parameters are passed into the function to provide data to work ono pre-defined functions –

built into the programming language already tested so the user knows that they work

o User-defined functions – Designed, written and tested by the programmer

Procedure:-o a block of code that can output no values, one value or many valueso can use parameters to pass data in and/or out

Difference between a function and a procedure – o function - subprogram that outputs one value o procedure - subprogram that may output no values, one value or many values

7

You should:- know the definition of local and global variables be able to read a short program and identify the scope of given variables be able to use local and global variables in program code

Computational Constructs

2017

8

2017

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

o Substring – extract part of a string to form a substring e.g. mid$(forename, 1, 3), left$(forename,2) right$(forename,3)

o Ucase, Lcase, Asc, chr$ Concatenation – Joining strings together

o E.g. forename = “Katie” o surname = “Forbes” o fullname = forename & surname fullname contains KatieForbes

Numeric Integer:-

o positive binary number stored using binary o positive and negative number stored using two’s complement

Real:-o number with a fractional part (or decimal place)o stored using a simple data type called a “floating point number”o 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 -

o the name of the arrayo the number of elements to be held in the

arrayo 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:-

o multiple values can be created by one line inside a loop

9

Data Types and Structures

2017

o each item can be accessed using a loop structureo makes code efficient (few lines)o 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 fileFor each line in the file: Read line from fileClose 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 fileClose 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)

10

Data Types and Structures

Line1. SET source TO [71, 76, 66, 67, 89, 72]2. SET position TO 13. FOR counter FROM 2 TO 64. IF source[counter] > source[position] THEN5. SET counter TO position6. END IF7. END FOR

Record memberData IS {STRING surname, STRING forename, STRING username, INTEGER password}

DECLARE members[1000] As MemberData

2017

11

2017

Testing and documenting solutions

Description and implementation of constructing a comprehensive a test plan

reasons for testing:-o to identify errorso to ensure that software is fit for purpose – does what the software specification said

it shouldSystematic 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 –

o complete and well chosen test data that is to be usedo expected resultso actual resultso 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:-

o data in range (normal)o boundary data(extreme) o out of range data (exceptional)

covers every part of the program:-o test individual modules independentlyo test that the modules work together

carry out acceptance/beta/field testing use an independent test group

12

Testing and Documenting Solutions

2017

Description and identification of syntax, execution and logic errors

Syntax error :-o is spotted by a translator and causes the program not to translateo 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) :-o causes a program to crash/stop responding when the program is asked to do

something that it cannoto includes e.g. –

a number outside the possible range of numbers in the HHL dividing by zero truncation error – calculation errors when a number 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 :- o caused by the programmer making an error when

writing the programo program runs to completion but does not produce the

expected outputo 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

o 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

13

Testing and Documenting Solutions

2017

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

Dry run :-o paper-based analysis of code

o a programmer-

1. looks at the program on the screen or a print out2. uses a pen and paper and executes the program line by line in their

head3. notes down the changes to values of each variable in a trace table4. checks that the variables are used and updated as expected

o helps to find logic and execution errorso carried out during design, implementation, testing or maintenance

Trace table/tools :-o table of values showing the contents of

several variables as each line stepped through

Breakpoint :-o 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:-o 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

14

Testing and Documenting Solutions

2017

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 displayedThis 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)

15

Line 1 SET found TO FALSELine 2 SET index TO 0Line 3 RECEIVE target FROM KEYBOARDLine 4 REPEATLine 5 IF target = array[index] THENLine 6 SET found TO TRUE Line 7 SEND target & " found at position " & index TO DISPLAYLine 8 ELSELine 9 SET index TO index + 1Line 10 END IFLine 11 UNTIL index = 10 OR found = TRUELine 12 IF found = FALSE THENLine 13 SEND “The program did not find a match for “ & target & “ within the array.” TO DISPLAYLine 14 END IF

Line 1 RECEIVE target FROM KEYBOARDLine 2 SET found TO falseLine 3 FOR index FROM 0 TO end of arrayLine 4 IF array(index) = target THEN Line 5 SET found TO trueLine 6 SEND target & “found at location ” & index TO DISPLAYLine 7 END IFLine 8 END LOOPLine 9 IF NOT found THEN Line 10 SEND not found message TO DISPLAYLine 11 END IF

Algorithm Specification

2017

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

16

Line 1 SET maximum TO array [0]Line 2 FOR index FROM 1 TO 9 DOLine 3 IF array[index] > maximum THENLine 4 SET maximum TO array[index]Line 5 END IFLine 6 END FOR Line 7 SEND "The maximum value was " & maximum TO DISPLAY

Line 1 SET minimum TO array [0]Line 2 FOR index FROM 1 TO 9 DOLine 3 IF array[index] ˂ minimum THENLine 4 SET minimum TO array[index]Line 5 END IFLine 6 END FORLine 7 SEND "The minimum value was ” & minimum TO DISPLAY

LINE 1 SET min TO first value in mark arrayLINE 2 SET max TO first value in mark arrayLINE 3 FOR index FROM 1 TO end of arrayLINE 4 IF mark(index) > max THENLINE 5 SET max TO mark(index)LINE 6 END IFLINE 7 IF mark(index) < min THENLINE8 SET min TO mark(index)LINE 9 END IFLINE 10 END FOR

Algorithm Specification

2017

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 scenarioThe program must find how many of the 1000 readings are above zero and less than ten degrees.

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

17

Line 1 SET counter TO 0Line 2 RECEIVE target FROM KEYBOARDLine 3 FOR index FROM 0 TO 9 DOLine 4 IF array [index] = targetLine 5 SET counter TO counter + 1Line 6 END IFLine 7 END FORLine 8 SEND "There were " & counter & " occurrences of " & target TO DISPLAY

Line 1 SET counter TO 0 Line 2 FOR index FROM 1 TO 1000 timesLine 3 IF temp(index) > 0 AND temp(index) <10 THEN Line 4 SET counter TO counter +1Line 5 END IFLine 6 END FORLine 7 SEND “Out of 1000 readings there were “ & counter & “readings that were above zero and less than 10 degrees” TO DISPLAY

Algorithm Specification

2017

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 :-o to access an older operating system o to access open source operating systems such as Linux o 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

o 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:-o to let a computer run machine code for a different processor than the one in the

computero 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)

o to run games for older games consoles, handheld gaming devices or arcade games

18

Low-level Operations and Computer Architecture

2017

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

Description:- used when positive or negative numbers are to be stored uses the leftmost column to represent the sign of the number (0 for positive and 1 for

negative) to write the two’s complement for a negative number (positive numbers are “normal”) –

o write the positive version of the numbero from the right hand side, copy until you copy a 1 then flip the rest of the bits

Examples:-

What is the 8 bit two’s complement representation of the number –72?Column headings sign 64 32 16 8 4 2 1Write 72 in binary with 0 at the start to indicate +ve 0 1 0 0 1 0 0 0Write -72 1 0 1 1 1 0 0 0

What is the decimal representation of the 8 bit two’s complement number 10110110?

Column headings sign

64 32 16 8 4 2 1

Write binary number with 1 at start to indicate -ve 1 0 1 1 0 1 1 0Write -74 0 1 0 0 1 0 1 0

Range of numbers that can be represented using a fixed number of bits:-o Calculate the largest positive number using 2 number of bits-1 -1o Calculate the smallest negative number using -(2 number of bits-1)o How to calculate the range of number that can be represented using 8 bit twos

complement:- Largest positive number is 01111111 = 2 number of bits-1-1 = 127 Largest negative number is 10000000 = -(2 number of bits-1) = -128

19

Low-level Operations and Computer Architecture

2017

Description of the relationship between the range and precision of real numbers using floating point representation

a number with a fractional part stored using “floating point representation” stored as two parts:-

o the mantissa – the digits that are in the number number of bits determines the precision of the number

o the exponent – stores the location of the point number of bits determines the range of the number

May use an extra bit called a signed bit to indicate positive or negative If 32 bits re used for e.g. —0·000000016.

o Allocate 16 bits for the exponent and 16 bits for mantissa (1 mark)o Two’s complement for the mantissa would allow negative values o Two’s complement for the exponent to allow for small values

Description of Unicode used to represent characters and its advantage over ASCII

ASCII (from Nat 5):- American Standard Code for Information Interchange used as a standard character code by many computers for decades used by many computers so makes it possible to transfer data between computers 7 bit code used to represent characters (8th bit can be used for error checking) 27 i.e. 128 different characters Extended ACSII:-

o 8 bit code used to represent 28 i.e. 256 characterso Allows extra characters e.g. those with accents é

Description of Unicode: – Unicode is an international version of ASCII that includes characters used in

non-English alphabets Each character uses 16 bits rather than 8 - double the storage space of

ASCII characters. 65536 (216)possible characters

Advantage of UNICODE over ASCII:- greater range of possible characters so represents all character based alphabets

20

Low-level Operations and Computer Architecture

2017

Description of the advantages and dis-advantages of bit-mapped graphics compared to vector graphics

Bit-mapped graphic reminder- o stored as a grid of pixels where each pixel is represented by a binary number

to indicate colour of the pixelo File size is fixed

Vector graphics reminder -o stores a list of objects (shapes) and their attributes

(position, colour, line thickness etc) o image can be edited by altering the attributes

Advantages of bit-mapped compared to vector graphics:-o individual pixels can be editedo file size remains the same when more objects are added to image whereas

the file size of a vector graphic increases when more objects are addedo images can be realistic

Disadvantages of bit-mapped compared to vector graphics:-o fixed resolution so becomes pixelated when user zooms in whereas a vector

graphic is resolution independent - the graphic can be redrawn at any scale on the screen without becoming pixelated

o parts of the graphic can’t be moved without leaving a white gap whereas in vector graphics objects can be layered (in front or behind each other)

o operations such as resize, delete, move which are available in vector graphics cannot be easily used as only pixels can be edited

o file sizes tend to be large

Understand that sound is represented in binary and described in terms of sample size and sample rate

Sound wave captured by microphone, sampled (measured) and the measurements stored as binary numbers in a file

Quality affected by –o sample rate - number of times the wave is sampled

(measured) per secondo sample size - the number of bits that are used to represent

each measurement of the sound wave

Understand that video is represented as a sequence of still frames and described in terms, for each frame, of frame rate, resolution and bit depthFrame rate – number of frames per secondResolution – number of pixels in one frameBit depth – number of bits used to indicate the colour of each pixel

21

Low-level Operations and Computer Architecture

2017

Calculation of storage requirements for uncompressed audio and video

Audio file size = sample rate x sample size x number of seconds x number of channels

Video file size = number of pixels X bit depth X frame rate X duration (in seconds)

Describe the trends and implications of computer architecture including multi-core processors and parallel processing

multi-core processors and parallel processing processors allow several instructions to be executed simultaneously and improve computer performance e.g.

o quad-core processors can be used to improve load times for web apps containing client-side scripts or multimedia because -

specific tasks can be allocated to certain processors/core processors allowing simultaneous execution of scripts and different media

elements

Describe the fetch-execute cycle using the components of computer architecture including processor (registers, ALU, control unit) memory buses (data, address and control)

1. Transfer the contents of the Program Counter to Memory Address Register

2. Increment the Program Counter3. Activate Read line on the Control bus (thereby

transferring the instruction to the Memory Data Register via the Data bus)

4. Transfer contents of Memory Data Register to the Instruction Register ready for decoding

5. Control unit decodes and executes the instruction which may require the Arithmetic and Logic unit to do a calculation or make decisions

The execute step might involve carrying out a simple instruction e.g. to increment a register; an instruction to load data from a memory location and add it to the accumulator; or an instruction to place a new memory location into the program counter.

22

Low-level Operations and Computer Architecture