international diploma in computer studies - … programming - prolog zobject ... – the building...

347
V1.1 © NCC Education Limited, 2007 Introduction to Programming - 1.1 International Diploma in Computer Studies Session 1 Introduction to Programming Programming Methods

Upload: doanngoc

Post on 10-Apr-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.1

International Diploma in Computer Studies

Session 1Introduction to Programming

Programming Methods

Page 2: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.2

Contents

What is a programming language? How they have developed The language modelsWays to evaluate their differencesProgramming from a chronological viewpointAn introduction to object-oriented concepts

Page 3: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.3

What Is a Programming Language?

Allows human beings and computers to communicateComputer language consists of 1s and 0s

– the binary systemComputer programming languages enable humans to write in a form that is more compatible with a human system of communication

Page 4: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.4

Language ModelsImperative/procedural languages - C, Pascal, Fortran and AssemblyFunctional languages - LISP, 'pure' Scheme, FP, ML and HaskellLogic programming - PROLOG Object-oriented languages - Simula, Smalltalk-80, Eiffel, Java and Visual Basic 2005Declarative languagesScripting languagesParallel languages - C* and ADAAssembly languages – FAB, D and MASMMultiparadigm languages – ActionScript, Python, CurryNon-English based programming languages – Chinese Basic, HPL(Hebrew), var’aq(Klingon) and Lexico(Spanish)

Page 5: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.5

Evaluating Languages

How readable is the language, to humans?How easy is it to write the program in this particular language? How reliable is the language? What is the cost of developing the program in this language? How complicated is the syntax going to be?Does the language have standards?

Page 6: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.6

Chronology of Programming

AbacusDevelopments in programming have also been dependent on the computer hardware Mainframe computersPersonal computers Networks

Page 7: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.7

The Language Generations

1st: Machine language2nd: Symbolic instructions and addresses3rd: Structured programming, database management systems4th : Non-procedural

– they concentrate on what you want to do rather than how you are going to do it

5th: Artificial Intelligence and Fuzzy Logic– natural language (making the computer appear to

communicate like a human being)

Page 8: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.8

Introduction to Object-Oriented Concepts

A system can be constructed from a set of objectsAdding new capabilities to existing objects can expand a systemCreating new objects can expand a systemRe-use of objects

– reduces the development time

Page 9: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.9

What is an Object?

An object can be:– a physical thing in the ‘real world’– a representation of reality– a tangible or visible thing– a thing to which action or thought can be directed– passive - doing nothing until activated – active - continually monitoring until conditions change

An object is never:– a value (e.g. name)– a process (e.g. sort)– time (e.g. five minutes)

Page 10: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.10

Classes

An object is an instance, or example, of a category or class Software objects have state and behavioursThe object’s state is made up of items of data called attributes (or properties)Classes can be used as a template for creating other objects The class can be thought of as a mould for producing new objects

Page 11: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.11

Classification

Looks at the shared attributes and behaviours to create or describe classes of objects

Classes are defined by specifying data or attributes and behaviour (operations or methods)

Class variables and instance variables

Abstract class and concrete class

Page 12: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.12

Classification

Reptiles Class

Colour

Size

Laying eggs

Rearing young

Data

Responsibilities

Page 13: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.13

Encapsulation and Abstraction

Encapsulation (black box technology) – shields the user from its mechanics or technological

workings– reduces the potential for error– interface, communicating with the outside world

Abstraction – enables the developer to re-use a class and filter out

operations and attributes from that class which are superfluous to needs

Page 14: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.14

Messages and Operations

Methods – data traditionally has things DONE to it, whereas an

object can DO things

Messages – when an object receives a message from another

object, it activates a method or operation – also called requests or function calls

Page 15: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.15

Relationships – Inheritance

An object can inherit from its class, and a class may also inherit from another classSuperclassesSubclasses

Page 16: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.16

Relationships – Association

Object relationships can either be one-way or two-wayObjects can also have relationships 1:1 or 1:manyMultiplicity

– indicates the number of objects that are associated with one particular class

Page 17: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.17

Polymorphism

Operations can have the same name even though they are associated with different objects Polymorphism allows developers to re-use terminology and allows it to have more than one meaning Each object understands how it is supposed to perform an operation even though it may have the same name as another object’s operation

Page 18: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Introduction to Programming - 1.18

Summary

Introduction to programmingA chronology of programmingThe idea of language generationsAn introduction to structured programmingAn introduction to object-oriented concepts

– classes– encapsulation and information hiding– messages and operations– relationships– polymorphism

Page 19: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.1

International Diploma in Computer Studies

Session 2Variables, Control Structures and Calculations

Programming Methods

Page 20: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.2

ContentsVariables and simple data typesOrder of precedenceControl structures

– sequence– selection– loops

PseudocodeDiagrams and charting

Page 21: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.3

Programming Languages

Every programming language has rules which must be followedWe can relate a programming language to the English language

– the building blocks are not nouns and verbs but reserved words and keywords which have a special meaning in programming languages

reserved words are unique to a program and cannot be used as identifiers, e.g. IF, REPEATkeywords are identifiers which indicate a specific command, e.g. PRINT, INPUT

Page 22: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.4

Definitions – 1

Syntax (syntax rules)– the rules defining the legal sequences of symbolic elements in a language– syntax rules define the form of the various constructs in the language, but

say nothing about the meaning of those constructs

Language constructs– a syntactic structure or set of structures in a language to express a particular

class of operations. – often used as a synonym for control structure

Pseudocode/pseudolanguage– used to provide an outline description of the specification for a software

module– contain a mixture of natural language expressions embedded in syntactic

structures taken from programming language (such as IF … THEN …ELSE) – not intended to be executed by computer, must be interpreted by people

Page 23: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.5

Solution in the Form of a Diagramstart

calculatethe sum

input the numbers

print theanswer

end

Page 24: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.6

Example Pseudocode – 1

BeginACCEPT number1, number2, number3Sum:=number1 + number2 + number3PRINT sum

End program

Page 25: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.7

Variables

Variables are used to store data in the computer’s memory (RAM)Three attributes

– the address in the memory where the data is stored– the actual data stored– the name of the variable or identifier

Limitations on the namesIdentifiers are usually written as text

– differences in programming languages as to the use of additional characters

Page 26: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.8

Definitions – 2

Variable– a unit of storage that can be modified during program execution, usually by

assignment or read operations– generally denoted by an identifier or by a name

Identifier– a string of characters used to identify some element of a program– the kind of element that can be named depends on the programming

language

Assignment statement– a fundamental statement of all programming languages (except declarative

languages) that assigns a new value to a variable

Name– a notation for indicating an entity in a program or system– generally a name must be a simple identifier, usually a textual string; in more

advanced languages, it may be composed from several elementary components according to the rule of the language

Page 27: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.9

Compiler/Interpreter

The compiler or interpreter needs to know what type of data is being used

– it will have a different way of dealing with whole numbers, fractional numbers and characters

The type of data being used influences the program designCompiler

– a program that translates high-level language into absolute code, or sometimes into assembly language

Interpreter– a language processor that analyses a line of code and then

carries out the specified action, rather than producing a machine-code translation to be executed later

Page 28: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.10

Variable Types – 1

Integer – whole numbers (e.g. 1, 678, 45) Real or float – fractional numbers (e.g. 3.678, 789.3)Character – letters (e.g. a,f,z,4 )String – names (e.g. Dr. H. Kelly )Boolean – FALSE or TRUE, 0 OR 1

Page 29: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.11

Variable Types – 2

English postal codes contain letters, numbers and a space, which the computer treats as a blank character, e.g. SW1A 2AJ

– the computer would use this data as a string because it contains a blank character

Numbers are only declared as integer or real if they are to be used in calculationsMany programming languages insist on a variables definition at the beginning of the program

– emphasises the importance of data in deciding the structure of the program

– good practice to identify the variables used and the types in the pseudocodedescribe any printed or displayed output, rather than just printing a number

Page 30: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.12

Example Pseudocode – 2

Use variables: number1, number2, number3, sum OF TYPE IntegerDISPLAY “Enter three numbers”ACCEPT number1, number2, number3sum:= number1 + number2 + number3PRINT “The sum is ” sum

end program

Page 31: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.13

Variable – 3

Although variables are used to hold data which can change throughout the program, the data stored is always under the control of the program Some variables may have data entered at the beginning of the program which stays the same throughout the running of the program (e.g. tax rate)

– the program code would have to be changed if the tax rate changed

Data items which have the same value throughout the program are termed constants

– as with variables, the computer needs a name for each constant and to know its data type so that it can be manipulated as required

Constants and variables obey the same rules – can be compared or used in arithmetic expressions, provided they are of the

same data type or of compatible types for the specific operation, e.g. integer and floating point

Page 32: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.14

Definitions – 3

Constant– a quantity or data item whose value does not change.– a value that is determined by its denotation, i.e. a literal

Literal– a word or symbol in a program that stands for itself

rather than as a name for something else, i.e. an object whose value is determined by its denotation

– numbers are literals– if other symbols are used as literals, it is necessary to

use some form of quoting mechanism to distinguish them from variables

Page 33: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.15

The Order of PrecedenceComputer languages provide a range of operators for arithmetic, + meaning add, – meaning subtract, * meaning multiply, / meaning divideThe order in which a calculation is evaluated is very important since the end result can differ according to which operation is given precedencea:= 4 + 3*2 could be worked out in two different orders

– Add the 4 to the 3 and then multiply the result by 24+3=7 7*2=14

– Multiply the 3 by the 2 and then add 4 to the result3*2=6 6+4=10

Page 34: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.16

Order of Precedence Rules

Do operations in brackets firstThen evaluate any exponentiation (e.g. finding the cube of a number, work out 6 to the power of 4)Then any division or multiplication operationLastly, addition and subtractionBODMAS

– Bracket– Of– Division– Multiplication– Addition – Subtraction

Page 35: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.17

Control Structure

Three main types of instructions are used in programming

– sequence– selection– loops

Control structure – definition – a syntactic form in a language to express flow of

control– common control structures are

IF … THEN … ELSE, WHILE … DO, REPEAT … UNTIL, CASE

Page 36: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.18

Control Structure – Sequence

Very important that the instructions are in the right order The computer will obey the instructions implicitly in the order in which they are written

Page 37: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.19

Control Structure – Selection

Many occasions where a program is required to include a range of alternative actionsExample:

– imagine a program in which one number (a constant) is divided by another (a variable)

– the contents of the variable can change throughout the program and it is possible that the variable contains a zero

– as it is not possible to divide by zero, the calculation should not be performed on this data

– therefore this condition has to be tested forinstruct the computer, “if a zero is entered then print ‘invalid entry’, and do not do the division calculation”

This can be illustrated in the form of a flowchart

Page 38: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.20

Selection – Flowcharts

Used extensively by programmers before the advent of pseudocodeStill a useful tool to help programmers work out the logic of the sequence of instructions needed, particularly where conditions occur

– note that the results of the test are placed on the lines exiting from the decision box

– best to write the condition in a form where the two choices are yes or no (i.e. TRUE or FALSE), as this matches the IF … THEN … ELSE statement

Checking for dividing by zero

start

end

input the number

calculate100/number

number< 0

print the answer

Yes

print “invalid entry”

No

Page 39: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.21

Selection – Example 1

When we need to take action based on user choiceIn a menu of options, the user may input alternative choices

– in consequence, the program must act on these choices

M A I N M E N U

IN P U T N E W O R D E R S

A M E N D O R D E R S

U P D A T E O R D E R S

D IS P L A Y S T O C K

Page 40: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.22

IF Statement and Logical Operators

All computer languages provide some means of selection– usually, in the form of an IF statement

IF statement (together with logical operators) is used to test for true or falseIF a = b THEN PRINT “a is equal to b” where the ‘=’ sign is the logical operator

– the action to be taken is preceded by the word THEN, and is only taken if the test result is true

The logical operators used in pseudocode are– = is equal to– >= is greater than or equal to– <= is less than or equal to– <> is not equal to

Page 41: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.23

Selection – Example 2

Choose one of the following:

m for multiply

a for add

s for subtract

a

Input the numbers you want to use:

34, 45

Page 42: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.24

Example – PseudocodeUse variables choice OF TYPE Character

answer, number1, number2 OF TYPE IntegerDISPLAY “Choose one of the following:”DISPLAY ”m for multiply”DISPLAY ”a for add”DISPLAY ”s for subtract”ACCEPT choiceDISPLAY ”Input the numbers you want to use”ACCEPT number1, number2IF choice = m

THEN answer:= number1 * number2ENDIFIF choice = a

THEN answer:= number1 + number2ENDIFIF choice = s

THEN answer:= number1 - number2ENDIFDISPLAY answerend program

Note that these statements are indented. This indicates that theyare part of the IF…THENconstruct.

Page 43: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.25

The IF … THEN … ELSE Statement

In an IF statement, the instructions following the THEN part of the IF statement are executed if the condition is TRUEA more comprehensive set of conditions can be created by adding an ELSE statement The IF … THEN … ELSE statement is used to deal with a situation such as

– “A person is paid at the top level for category 1 work, otherwise his pay is at normal rates.”

There is some processing to do when the expression is FALSE

– IF the work is category 1, THEN the pay rate is at the top level ELSE the pay rate is normal

IF work = cat1

THEN p_rate := “top”

ELSE p_rate := “normal”

ENDIF

Page 44: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.26

The CASE Statement

Use variables: category OF TYPE character insurance OF TYPE string

ACCEPT category DO CASE of category

CASE category = U PRINT Insurance := “not available”

CASE category = A PRINT Insurance := “double”

CASE category = B PRINT insurance := “normal”

CASE category = M PRINT Insurance := “medically dependent”

OTHERWISE PRINT “entry is invalid”ENDCASE

end of program

Note that the last alternative statement in the CASE statement is OTHERWISE . This statement will be executed if noother case has been selected as TRUE.

Some programming languages, such as C,use fall-through CASE structures andserious errors can arise if theOTHERWISE case is not included.

You are advised to always include theOTHERWISE case in every CASEstatement.

A conditional control structure – allows a selection to be made between several sets of program statements

Page 45: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.27

Logical Operations

Conditions set in the IF .. THEN statements have been concerned with operands being equal

– but there are many occasions when the conditions to be tested need to be extended

AND, OR, NOT, NAND, NOR, XOR– for example, IF a > b AND a > c THEN display “a is the

largest”

Page 46: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.28

Logical Operations – Example The mark is a whole number between 1 and 100 Grades are awarded according to the following criteria:

>= 80 distinction, >= 60 and < 80 merit, >= 40 and < 60 pass, < 40 fail

Use variables: mark OF TYPE IntegerACCEPT markIF mark >= 80

THEN display “distinction”ENDIFIF mark >= 60 AND mark < 80

THEN display “merit”ENDIFIF mark >= 40 AND mark < 60

THEN display “pass”ENDIFIF mark < 40

THEN display “fail”ENDIF

end program

start

input the mark

distinction

mark>= 80

Yes

merit

mark>= 60

No

mark< 80

Yes Yes

No

Page 47: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.29

Loops

The power of a computer lies in its ability to do things, time and time again, very quickly, without becoming inaccurateThe sequence of instructions which is repeated is called a loop

– sometimes referred to as an iteration, but strictly speaking an iteration is more complex than a simple loop

Page 48: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.30

Example – Loop Read the payroll details for one employee

Process the data to calculate the pay

Write the new pay details to a file

print all the payslips from the file

Until nomore records

The instructions are in the form of a loop – will be repeated for every record on the payroll file

The loop will terminate when end-of-file is reached– the instruction after the loop will then be executed, e.g. the pay

slips would then be printed

Page 49: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.31

Iteration

An iteration is a repetition of a sequence of instructions

– the results from one pass of the loop are used as input to the instructions in the next pass of the loop

Example – if, during the running of the payroll loop, a running

total was kept of e.g. tax to be paid– each time through the loop, the tax for the current

employee would be added to the previous total– used as input in the following loop for the next

employee

Page 50: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.32

Elements of a Loop

Two main elements– a sequence of instructions to be performed each time the loop

is executed– an indication of when to finish executing the loop

Three constructs for loops in pseudocode– REPEAT UNTIL which tests at the end of a block of code, so

the sequence of instructions are always repeated at least once– WHILE which tests at the start of a block of code so it is

possible that the instructions in the loop may never be executed

– FOR loop which is controlled by a count given from known conditions

Page 51: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.33

REPEAT… UNTIL Loop

Use variables: number of type IntegerREPEAT

DISPLAY “Enter a number between 0 and 100”ACCEPT number

UNTIL number <0 or number > 100end program

Algorithm for only accepting a number between 1 and 100

Pseudocode:start

input the number

number< 0

number>100

No

Yes

No

end

display instructions

Yes

Page 52: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.34

REPEAT… UNTIL Example

Another common use is in selection from a menu of optionsExample – a survey carried out to discover the most popular sportResults will be typed into the computer for analysis

Use Variables: letter OF TYPEathletics, swimming, football, badminton OF TYPE Integer

REPEATDISPLAY “Type in the letter chosen or Q to finish”DISPLAY “A : Athletics”DISPLAY “S : Swimming”DISPLAY “F : Football”DISPLAY “D : Badminton”DISPLAY “Q : end data:”ACCEPT letterIF letter = ‘A’

THEN athletics := athletics + 1ENDIFIF letter = ‘S’

THEN swimming := swimming + 1ENDIFIF letter = ‘F’

THEN football := football + 1ENDIFIF letter = ‘B’

THEN badminton := badminton + 1ENDIF

UNTIL letter = ‘Q’DISPLAY “Athletics scored ” athletics “votes”DISPLAY “Swimming scored ” swimming “votes”DISPLAY “Football scored ” football “votes”DISPLAY “Badminton scored ” badminton “votes”

end of program

Page 53: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.35

WHILE Loop

WHILE (a true condition)STATEMENT or STATEMENT BLOCK concluded with

ENDWHILEUse variables: letter OF TYPE CharacterACCEPT “letter”WHILE letter <> ‘q’

DISPLAY “the character you typed is “, letterACCEPT letter

ENDWHILE

Page 54: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.36

FOR Loop

A FOR loop uses two values of a variable, the starting and the final condition for the actionThe variable is incremented on each iteration until it reaches the value identified as the final state

FOR (starting state, final state, increment)

Statement

Statement

ENDFOR

Page 55: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.37

FOR Loop Example Use variables: n, count OF TYPE Integer

sum, average, number OF TYPE Real DISPLAY “How many numbers do you want to input?” ACCEPT count

FOR (n:=1, n = count, +1) ACCEPT number sum := sum + number

ENDFOR average:= sum/count DISPLAY “The sum of the numbers was “, sum DISPLAY “The average of the numbers was”, average

end of program

sum := 0

start

input the count

n < =count

No

end

display instructions

Yes

input a number

add number to sum

average = sum/count

add +1 ton

Page 56: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Variables, Control Structures and Calculations - 2.38

Summary

Variable types and namesCalculations and order of precedenceControl structures

– sequence – selection– loops

the primary difference between the Do/While statement and the Repeat/Until statement, is the treatment of the loop exit condition the Do/While statement exits on false, the Repeat/Until statement exits on true

Page 57: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.1

International Diploma in Computer Studies

Session 3Data Analysis and Problems – 1

Programming Methods

Page 58: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.2

Contents

The software development processData structures and data structure diagramsOrganising informationFixed and variable records

Page 59: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.3

Program Development Process – 1

Many different types of programsA suite in a production control systemA simple database programA program to perform statistical analysis on experimental resultsA program to display the contents of a database via the web and process orders and paymentsAn interactive multimedia program, e.g. – an encyclopaedia (informative)– a game (user interaction)

Page 60: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.4

Program Development Process – 2

Before writing a program we need to knowThe output required by the user from the systemThe processes necessary to produce this output for the userThe data or input to be processed to create the output required

Page 61: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.5

Program Development Process – 3

ProgrammerResponsible for writing computer programs

Systems analystResponsible for the development of an information systemDesigns and modifies systems by turning user requirements into a set of functional specifications, which are the blueprint of the system

Systems analysisThe analysis of the role of a proposed system and the identification of a set of requirements that the system should meet – the starting point for systems design

Page 62: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.6

Program Specification

A formal description of a system, or a component or module of a system, intended as a basis for further development Characteristics of a good specification – unambiguous, complete, verifiable, consistent,

modifiable, traceable, and usable after development

Details of the specification will be discovered during the analysis and design stages of software development

Page 63: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.7

Software Lifecycle

The program development process is part of the software lifecycle, characterised by the following stages

Requirements analysisDesignCodingTestingImplementation and support

Page 64: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.8

Requirements Analysis Stage

An accurate and complete set of client and user requirements is produced to determine the characteristics of an acceptable solution

The requirements analysis specification will contain– the proposed system or solution, which has been

agreed by the client and developer– a list of existing tools, new tools required, facilities

and people available for developing the solution– a schedule for the next stages of the project, including

the deliverables for each stage

Page 65: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.9

Deliverables

Deliverables are the products of the different phases throughout the development process Provided for the client by the developer, as evidence that progress is being made according to requirements – may be written documents and diagrams produced

during the analysis and design phases, sample screen layouts or sample reports

Page 66: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.10

Requirements Analysis – Objective

To define, in detail, a solution that will fully meet the client and user requirements (programme specification)The program specification will include a description of the– inputs to the process– operations the system performs for each input– output obtained for the corresponding input

If there is more than one program in the system, the document is called a system specification

Page 67: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.11

Design Stage

How the solution will be built to satisfy the requirementsComplex problems are divided into a set of sub-problems Programs and modules are defined – inputs, outputs, functions and processes The use of formal program design techniques and programming standards are recommendedThe most appropriate programming language will have been decided upon during the development of the design

Page 68: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.12

Coding Stage

Produce the programs that will make up the systemComplete when all code is written and documented, and compiles without any errors

Page 69: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.13

Testing StageEvery program module needs to be tested according to the test plan developed in the design phase

– can be carried out whilst program is being developed

When the program is completed and all separate modules have been tested, a full test of the program is performed

– any errors in the program will be corrected and the test repeated

If testing identifies changes required to the program design– analysis, design, coding and testing phases are repeated for the changes

Systems test – programs are tested as a group The system must be tested in all environmentsAlpha test (test of the finished application completed internally) Beta test (tested externally)Simulation (used when live environment test is not possible, e.g. nuclear reactor control)

Page 70: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.14

Implementation and Support

When all the previous stages have been completed satisfactorily, the system is ready for implementationUser documentation or operating instructions may be requiredAfter installation it must be maintained according to the needs of the usersIf needs change and the amendments required are substantial, then the software lifecycle would be applied to the amendments

Page 71: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.15

Lifecycle – Definition The complete lifetime of a software system from initial conception through to final obsolescence

– the term is most commonly used in contexts where programs are expected to have a fairly long useful life

Traditionally, a lifecycle is modelled as a number of successive phases

– user requirements– system requirements– software requirements– overall design– detailed design– component production– component testing– integration and system testing– acceptance testing and release– operation and maintenance

Page 72: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.16

Data Structure DiagramsData structure – a way of describing the relationship of the component parts to the whole Technique

– a rectangle containing a * means an iteration of all lower levelboxes

– a box containing a small circle represents a choice between alternative sets of data (a selection)

Iteration(repetition)

Selection

o*

Page 73: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.17

Structure Diagram – Example 1 Module

Student

Result Details

*

Results

First Name

Student ID Name

*

Second Name

Assignment Exam

Page 74: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.18

Structure Diagram – Example 2Pack ofCards

Redo

Blacko

DiamondSuit

HeartSuit

SpadeSuit

ClubSuit

DiamondCard

HeartCard

SpadeCard

ClubCard

* * * *

o o o o

Page 75: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.19

Structure Diagram – Example 3

Pawns

*

Bishops

*

Castles

*

Knights

*

Queen King

Pawn Bishop Castle Knight

Chess Set

White Set Black Seto o

o o o o o o

Page 76: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.20

Organising Information

A file is composed of recordsEach record contains data organised in a defined structureThe components of this structure are called fields

Results File

Record Details

Name Modules Student ID second

name first

name 1st core module number

and results 1st optional module number and results

12345 Powell Sandra C1 34 46 O2 45 0

23456 James Jenny C1 36 22 O3 46 50

Page 77: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.21

Data Structure DiagramResults

Student

Student ID Name

FirstName

*

SecondName

ModuleNumber

*

Moduleresults

*

ResultDetails

Assessmentmark

Modules

Page 78: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.22

Record Structures

The fields in a record must be carefully designed to contain all the data that may need to be referenced for producing information

– this task would be performed in conjunction with the client and the result would form part of the program specification

Data Records (called File body in diagrams)

record 1 ………………… record n

Page 79: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.23

General File StructureFile

Record*

Fields*

Field nField 1Block ofFields Field n-1

Field a Field b

Page 80: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.24

Fixed Length Records

Number of characters allowed in each record can be predetermined

Field Name Size (in characters)

Employee Number 5

Surname 20

Initials 5

First name 15

Page 81: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.25

Variable Length Records

Sometimes records in a file store variable amounts of dataIt is not sensible to allow spare capacity in the field lengths – this would be highly inefficient use of the backing store – the more complex processing requirements needed to

deal with variable length records may be justified– it is the responsibility of the design team to ensure

that the processing/storage trade-off is sensibly chosen

Page 82: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 1 - 3.26

Summary

Program development processStructure diagramsOrganising informationFixed and variable length records

Page 83: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.1

International Diploma in Computer Studies

Session 4Data Analysis and Problems – 2

Programming Methods

Page 84: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.2

Contents

Analysing problemsDesigning a top-down modular programDetermining the structure of a programme from a given specificationStructured programming diagramsCRC Cards

Page 85: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.3

Analysing the Problem

Insist on a proper program specificationAnalyse the problemBreak the problem down

Main Problem

Step 1Sub Problems

Step 2FurtherRefinements

Page 86: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.4

Designing a Top-down Modular Program

One module contains instructions that supply the top-down logic for the whole programThis module controls three basic functions:

– initialising – processing – closing down the program

Page 87: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.5

Example Initialisation Routines

Requesting library routinesOpening fileDefining headings, creating opening screenInitialising variables

Page 88: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.6

Example Processing Tasks

Input– reading records from a file– requesting data from the user

Computation and logic– comparing values – computations– assignments

Output– updating files– writing records to a file– printing a report– displaying information on screen

Page 89: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.7

Example Closing Tasks

Producing printed outputWriting a filePrinting final totals in a reportDisplaying final user messagesClosing all open files

Page 90: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.8

Jackson Structured Programming – Iteration

Write the terminating condition (or a reference code for a conditions list) above the box indicating the iterationInsert an * in the top right hand corner

Process

Tasks*

until finished

Page 91: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.9

JSP – Example 1

Section

Read record

*Until EOF

Page 92: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.10

JSP – Example 2

section

process *until user types Stop

Page 93: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.11

JSP – Example 3

number >= 0 number < 0

Oprocess error

O

Input number

calculation display answer

display error

message

Page 94: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.12

Determining the Structure of a Program

Program is designed from the program specification

ProcessingInitialising

Program

Closing

Page 95: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.13

Stepwise Refinement – Step 1Outline requirements for each main component

Open all files

Process each record to

calculate grades

Close all files

ProcessingInitialising

Program

Closing

Page 96: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.14

Each component can then be further divided

Stepwise Refinement – Step 2

Process a record to

calculate grade

*until EOF

Open input file

Open outputfile

Close allfiles

Output closing

message

ProcessingInitialising

Program

Closing

Open allfiles

Page 97: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.15

Stepwise Refinement – Step 3

No further refinement needed for initialisation or termination

Process a record to

calculate grade

*until EOF

Open input file

Open outputfile

Close allfiles

Output closing

message

ProcessingInitialising

Program

Closing

Open allfiles

calculate average

establish grade

write results to file

accumulate number of

results

Further analysis of processing tasks is required

Page 98: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.16

Stepwise Refinement – Step 4

Actions required to complete the diagram are easily determined

– Calculate averageaccumulate marks - add each mark to total variable divide total by number of marks (6)assign result to average variable

– Assess gradecompare average with grade boundarieswrite result to grade variable

– Write to filewrite name variable + average mark + grade variable to record.

– Accumulate number of recordsadd 1 to number_of_records variablemake sure this running total is at zero at the beginning of the program

Page 99: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.17

Jackson Structured Programming (JSP)

This technique – uses top-down stepwise refinement– only uses the three control constructs– bases the program design on the structure of the data

to be processedThe steps are

– from the program specification, produce data structure diagrams of the data to be input for processing and output

– produce a program structure which reflects the requirements of the data structures

– analyse this in a top-down manner to produce an increasingly more specific program structure

Page 100: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.18

JSP – Example 1 (Physical Data Structure)

Stock File

Children’s clothes

Men’s clothes

Women’sclothes

StockRecords *Stock

Records * StockRecords *

Page 101: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.19

JSP – Example 1 (Logical Data Structure)

Stock File

Children’s clothes

Other sections

O

StockRecords

*

O

not children’schildren’s

Page 102: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.20

JSP – Example 2 (Physical Data Structure)

SalesHeader

SaleRecords

SalesBody

Sales

PurchasesHeader

Purchases

Batch

TransactionFile

File body

O

*

O

* PurchasesRecords

PurchasesBody

*

Page 103: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.21

JSP – Example 2 (Logical Data Structure)

Sales

Batch

TransactionFile

File body

O

*

O

CreditHeader

CreditRecords

CreditBody

*

SalesHeader

SalesRecords

SalesBody

*

cash sales credit salesO O

type=cash type = credit

Page 104: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.22

Establishing the Program Structure

Determine the input and output data structuresCombining them to produce the program structure

– the process is illustrated on the next visual

Page 105: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.23

Physical and Logical DSDs

Filebody

Garage SparesOrder File

Garage *

Area *

Partsorder

*

Filebody

Garage SparesOrder File

Garage *

Partsorder

*

•In this example, the input file is organised sequentially

•Contains details and prices of spare parts which have been ordered by garages.

•The garages have been grouped together by area

•The parts orders grouped together for each garage

•Organised to access the file and produce value of orders by garage

Page 106: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.24

Physical DSD – Report

reportbody

Garage SparesOrder Report

lines ofreport *

footerheading

garagedetails

total ordered

*individualorder amounts

Page 107: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.25

Comparison of Physical DSDs

Filebody

Garage SparesOrder File

Garage*

Area *

Partsorder

*

reportbody

Garage SparesOrder Report

lines ofreport *

footerheading

garagedetails

totalordered

*individualorderamounts

Page 108: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.26

Comparison of Logical DSDs

filebody

GarageSpares

Order File

Garage *

Partsorder

*

trailerheader reportbody

GarageSpares

Order Report

footerheading

lines ofreport *

garagedetails

total ordered

*individualorder amounts

Page 109: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.27

Program Structure

processing

Garage SparesOrder Report

program

processrecords for a

garage

*

closingInitialising

garagedetails

accumulatetotal amountordered

*add individualorder

amounts tototal

open allfiles

printfooter

printheadings

close allfiles

print a lineon the report

Page 110: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.28

CRC Cards

CRC stands for – Class– Responsibility– Collaboration

Created in the late 1980s as a method to teach the object-oriented paradigm

Page 111: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.29

Advantages/Disadvantages of CRC-based Modelling

Creates a good understanding of the domain to be modelledIdentifies high-level responsibilitiesEnsures better system designEnsures that knowledge of the domain is shared by everyoneA good working model can be developedIdentifies areas that may be missed otherwiseIt is fun!The main disadvantage - lack of structure which can be disconcerting to structured programmers not used to the object-oriented paradigm

Page 112: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.30

CRC – Finding Classes and Considering Scenarios

Participants need to know what the requirements of the system will be Brainstorming – the major classes for the system are identifiedIndividual classes can then be discussed and refined until a set is agreedThe group then considers scenarios likely to occur, to test the classes

– some will be discarded, others will become subclassesA subclass is a class within a class

– sharing some of the attributes and behaviours of its parent, but having attributes and behaviours of its own

Page 113: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.31

CRC – Method

A CRC card session should involve about five or six people– include people who have a detailed understanding of the system to be developed

Begin with a brainstorming session– usually someone oversees the session, recording suggestions on a flipchart/board – suggestions are not analysed or discussed– these suggestions form the basis of the classes for the system

Next, the classes suggested are discussed in detail and some will be filtered outEach class is written on a card, and assigned to a participant

– a short description can be added on the back of the card, which can be read out to the group for approval

– the responsibilities of that class are then added to the card in the section providedNext, the group considers simple scenarios which are likely to occur

– helps to discover any missing classes, and the relationships that objects have to each other

Scenarios involve a discussion of how the classes behave and how they interact with each other

Page 114: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Data Analysis and Problems – 2 - 4.32

Summary

Analysing the problemStructured programming diagramsCRC cards

Page 115: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.1

International Diploma in Computer Studies

Session 5Further Programming Techniques – 1

Programming Methods

Page 116: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.2

Contents

Procedures and functionsArraysSorting and searching

Page 117: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.3

Introduction

Program structures– Procedures and functions

Data structures– queue– stack– graph – tree

Page 118: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.4

Top-Down Design Process

Splitting up a problem into its component parts over and over again, until a stage is reached where building a solution becomes much easierDefinition: An approach to program development in which progress is made by defining required elements in terms of more basic elements, beginning with the required program and ending when the implementation language has been reached At every stage, each of the undefined elements from the previousstage is definedIn practice, ‘pure’ top-down development is not possible

– the choice of more basic elements at each stage must always be guided by an awareness of the facilities of the implementation language

– often discovered at a later stage that some earlier choice was inappropriate, leading to a need for iteration

Page 119: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.5

Procedures and Functions

Sections of a program, or subprograms, written to perform a specific task

– will involve operations on data

Written once but can be used many times during execution

– each time the data can be different

Page 120: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.6

Local and Global Variables

The values of local variables are LOST as soon as the procedure or function call has concludedGlobal variables keep any values assigned to them and although they can be used anywhere in the program, they can also be influenced or changed by any part of the program

Page 121: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.7

Quiz Program

choice 2 choice 3 choice 5choice 4 choice 1CAPITALProcess

MATHSProcess

CHEMProcess

Displaychoices

Choice?

Display“Error”

Acceptchoice

end

Page 122: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.8

Parameters

Variables which are used in a procedure or function to accept values passed to the procedure or function with the procedure call

– the technical term for the value passed is an argument or actual parameter

– the variables used within the procedure or function are called formal parameters

Page 123: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.9

Functions

A function returns a value to the calling program

– a procedure carries out a process without returning a value

Most programming languages contain a library of functions, e.g.

– to generate a random number– to calculate a variety of mathematical functions

such as square root– to find and return values from lists

Page 124: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.10

Answer to Exercise 4.3INTEGER FUNCTION subtract (a,b OF TYPE Integer)

answer:= a-bRETURN answer

ENDFUNCTION

INTEGER FUNCTION multiply (a,b OF TYPE Integer)answer:= a*bRETURN answer

ENDFUNCTION

INTEGER FUNCTION divide (a, b OF TYPE Integer)WHILE b= 0

DISPLAY “You cannot divide by zero"DISPLAY “Enter another value”ACCEPT b

ENDWHILEanswer:= a/bRETURN answer

ENDFUNCTION

Page 125: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.11

Reasons for Using Procedures/Functions

Code can be built to reflect a structured design with procedures echoing the design at each level of the top-down processTasks needed repeatedly within a program can be coded once, and then called when neededSmaller sized procedures – easier to test and debug, leading to greater overall reliabilityVariables can be confined to the procedure in which they are used – eliminating unexpected side effects in other parts of the program

Page 126: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.12

Arrays

Sequence or list of data items, all of which are the same data type

– each data item can be referenced by its position in the sequence

One or two-dimensional (or more)Some programming languages use simple lists instead of arrays

Page 127: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.13

One-Dimensional Arrays

Sequence of data items where each element can be referenced by the position it occupies in the sequenceElements can be simple or complex data types but they must all be the same, i.e. homogeneous

subscript names array marks array 1 Peters J 55 2 Ratcliffe N 43 3 Smith J 67 4 Sutcliffe B 34 5 Yates V 78

Page 128: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.14

Two-Dimensional Arrays

COLUMNS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

R 1 j a m e s O 2 j a n e t W 3 a l e x a n d e r S 4 l e e 5 z a c h a r i a

Have two subscripts to identify an element of the array– can be thought of as the rows and columns in a table

Elements MUST be of the same data type

The letter ‘m’ in the name james can be precisely located as name_list[1, 3]

Page 129: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.15

Exercise 4.6

Page 130: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.16

Answer to Exercise 4.6

PROGRAM multiplication tables use variables:multiply[15,12] : ARRAY OF TYPE Integerrow, column of type IntegerFOR (row = : 1, row = 15, +1)

FOR (column = 1, column = 12, +1)multiply[row, column] := row * column

ENDFORENDFOR

endprogram

Page 131: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.17

Tables: Arrays of Records

Field Names

First Name Last Name Grade Job Type

John Chang a1 EngineerEric Teo a5 ComputingDavid Smith a4 AdminPeter Lee a4 Writer

Records

A table of records can be considered as a two-dimensional array in which the rows represent the records, and the columns represent the fields

Page 132: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.18

Record Data Structure

To declare a record called car with fields, make, size, and colour

RECORD car

HAS FIELDS make : String

size : Integer

colour : String

To declare an array which contains 20 of these records

types_of_car [20] ARRAY OF TYPE car

Page 133: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.19

Exercise 4.8

Field Names

First Name Last Name Grade Job Type

John Chang a1 EngineerEric Teo a5 ComputingDavid Smith a4 AdminPeter Lee a4 Writer

Records

Page 134: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.20

Answer to Exercise 4.8RECORD employee

HAS FIELDS first_name: Characterlast_name: Charactergrade: Characterjob_type: Character

personnel [20] ARRAY OF TYPE employee

Note that you can decide on the size ofthe array, but a number of elementsMUST be specified

or HAS FIELDS first_name,last_name, grade, job_type OF TYPECharacter but it is easier to read inthe list.

Page 135: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.21

Sorting and Searching

Internal sorts, i.e. performed in the memory of the computerDefinition: sorting– rearranging information into ascending or

descending order by means of sort keys Sorting may be useful in three ways – to identify and count all items with the same

identification– to compare two files– to assist in searching

Page 136: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.22

Sort Methods

Selection sorts– Selection sort using two arrays– Straight selection sort

Straight insertion sortExchange selection sort, often called bubble sort

Page 137: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.23

Selection Sort Using Two Arrays

Starting state After pass 1 After pass 2 After pass 3

Data Array

Extra Array

Data Array

Extra Array

Data Array

Extra Array

Data Array

Extra Array

205 205 45 999 45 999 45

310 310 310 205 999 205

45 999 999 999 310

Page 138: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.24

Pseudocode for a Straight Selection Sort

Note: pass < nAn array of 20 would only require 19 passes. At the end of the 19th pass, the 19th and 20th elementwould be in the correctposition.

VARIABLESnumbers[n]: ARRAY OF TYPE Integercount, pass, lowest,temp OF TYPE IntegerFOR (pass: = 1, pass = n - 1, +1)

count:= pass + 1 lowest:=pass FOR (count: = pass+1, count = n, +1) IF numbers[count] < numbers[lowest]

THEN lowest:= count + 1ENDFOR temp:= numbers[pass]numbers[pass] := numbers[lowest]numbers[lowest] := temp

ENDFOR

Note:exchange the contents of the current element (pass) with the contents of thelowest element, using temp as temporary storage.

}

Page 139: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.25

Straight Selection Sort

Page 140: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.26

Straight Insertion SortEffective when sorting small arrays – slow when sorting larger arrays

VARIABLES show[6]: ARRAY OF TYPE Integerposition, pass, copy OF TYPE IntegerFOR (pass := 2, pass = 6, +1)

copy := show[pass]position := pass WHILE (position > 0) AND (show[position - 1]) > copy

show[position] := show[position - 1]position := position - 1

ENDWHILEshow[position] := copy

ENDFOR

Page 141: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.27

Exchange Selection Sort

Step Two 1 2 3 4 5

Compare2nd<=3rd 2nd>3rd

Nochange

2nd and 3rdelements swapplaces via temp

1 2 3 4 5

Compare

1st<=2nd 1st > 2nd

Nochange

1st and 2ndelements swapplaces via temp

contents:is (3 > 1)?

First passStep 1

subscripts3 1 2 5 4

contents

1 3 2 5 4

contents

subscripts

1 3 2 5 4

contents

1 2 3 5 4

contents

contents:is (3 > 2)?

Also referred to as bubble sort because the largest element rises to the top of the array

Page 142: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.28

Bubble Sort Pseudocode

these three statements exchange elements n and n+1 }

main program Use local variables

example [10]: ARRAY OF TYPE Integer exchange_count, pass, temp OF TYPE Integer

pass:=1 REPEAT

exchange_count:= 0 FOR (n:=1, n = 10 - pass, +1)

IF example[n] > example[n+1] THEN temp:= example[n] example[n] := example[n+1] example[n+1] := temp exchange_count := exchange_count+1

ENDIF ENDFOR pass:= pass+1

UNTIL exchange_count= 0 endprogram

this statement records the number of exchanges that have taken place in this pass (only need to know whether > 0)

Page 143: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.29

Bubble SortArray element Initial state After 1st pass After2nd pass After 3rd pass

1 41 23 23 232 23 41 32 323 42 32 41 414 32 42 42 425 67 53 46 466 53 46 53 537 46 67 67 678 99 81 73 739 81 73 81 81

10 73 99 99 99Variables used

during looppass 1 2 3 4

n 1, 2, 3, 4, 5, 6, 7, 8, 9 1, 2, 3, 4, 5, 6, 7, 8 1, 2, 3, 4, 5, 6, 7temp 41, 42, 67, 99 41, 53, 81

exchange_count 1 0, 1, 2, 3, 4, 5, 6 0, 1, 2, 3 0Thus the program will end after the 3rd pass as exchange_count = 0

Page 144: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.30

Searching

Finding one particular element in an array – simply a matter of looking through the array, element

by element, until the required key is found– can be done sequentially, i.e. starting from the first

element and looking for a matching key until one is found, e.g

IF key_to_be_found = array[n] THEN found := TRUE

More efficient methods– searching a sorted list– binary search

Page 145: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.31

Searching – Example -- note that key_to_be_found and key_array would contain data at-- this point of the program. The key_to_be_found data could have-- been input over the keyboardUse local variables

key_array: ARRAY [10] OF TYPE Stringkey_to_be _found OF TYPE Stringcount, n OF TYPE Integerfound OF TYPE Boolean

begin sort procedureCount := 1found := FALSEREPEAT

IF key-to-be-found = key_array[count]THEN found := TRUEELSE count :=count+1

UNTIL found = TRUE OR count >10-- the program would then continue-- taking appropriate actions with the item found - element count-- or a “not found” result

Page 146: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.32

Searching a Sorted Listkey_array: ARRAY [10] OF TYPE StringUse variables key_to_be _found OF TYPE String

count, n OF TYPE Integer found, missing OF TYPE Boolean

-- note that key_to_be_found and key_array would contain data at -- this point of the program. The key_to_be_found data could have-- been input over the keyboardbegin sort procedure

count:=1found:= FALSEmissing:= FALSEREPEAT

IF key-to-be-found = key_array[count] THEN found := TRUEELSE IF key_to_be_found < key_array[count]

THEN missing:= TRUEENDIFcount :=count+1

UNTIL found = TRUE OR count >10 OR missing = TRUE-- the program would then continue -- taking appropriate actions with the item found -- or a “not found” result

Page 147: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.33

Binary SearchUse variables start, end, middle OF TYPE Integer

found OF TYPE Booleankey_required OF TYPE Stringkey_name (10): ARRAY OF String

start:= 1end:= 10found:= falseREPEAT

middle:= (end+start)/2IF key_required = key_name[middle]

THEN found := TRUEELSE IF key required < key-name[middle]

THEN end : = middle-1ELSE start := middle+1

ENDIFUNTIL found= TRUE OR start > end

Page 148: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 1 - 5.34

Summary

Local and global Variables Procedures Using parameters Functions One and two-dimensional arraysTablesSorting and searching

Page 149: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.1

International Diploma in Computer Studies

Session 6Further Programming Techniques – 2

Programming Methods

Page 150: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.2

Contents

Linked ListsData structures– queues– stacks– graphs– trees

Page 151: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.3

Arrays and Linked Lists

Two different implementation mechanisms that allow classic data structures to be held within a computer program

– any data structure can be represented as either a linked list or an array

– in most structured languages it is possible to have linked lists and arrays of any type

Each programming language will have a particular way of defining and accessing arrays

Page 152: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.4

Linked Lists

Make better use of storageItems not necessarily stored in sequenceEach element of the list contains

– the data required by the programmer– a pointer which points to the next element in

the list in terms of sequence rather than storage (singly linked list)

A more flexible linked list has two pointers (doubly linked list)

Page 153: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.5

DefinitionsSingly linked list (one-way linked list)

– a linked list in which each item contains a single link to its successor

– by following links it is possible to access the entire structure from the first item

Doubly linked list (two-way linked list; symmetric list) – a linked list where each item contains links to both its

predecessor and its successormakes it possible to traverse the list in either direction.

– the flexibility allowed by double linking must be offset againstthe overheads of the storagethe setting and resetting of the extra links involved when items are inserted or removed

Page 154: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.6

Singly Linked List

linked list

Address

1

2

3

4

5

6

7

Data

“I”

“do”

“not”

“understand”

“linked”

“lists”

Pointerto next

element

2

3

4

5

6

null

Comment

next element in thesequence is element 2next element in thesequence is element 3next element in thesequence is element 4next element in thesequence is element 5next element in thesequence is element 6null pointer indicates thelast data itemempty in that no data inthis element

start pointer has aninitial value of 1, sopoints to firstelement in thelinked list

startpointer 1

freestoragepointer

7free storage pointerhas an initial valueof 7 i.e. points to theaddress of the firstavailable freeelement in the

Linked List

Page 155: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.7

Singly Linked List – Deletion

Address

1

2

3

4

5

6

Data

“I”

“do”

“understand”

“linked”

“lists”

Pointerto nextelement

2

4

5

6

null

Comment

delete “not” from thelinked list

start pointer has aninitial value of 1 sopoints to first elementin the linked list

startpointer 1

freestoragepointer

3free storage pointerstill points to theaddress of the firstavailable freeelement in thelinked list

Linked List

1 Position 2Pointer to next elementchanged from 3 tonext_pointer of item 3(was 4). (this willensure the deleted one isbypassed)

2 Position 3:Data deleted from listat position 3.

3 Free storage pointerchanged to this deletedone (same asnext pointer in previousposition before it wasupdated)

Page 156: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.8

Singly Linked List – Insertion and Addition

Address

1

2

3

4

5

6

7

8

Data

“I”

“do”

“arrays”

“understand”

“linked”

“lists”

“and”

Pointerto next

element2

4

7

3

6

null

5

Comment1 Insert “arrays” into

position 4 in thesequence• new data inserted at

free storage address (3)• next_pointer changed to

indicate next element (5th)• previous 3rd element

(‘understand’) - changenext_pointer to addressof new element

• free storage pointerchanged to 7

2 Insert “and” intoposition 5 in the linked list• new data inserted into

empty element (7) andnext_pointer changed to 5

• free storage pointerchanged to 8

start pointer has aninitial value of 1 sopoints to first elementin the linked list

startpointer 1

freestoragepointer

8

free storage pointerstill points to theaddress of the firstavailable freeelement in the linkedlist

Linked List

Page 157: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.9

Answer Exercise 4.15Address

1

2

3

4

5

6

Data

“I”

“do”

“understand”

“linked”

“lists”

Pointerto next

element

2

4

5

6

null

Comment

delete “not” from thelinked list

start pointer has aninitial value of 1 sopoints to first elementin the linked list

startpointer 1

freestoragepointer

3

free storage pointerstill points to theaddress of the firstavailable freeelement in thelinked list

Linked List

1 Previous position (2)Pointer to next elementchanged from 3 tonext_pointer of item 3(was 4). (this willensure the deleted one isbypassed)

2 Position 3:Data deleted from listat position 3.

3 Free storage pointerchanged to this deletedone

Page 158: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.10

Doubly Linked List

freestoragepointer

7

‘Address’

1

2

3

4

5

6

7

Data

47

53

64

75

86

97

Pointerto next

element

2

3

4

5

6

null

Comment

null pointer indicates the first data item

null pointer indicates the lastdata item

empty, containing no data

Doubly Linked List

Pointerpreviouselement

null

1

2

3

4

5

Page 159: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.11

Doubly Linked List – Deletion Comment

a) 47 deletedElement 1 - 47 deleted,previous _pointer was nullnext_pointer was 2so previous_pointer of next element (2) := nullfree storage pointer changed to 1

b) 64 deletedElement 3 - 64 deletedprevious_pointer was 2next_pointer was 4so previous_pointer of next element (4)changed from 3 to 2 and next pointerof previous element changed from 3 to 4free storage pointer changed to 3

This would be a list (or stack) where 3 is the top entry and then 1, 7, 8Thus the free storage pointer list is 3, 1, 7, 8

freestoragepointer

3

‘Address’

1

2

3

4

5

6

7

Data

53

75

86

97

Pointerto next

element

4

5

6

null

Doubly Linked List

Pointerpreviouselement

null

2

4

5

Page 160: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.12

Doubly Linked List – Addition

freestoragepointer

1

‘Address’

1

2

3

4

5

6

7

Data

53

75

86

97

Pointerto next

element

3

5

6

null

Doubly Linked List

Pointerpreviouselement

null

3

4

5

2 66 4

Comment

66 inserted in correct position (2nd) at freestorage pointer address (3)

Element 3 - 66 to be addedprevious element (2) had next_pointer of 4 andnext element (4) had previous_pointer of 2

new element:next_pointer :=4previous_pointer :=2

previous element (2):next pointer:=3next element (4)previous pointer :=3free_storage pointer changed to 1

This would be a list (or stack) where 3 has been removedso 1 is now the top entry and then 7, 8Thus the free storage pointer list is now 1, 7, 8

Page 161: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.13

How are Linked Lists used by Programmers?

Depends on whether the programming language used provides functions for list manipulation

– if lists are not managed by the programming language, then the programmer has to provide this logic by using arrays

Programming languages which can deal with lists would have a number of functions provided for list manipulation

– programmers can then use these lists and the functions provided to create singly linked lists or doubly linked lists

Page 162: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.14

Linked List FunctionsDefining lists, emptying or clearing listsAdding or inserting elements, changing elements and deleting elementsProviding information about the list e.g. the number of elements in the list, the minimum and maximum valuesSearching lists.

– e.g finding the element “array” and returning its position in the list (4)

Note: a list is often implemented as an object, with the function as methods

Page 163: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.15

Linked Lists Using ArraysSingly Linked List

RECORD resultsHAS FIELDS

previous_pointer: Integername: Stringexam_mark: Integernext_pointer: Integer

Use variablesresult_list [20] AN ARRAY OF TYPE results

RECORD sentenceHAS FIELDS

words: Stringnext_pointer: Integer

Use variablessentence_list [20] AN ARRAY OF TYPE sentence

RECORD resultsHAS FIELDS

previous_pointer: Integername: Stringexam_mark: Integernext_pointer: Integer

Use variablesresult_list [20] AN ARRAY OF TYPE results

Doubly Linked List

Page 164: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.16

PointersUsually four pointers associated with a linked list, depending on the data structure the linked list is being used for The four main pointers are

– first − a pointer to the first element in the list, i.e. the one with a null previous_pointer

– last − a pointer to the last element in the list, i.e. the one with a null next_pointer

– current − a pointer to the current element of interest– free-storage − a pointer to the first available free

storage

Page 165: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.17

Data Structure – Linked ListsThe choice of storage mechanism for implementing a data structure

– critical to the performance of a computer application– when the size of the data to be manipulated is

unknown a linked list must be used– if the maximum size of the data is known, an array is

the more efficient storage structure

Many languages do not support dynamic data storage mechanisms such as linked lists

– it is the programmer’s responsibility to manage the size of the array

Page 166: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.18

Queues and Stacks

Types of abstract data structures– managed by using linked lists, or arrays

or lists

Abstract data type– a data type that is defined solely in terms

of the operations which apply to objects of the type, without commitment as to how the value of such an object is to be represented

Page 167: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.19

QueuesThe first element added to the queue is also the first element to be removed

– referred to as a FIFO (First In First Out) list

Only three operations required for handling a queue (programminglanguages which support queue handling provide these functions)

– access the next element in the queue– add an element to the queue– remove an element from the queue

Queue manipulation falls within the bounds of normal list manipulationTheoretically, queues could be implemented as arrays, provided that

– the absolute maximum size of the queue is known, or – elements can be stopped from entering the queue until a space is

available

Page 168: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.20

StacksDiffer from queues in the way in which data is added and removedData is added to the ‘top’ of the stack and is also removed from the ‘top’

– often referred to as a LIFO (Last In First Out) listStored in the form of listsOnly three operations required for handling a stack (programminglanguages which support stack handling provide these functions)

– add an element to the stack (push)– access the next element– remove an element from the stack (pop)

Use lists to implementCan be implemented as arrays if

– absolute maximum size of the stack is known, or – elements can be stopped from entering the stack until a space is

available

Page 169: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.21

Graphs and Trees

Abstract data structures used to describe the data and operations in real life situations

– a storage structure such as arrays or linked lists used to implement

Graphs– multi-connected network of elements

Trees– hierarchical structures, subset of graphs

useful for sorting

Page 170: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.22

Graphs1

2

3451

2

345

Acyclic graph

Cyclic graph

Page 171: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.23

Graphs – Array Representation

TO

1 2 3 4 5

F

R

O

M

1 / Y N Y Y

2 N / Y N N

3 N N / N N

4 N N Y / N

5 N N N Y /

Page 172: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.24

Trees

A subset of graphs Very useful in sorting dataHierarchical data structures, similar to a family treeThe elements of a tree are called nodes

0

1

4

2

5

3

6 7 8

Note that there is a single root element, each element has a set of children and each element has a single, unique parent.

Page 173: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.25

Binary Tree

All elements have – maximum of two child

elements– a single parent

At each node there is either a left branch or a right branch, or both

– each element consists of data and at least two pointers, a left pointer and a right pointer

0

8

2

5

1

75

Page 174: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.26

Sorted Binary Tree

55

83

66

44

47

1

2 3

4

5

1 55 is the first element

2 44 <55 so appears on the left

3 83>55 so appears on the right

4 66>55 but <83 so appears to the left of 83

5 47<55 but > 44 so appears to the right of 44

Assume the numbers 55, 44, 83, 66 and 47 are to be placed in a tree in that order

Page 175: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.27

Sorted Binary Tree – Addition Add 92, 26 and 72 to the tree

55

92

83

66

44

4726

72

1 92 > 55, >83 so appears on theright of 83

2 26<55, <44 so appears to the left of 44

3 72>55, <83 and >66 so appears tothe right of 66

Page 176: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.28

Sorted Binary Tree – Deletion 55

6644

4726

92

72

1 83 is a parent node so is replacedby the first child (66) plus child (72)

83 is now removed from the tree

Page 177: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.29

Binary Tree – Linked List

55

83

66

44

47

1

3

5 4

Start

2

Page 178: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.30

Arrays – Binary Trees

It is only possible to represent a binary tree as an array when the total number of elements in the tree is known beforehand– using the binary tree as the data

structure – the array as the underlying storage

Page 179: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.31

Binary Tree – Array RECORD results

HAS FIELDS left_pointer: Integermarks: Integerright_pointer: Integer

results_tree[100] ARRAY OF TYPE results

Array RecordArray element

NumberLeft pointer Data Right pointer

1 2 55 32 -1 44 53 4 83 -14 -1 66 -15 -1 47 -1

Array record structure for a binary tree

Binary tree represented by an array

Page 180: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Further Programming Techniques – 2 - 6.32

Summary

Linked listsData structures including queues and stacks, graphs and trees

Page 181: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.1

International Diploma in Computer Studies

Session 7Modelling Objects – 1

Programming Methods

Page 182: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.2

Contents

Unified Modelling Language (UML)– Introduction– UML advantages and disadvantages

NotationsUse casesClass diagrams

Page 183: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.3

Introduction

Before the development of design and analysis methodologies

– programmers often relied on rough sketches– programs were built up gradually – no overall plan, so difficulties existed

in communicating the nature of the program being builtIf it was necessary for another programmer to take over the developmentin ensuring that programme being built is actually what the client wants

Page 184: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.4

Analysis and Design

Developers now use analysis and design techniques to determine client requirements

– the resulting plans allow each member of the team to

understand where their work fits into the system being developedknow exactly what that system is

Design methodology – a means of notation or expressing the design

in graphical form– a process for software development

Page 185: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.5

Modelling Languages

Means of expressing design in graphical formImportant for a number of reasons:

– an exact specification for the developers– project managers can estimate cost more accurately

Early methodologies were created for structured programmingIn the 1980s object-oriented languages gained poplularity

– it was felt that analysis and design methods would be beneficial to object oriented programs

Page 186: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.6

Why the UML was Developed

Offers a method of communication between technical developers and non-technical usersApplies analysis and design methods to OO programsSeveral methodologies – a standard notation needed Independent task force set up to deal with the process of creating official UML standards

– part of the Object Management Group (OMG)– public version of UML released in 1999

Page 187: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.7

UML Advantages – 1

New UML development tools – design systems, and allow code to be exported

Code can be exported as diagramsReady-made modelling language to help developers communicate Language is graphical and capable of expressing ideasEnables modelling using object-oriented conceptsA means of extending core concepts of the languageIndependent of programming languages and development processesFormal basis for understanding the modelling languageEncourages growth of the OO tools market

Page 188: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.8

UML Advantages – 2

Supports higher-level development conceptsIntegrates best practicesAddresses issues of scale inherent in complex, mission-critical systemsModelling language usable by both humans and machinesGood upfront design shortens development timeA standard model means easier communication between development teamsAn official standard

Page 189: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.9

UML Disadvantages

Initial learning curve can be steepModelling is a discipline

– needs to be used– a tool will not model the system for you

Independence of programming languages– processes might not suit some people

Developers will probably still need an iterative development process

Page 190: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.10

UML Diagrams

Use case diagramsClass diagramsSequence diagramsComponent diagramsDeployment diagramsStatechart diagramsCollaboration diagrams

Page 191: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.11

Use Case DiagramsConcentrate on the user's point of viewUse cases should explore scenarios which aim to satisfy the needs of those using the systemThe ‘actor’, or thing that is interacting with the system on the left is connected to the use case on the rightThe use case is what the actor wants to achieve

Page 192: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.12

Class Diagrams

Express the classes of objects found in the systemClasses share attributes and behavioursName of the class is at the top, attributes in the centre, behaviours in the bottom section

Bird

feathersbeakwings

can flylays eggssings

Page 193: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.13

Sequence Diagrams

:Timer:HeatingElement :Turntable

Turn on turntable

Time15 minutes Keep heating Keep rotating

Set timePress 'Start'

Turn on heating element

Turn off turntable

Turn off heating element

Show how objects in the system will interact with each other

Page 194: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.14

Component Diagrams

Solely concerned with the development of computer systems A component can be a table, data file, executable file and many other things

bird.exe

Page 195: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.15

Deployment Diagrams

<<Processor>>PC

AMD K6 300

<<Device>>Monitor

ADI Microscan 4V

Show the physical set-up of the system

Page 196: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.16

Statechart Diagrams

Objects in the real world are usually in one state or another

Stop

Prepare to go

Free to go

Prepare to stop

Stop

RED

RED AND AMBER

GREEN

AMBER

RED

Page 197: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.17

Collaboration Diagrams

:Timer

:HeatingEelement

:Turntable

1:Rotate(Turntable)

2:Switch on(Heating Element)3:Check time(less than set time)

Show how the elements of the system being developed collaborate or work together to achieve the system’s

purpose

Page 198: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.18

Use Cases – Introduction

Systems are often developed according to clients’ and developers’opinions

– little thought given to the users of the systemA system designed for its end users is easy to useUse cases provide

– a useful means for explanation and communication between user and developer

– offer a dynamic view of the system from the point of view of the end users To understand how the system should interact with the outside world

– identify the scenarios which will occur Purpose of a use case is to examine the scenarios that will benefit an ‘actor’ (an object which is not part of the system, but interacts with it, e.g. a customer)

Page 199: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.19

Use Case Analysis – 1

Important to identify the actors during the analysis stage of software development

– questions asked to determine exactly what the system is required to do

Begins with the client interviews which take place to determine the initial classes in the system

– a basis for discussing possible use casesThe analyst’s role is then to ask the users to describe

– all their interactions with the system– each use case i.e. the scenarios that will occur

Important to determine all the actors who will initiate and benefit from the system

– analysts can ask questions such as:What exactly do the users want the system to do?

Page 200: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.20

Use Case Analysis – 2

Use cases are not confined to the analysis phase– can be used in both the development and testing

phases Use case analysis aims to describe how the system will behave rather than how it will be implementedA use case model defines

– the boundaries between the system and the outside world

– where the system interacts with the outside world

Page 201: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.21

Use Cases

ActorsClass diagramsActivity diagrams

SystemAdministrator

ClericalStaff

ProjectManager

MarketingManager

SalesRepresentative

connectexternally

providesecurity levels

use email

store files

access companydocumentation

share printers

connect tointernet

LAN

A high-level use case diagram showing some examples of use casesfor a company LAN

Page 202: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.22

Relationships

May exist between use cases themselves as well as between actors and use casesFour types of use case to use case relationship:

– inclusion– use case generalisation– extension– grouping

Page 203: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.23

InclusionAvoids repetition

– allows developers to create use cases that can simply be referred to each time they are needed

Inclusion use cases – dependent on the use case that contains them– cannot be used on their own, and must be

used in conjunction with the use case that includes them

Page 204: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.24

Inclusion – Example

Open machine inclusion use case– Unlock the machine – Enter a security code – Open the door

RESTOCK THEDRINKS MACHINE

RESTOCK ACCORDINGTO BEST SELLERS

OPEN MACHINE

CLOSE MACHINE

<<extend>>

<<include>>

<<include>>

A CASE DIAGRAM SHOWING EXTENSION AND INCLUSION

Page 205: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.25

Generalisation

Use cases can inherit behaviour from parentsSteps from buy drink use case

– Add tonic or bitter lemon – Add ice – Add lemon PARENT

CHILD CHILD

GENERALISATION BETWEEN ACTORS THE SOLID LINEAND OPEN TRIANGLE POINT TO THE PARENT USE CASE

order goods order shoes

Page 206: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.26

Extension

May need to make additions to standardised or base use cases Extension use cases only occur at specified points within the base use case’s sequence

PURCHASE ITEMS

CREATE ACCOUNTFOR NEW USER

LOG ONTOACCOUNT

<<INCLUDE>>

A USE CASE DIAGRAM SHOWING EXTENSION

<<EXTEND>>

Page 207: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.27

Grouping

The developer may find it helpful to organise use cases, if there are several in existenceThe notation for grouping use cases is to simply include them inside a package

PACKAGE

Page 208: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.28

UML Symbols

ACTOR

USE CASE

GENERALISATION ASSOCIATION

SYSTEM BOUNDARY

DEPENDENCY

<<STEREOTYPE>>PACKAGE

Page 209: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.29

Business and System Use Cases

Business use cases are concerned with how a business responds to a particular customer or event

– can be useful in considering how to meet an actor's goal

System use cases are concerned with the interaction between the system or software and the user

– more useful for planning the system– how the system behaves in particular scenarios

For each business use case identified, there should follow a set of system use cases

Page 210: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.30

Class Diagrams

Create a visual map of objects which make up the system Class diagrams are static

– subtypes or associations Types of objects may include

– physical entities – logical entities– soft entities– conceptual entities

Page 211: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.31

Building Class Diagrams

Define objectsGroup them according to classes (categories)Determine parent classesDefine attributes and operations for each objectDefine associations between objects and messages sent to associated objects, by further sorting and rearranging the objects

Page 212: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.32

Class Diagram Notation

Define the domain for analysisForm some meaningful groups of objects which are relatedDefine and label associations between classesFor an individual object, add attributes and operations

Page 213: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.33

Subtypes and Generalisation

Subtypes are a form of linkage where individual objects share common features with other objects and may be said to be examples of "a kind of " something e.g. kind of animal Airport modelling exercise – group objects

Page 214: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.34

Associations – 1

Associations represent relationships between different object classes

– needed to enable objects to communicate with each otherEach association has two association ends

– each end is attached to one of the classes in the association

Association

Multiplicity

Page 215: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.35

Associations – 2

Aggregation

Constraints

Page 216: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.36

Attributes and Operations

Recorded in class icons– top panel contains the

class or object instance name

– middle panel describes the attributes

– bottom panel describes the operations

A one-word attribute or operation is written in lower case letters

– more than one word –words linked, each word other than the first begins with an upper case letter

Page 217: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.37

Attributes

Describe the data contained in an object of the classAn attribute has a name and a type

Page 218: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.38

OperationsOperations are the processes that a class knows how to carry outThe operations of a class define the ways in which objects may interact

Page 219: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.39

Operations – UML Syntax Visibility name (parameter -list): return- type -expression {property-string}

Page 220: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 1 - 7.40

Summary

Why the Unified Modelling Language (UML) was developedThe advantages and disadvantages of the UMLBasic notations and diagramsUse cases including scenarios, actors, relationships and business and system use casesClass diagrams including subtypes and generalisation, associations and attributes and operations

Page 221: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.1

International Diploma in Computer Studies

Session 8Modelling Objects – 2

Programming Methods

Page 222: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.2

Contents

Interaction diagramsState diagramsActivity diagramsFitting the diagrams together

Page 223: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.3

Interaction Diagrams

Concentrate on the messages (or events) which flow between objectsTwo diagram types

– Sequence diagrams– Collaboration diagrams

Page 224: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.4

Sequence Diagrams – 1 Indicate how multiple objects communicate with each other over a period of time and in what sequence

Page 225: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.5

Sequence Diagram –CD Player

Page 226: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.6

Sequence Diagram –Use Case

Page 227: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.7

Sequence Diagrams – 2

Sequence diagrams come in two forms to deal with real life scenarios

– Instance sequence diagramdeals with an action in which one scenario, and only one scenario, is possible

– Generic sequence diagram deals with actions, following which a number of scenarios can occur

For every use case, a sequence diagram is used to illustrate the activities, sequence and relationships therein

Page 228: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.8

Instance Sequence Diagram

Page 229: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.9

Generic Sequence Diagram

Page 230: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.10

Sequence Diagram – Example

Page 231: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.11

Recursion

Object must invoke itself more than once to carry out a repetitive task

Page 232: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.12

Collaboration DiagramsAlternative analysis method examining things from a space point of view rather than time Highlight the context and overall organisation of the objects as they interact

Page 233: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.13

Collaboration Diagram CD Player – 1

Page 234: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.14

Collaboration Diagram CD Player – 2

Page 235: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.15

Best Case Collaboration Diagram

Page 236: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.16

Multiple Conditions Collaboration Diagram

Page 237: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.17

Collaboration Diagram –Example 1

Page 238: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.18

Collaboration Diagram –Example 2

Page 239: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.19

Collaboration Diagram – Active Object

Page 240: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.20

Collaboration Diagram –Synchronisation

Page 241: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.21

State Diagrams

Symbol for the stateicon showing details

Represent dynamic change in objects

Page 242: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.22

State Diagram –Camera

Page 243: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.23

State Diagram – CD Player Switch on/switch off process

The guard condition

Page 244: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.24

Sequential and Concurrent Substates

Page 245: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.25

State Diagrams – History Icon

Page 246: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.26

Activity DiagramsTrack activities, decision points and branchesA simplified view of what happens during operations and processes

Page 247: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.27

Concurrent Activities

Page 248: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.28

Input and Output Signals

Page 249: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.29

Operation Activity Diagram

Page 250: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.30

Process Activity Diagram

Page 251: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.31

Process Activity Diagram –Example

Page 252: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.32

Activity Diagram – Swimlanes

Page 253: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.33

How Diagrams Fit Together - 1

Requirements gathering– Discover business processes– Perform domain analysis– Discover system requirements

Analysis– Understand system usage– Flesh out use cases– Refine the class diagrams– Analyse changes of state in objects– Define the interactions among objects– Analyse integration with co-operating systems

Page 254: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.34

How Diagrams Fit Together – 2

Design– Design and refine object diagrams– Develop component diagrams– Plan for deployment– Design tests

Development– Construct code– Construct user interfaces, connect to code and

test

Page 255: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Modelling Objects – 2 - 8.35

Summary

Interaction diagrams – Sequence diagrams – Collaboration diagrams

State diagramsActivity diagrams

Page 256: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.1

International Diploma in Computer Studies

Session 9Testing

Programming Methods

Page 257: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.2

Contents

Documentation of testsLevels of testingDesk checking and dry runningDiagnostic aidsInteractive debuggingProgram maintenanceNeed for robust and reliable software

Page 258: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.3

Testing

Should be planned and systematic to be most effective, not a haphazard approachTesting can be either manual or automatedThere are a variety of purposes for which testing is carried out

Page 259: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.4

Reasons for Software BugsLack of effective communication on software functionComplexityErrors by programmersRequirements changingPressures of timescaleUnderestimation of the difficulty of tasksCode not properly documentedUse of development tools that have bugsMiscommunication on application function

Page 260: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.5

Associated RisksProduce incorrect resultsAllow unauthorised transactionsLose computer file integrity Not be able to reconstruct processing Lose continuity of processing Deteriorate in performance to an unacceptable levelCompromise securityNot comply with organisational policy or governmental regulationProduce unreliable resultsBe difficult to useNot be portable to other hardware and softwareInability to interconnect with other computer systems

Page 261: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.6

Variance

Variance from specifications – a defect from the perspective of the build of

the productVariance from what is desired

– the defect from the user (or customer) perspective

Page 262: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.7

Testing Processes

Static – e.g. reading and checking documents on

requirements, reading and checking code without running software

Dynamic – e.g. running code to check outputs

Page 263: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.8

Verification

Checking that developers are building the right productChecklistsIssues lists WalkthroughsInspection meetings

Page 264: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.9

Validation

Checking that the product worksDemonstrate the validity of the software at each stage in the system development lifecycleCheck the final system meets user needs and requirements, as specifiedExamine the behaviour of software or system by using sample test data

Page 265: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.10

Documentation of Tests

Tests must be fully described BEFORE they are carried out:

Identity of the component to be testedPurpose of the testConditions under which the test is to be carried outTest data to be usedExpected outcome

Page 266: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.11

Five Levels of Testing

Unit testingIntegration testingSystem testingAcceptance testingInstallation testing

Page 267: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.12

Testing Approaches

Two main approaches:

Black box testingWhite box testing

Page 268: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.13

Integration Testing

Identify situations where:

Data is lost between modulesOne module creates a fault in another moduleCombining several modules creates a major undesirable side effect

Page 269: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.14

Combining Modules for Integration Testing

Alternatives:Big bang Phased Incremental

Order:Top-downBottom-upSandwich integration

Page 270: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.15

System TestingFacilityVolumePerformanceUser interfaceSecurityRecoveryError exitHelp information

Page 271: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.16

Acceptance Testing

Comparing the program with its initial requirements specification and the current needs of its potential usersDemonstrates the way the system works

– does not aim to find errors

Page 272: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.17

Installation Testing

The purpose of the test is to find installation errors rather than software errorsIncluding files, libraries, hardware, operating system

Page 273: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.18

Desk Checking and Dry Running

Desk checking aims to check action or process

– Variables list– Subroutines, functions– Constants– Equation of variables

Dry running involves the execution of code segment

– programmer acts as computer– very time consuming

Page 274: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.19

Diagnostic Aids

Programmers need good diagnostic skillsMake effective use of all the clues providedObtain as many clues as possible

Page 275: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.20

Interactive Debugging

TraceDebuggerLog fileSingle steppingAnimation

Page 276: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.21

Other Automated Tools

Code analysersCoverage analysersMemory analysersLoad/performance test toolsWeb test toolsMiscellaneous tools

Page 277: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.22

Problem Solving Process Understanding the problem

– study the available facts– investigate what is not known– decide whether more information is needed– identify contradictory information

Devise a planCarry out the planReview the solution

Page 278: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.23

Debugging ProcessIdentifying the fault

– avoid making assumptions– only output is relevant– errors can escalate– visualise the problem

Construct a theory for causeDevise a solutionCarry out solution

– change code– testing– implementation

Page 279: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.24

Robust and Reliable Software

Reduce the time spent on maintenanceEasier to test a programSoftware house public image

– robust and reliable software is a measure of organisational capability and maturity

Page 280: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Testing - 9.25

Summary

Documentation of testsLevels of testingDesk checking and dry runningDiagnostic aids during compilation or run timeTypical facilities during interactive debuggingProgram maintenance including problem solving

Page 281: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.1

International Diploma in Computer Studies

Session 10Alternative Methods – 1

Programming Methods

Page 282: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.2

Contents

PatternsThe unified processRe-factoringDesign by contractClass librariesVisual programmingJava beans

Page 283: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.3

Introduction

New ways to improve the speed and quality of software productionOO programming reaching a critical mass

– practitioners, languages and applicationsHow to improve upon OOP usage and utilisethe productivity the technique has long promised

Page 284: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.4

Patterns

Describe ways of doing thingsSoftware frameworks recorded using software design patternsPattern booksCapitalise on knowledge and capability of others

Page 285: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.5

Design PatternsProvide common vocabularyExplicitly capture expert knowledgeImprove developer communicationsPromote ease of maintenanceProvide a structure for change

butWork is needed on how to define and apply patternsAppear simpler to use than is the case and need careful selection

Page 286: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.6

The Unified Process

Lifecycle model to use with UMLIterative and incrementalTakes account of riskSmall, progressive steps

– plan– specify, design and implement – integrate, test and run– obtain feedback before next iteration

Page 287: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.7

UP Phases and WorkflowsFour main phases

– Inception– Elaboration– Construction– Transition

Each phase has five workflows– Requirements– Analysis– Design– Implementation– Test

Page 288: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.8

Re-factoring

Process of rearranging an object design to make it more flexible and/or reusableInheritance or compositionUse small steps

– find the smallest useful change you can make– make it– test the system

Page 289: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.9

Design by Contract

A software system is viewed as a set of communicating components whose interaction is based on precisely defined specifications of their mutual obligations

– i.e. contractsAssertions take the form of

– pre-conditions– post conditions– invariants

Page 290: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.10

Class Libraries

Objects created by OO programmers and gathered into classes for general disseminationDevelopers more productive because they do not have to start programming from scratchBut finding the right code is time consumingMajor software providers make software libraries available, which can be found on the Internet

Page 291: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.11

Visual Programming

Programming is accomplished using visual techniques

– sketching– pointing– demonstrating

Classified according to the type and extent of visual expression used

– icon-based languages– form-based languages – diagram languages

Page 292: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.12

Visual Programming –Advantages

Fewer programming concepts ConcretenessExplicit depiction of relationships Immediate visual feedback

Page 293: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.13

Java Beans

Components designed to be used within an application or an appletIntrospectionCustomisationEventsPropertiesPersistence

Page 294: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 1 - 10.14

Summary

Emerging ways of software development such as

– patterns– the Unified Software Development Process, – re-factoring– design by contract

Emerging development aids including – Java beans – visual programming

Page 295: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.1

Session 11Alternative Methods – 2

Programming Methods

International Diploma in Computer Studies

Page 296: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.2

Contents

Application Program Generators– Features of a 4GL– Development of Application Generators

DBMS and the Database Query Language– Organisation of Data– File Management Systems– Database Models– Database Management Systems– Query Language

Client server computing

Page 297: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.3

Application Program Generators

Software system that produces a computer program in response to a user's needs4GLs - non-procedural languages

– i.e. users specify what a program must do, rather than how to do it

Page 298: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.4

4GL Features

Define data – input, validation processing

Define required output – data format and layout

Define processing requiredSelect combinations of standard processing operations

Page 299: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.5

Development of Application Generators

Two main areas of developmentThe domains in which the created application will workThe type of user of the application program generator

– initially programmers – more recently end-users who have no or little

programming experience

Page 300: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.6

Report Wizards – 1

Page 301: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.7

Report Wizards – 2

Page 302: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.8

Report Wizards – 3

Page 303: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.9

Report Wizards – 4

Page 304: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.10

Application Generators

Allow users to specify a complete software applicationA further development has been in the area of applications for the World Wide Web

Page 305: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.11

DBMS and the Database Query Language

Organisation of dataFile management systemsThe introduction of databasesRelational databasesDatabase management systemsQuery languageDatabase design

Page 306: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.12

Organisation of Data

Data redundancyData integrityData dependency

Page 307: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.13

File Management Systems –Limitations

Lack of data integration leading to data redundancyLack of data integrityData dependence of programs

Page 308: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.14

The Introduction of Databases

Single organised collection of structured data, stored with minimum of duplication of data items so as to provide a consistent and controlled pool of dataThe data is common to all users of the system but is independent of the programs which use itThe software used to create and use databases is called a Database Management System (DBMS)

Page 309: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.15

Database Models

HierarchicalNetworkRelational

Page 310: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.16

Relational DatabasesPersonnel Table

Employee Number Name Address Telephone Position

(Relation)

Employee Number Salary Pay YTD Deductions YTD106 20,000 12,000 3,000

106 B. Hall 12 Hill St 56723 trainee

Salary Table

Table - relation - fileTuples - recordsAttributes - fields

Page 311: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.17

DBMS – 1

Comprehensive software tools for manipulating an integrated base of business data to produce management informationFunctions

– data independence– establish relationships among records in different

tables– eliminate data redundancy– define the characteristics of the data– manage file access– maintain data integrity

Page 312: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.18

DBMS – 2

Data Manipulation Language (DML)– used to access data

Data Description Language (DDL)– used to define the data in the database

Data dictionary– what, where, descriptions, ownership, access, how

used, relationships, limitationsTransaction log

– used to ensure a change made to the database is completed fully

– used to backup databases and rebuild damaged files

Page 313: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.19

Query Language

Allows managers to use everyday language to obtain information on demandSQL

– a language designed for retrieving information from relational databases

Page 314: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.20

Database Design

Logical design – represents what the data is, i.e. from a

business perspective– two viewpoints

schema sub-schema

Physical design – how it operates i.e. technical perspective

Page 315: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.21

Client Server Features

A single application can be divided into self-contained tasksTasks can be performed by different machinesOne of the machines will be a PC or intelligent workstation

Page 316: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.22

Client Server Computing –Optimisation

Server component responsible for data storage and management

– optimised for data integrity, security, and transaction performance

Client component is responsible for presenting information to the user

– optimised for presentation and ease-of-use

Page 317: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.23

Client Server Computing

Advantages– reliability– cost

Disadvantages– security of data– uneconomical use of storage

Page 318: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Alternative Methods – 2 - 11.24

Summary

More established, yet still evolving tools and techniques for programmers

– application program generators– database management systems – database query language – client server computing

Page 319: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.1

International Diploma in Computer Studies

Session 12Implementation

Programming Methods

Page 320: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.2

Contents

Traditional systems lifecycleDevelopment lifecycle models and increasing sophistication in model developmentNeed for documentation and coding standardsAttributes of good documentationElements of documentationTechniques of documentationProgrammer’s role

Page 321: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.3

Introduction

The objective is to produce good softwareTo achieve this requires

– positive effort to record clearly i.e. document, all key aspects of construction (especially programming)

– an organised and methodical approach to the development process

Page 322: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.4

Standardised Documentation

Provides managers with documents to review at significant milestonesRecords technical informationProvides a guide to follow in preparing and checking documentation

Page 323: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.5

The Traditional Systems Lifecycle

Initial studyRequirements analysisSystems analysisDesignCodingTestingImplementation and support

Page 324: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.6

Initial Study

A brief description of the proposed system – which could include the hardware and software

specifications

An estimate of the project costA possible completion date for the work

Page 325: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.7

Requirements Analysis

Evidence of a clear understanding of the proposed system between the user and the developerA list of existing and new tools, available facilities, and personnel for developing the solutionA schedule for the stages of the project with deliverables for each stage

Page 326: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.8

Systems Analysis

Description of– the inputs to the process

– the operations the system performs for each input

– the output obtained for the corresponding input

Page 327: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.9

Design

Complex problems – divide into a set of subproblems

Programs and modules – define in terms of inputs, outputs, required functions

and processes

Select data structures and algorithms for implementation of input and output data and system functionsPrograms developed internally, externally or both?

Page 328: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.10

CodingThe programs and modules need to be tested according to the system test plan, developed in the design phase

– carried out whilst the program is being created.This phase is complete when all the code has been written and documented, and compiled without errors

– system is then ready to be testedGood code is code which:

– works– is bug free– is readable and maintainable

Some organisations have coding standards which all developers are supposed to adhere to

Page 329: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.11

Testing

In the previous stage, modules were tested in isolationTest as a group

– interaction

Test in each environment Test by users in controlled environmentTest by users in live (or simulated live) environment

Page 330: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.12

Implementation and Support

Co-operation of developers and client staff (management, users, technical support)After installation, system kept operational and updatedBugs need tracking

– fixing, testing, regression testing

Page 331: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.13

Factors to be Considered in Problem Tracking

Completeness of information Bug identifier and statusApplication identifier and version Where the bug occurred Environment specificsTest case name/number/identifier and tester nameSteps needed to reproduce the bugFile/data/messages/etc. used in test File excerpts, error messages, log file, screen shots, testing logsSeverity estimate (e.g. grade 1 to 5)

Page 332: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.14

Software Development Lifecycle

SpecificationDesignImplementationTestingReview and maintenance

Page 333: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.15

Software Development Lifecycle Models

Waterfall V-Shaped Prototyping Incremental Spiral

Page 334: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.16

Waterfall Model

Consists of a series of phases through which a project progresses in a sequential order, and is the nearest in type and intention to the generic modelNo overlap between phasesEach phase must be completed before the project can progress to the next phase

Page 335: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.17

V-Shaped Model

Similar to the Waterfall Model but emphasises the importance of considering the testing activities at the outset instead of later in the lifecycleEach test phase considered in its matching development phase

Page 336: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.18

Prototyping ModelProcess of creating an incomplete model of the future program prior to or during the software requirements phaseThe client evaluates the prototype and provides feedback to the developers as to its strengths and weaknessesTwo major types of prototyping

– Throwawayultimately discarded, but can be produced quickly

– Evolutionaryvery robust, will form part of the system

Page 337: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.19

Incremental Model

Each stage adds additional functionality, and consists of

– design– code – unit test– integration test– delivery

Functional software delivered earlyCareful planning vital

Page 338: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.20

Spiral Model Risk-oriented model, particularly valuable for innovative projects where there is no track record of developmentEach spiral addresses major risksEach iteration involves six steps

– determine objectives, alternatives, constraints – identify and resolve risks – evaluate alternatives – develop deliverables and verify them– plan the next iteration– commit to an approach for next iteration

Page 339: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.21

Documentation and Coding Standards

Use of comprehensive and proven standardsAvoid ambiguity, duplication, omission and contradictionCode readability and maintainability A coding standard can only be feasible when followed throughout the software project

Page 340: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.22

Coding Standards

Names are important in helping to understand the logical flows of an application

– routines– variables

Comments– external– internal

Formatting of the code layout – emphasises logical organisation of code

Page 341: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.23

Documentation Attributes of good documentation

Complete and up-to-dateWell structured, with neither too much information nor too littleIndexedPresented in a standard form (which needs to be defined)

Types of documentation User documentation

– describes the functions of the system, without reference to how they are implemented

System documentation – includes all aspects of the system design, implementation and

testing

Page 342: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.24

User DocumentationEnd user documentation (manuals and guides)

– written by technical specialists with input from the systems analyst and the programmer

Three types of document, one for each person who is going to use the system after its completion

– operator– user – maintainer

User documentation can begin with the User Request which is the starting point for every software projectUser request is a written and approved statement of the nature and objectives of the project and in general it will

– state the problem– assess the feasibility– plan and schedule for implementation

Page 343: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.25

System Documentation

Development of the systems design documentation is usually performed by the systems analyst It requires the production of sub-set specifications

– overall system specifications– input/output specifications– program specification– tables of contents

Page 344: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.26

Module DocumentationLowest level of documentation outside the source code itself The most useful when the program needs to be maintained or improved at a later stage and it should include

– name and function of the module– list of routines called– input data, type, format and value range– local variables– description of algorithm– internal functions/procedures with global variables listed– data and program flowcharts– error handling; error types and action taken– the tests performed and their results

Page 345: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.27

Documentation – Techniques

FlowchartsOther chart formsDigital documentationMultimedia programsScreen grab tools can enhance documentation

Page 346: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.28

The Programmer’s Role

CodingTestingImplementationSupportIterative or prototyping approaches

– demonstrator interfaces

Role changing – software tools

Page 347: International Diploma in Computer Studies - … programming - PROLOG zObject ... – the building blocks are not nouns and verbs but ... – emphasises the importance of data in deciding

V1.1 © NCC Education Limited, 2007

Implementation - 12.29

Summary

Traditional systems lifecycle A variety of software development lifecycle models and an indication of increasing sophistication in model developmentThe need for documentation and coding standardThe attributes of good documentationThe elements of documentationTechniques of documentationThe programmer’s role