Author: Mr Stratton

Computing teacher and a PT at Coltness High School.

National 5 – Low-level operations and computer architecture (Revision)

Units of storage:

8 bits = 1 byte
1024 bytes = 1 Kilobyte
1024 Kilobytes = 1 Megabyte
1024 Megabytes = 1 Gigabyte
1024 Gigabytes – 1 Terabyte
1024 Terabytes = 1 Petabyte

Translation of high-level program code to binary (machine code):

  • interpreters – translates source code to machine code line by line, spots errors more easily but takes longer.
  • compilers – translates the source code to machine code in one step, does not spot errors as line being typed, but more efficient. Creates a run time version (object code) that can’t be edited.

Use of binary to represent and store:

  • Real numbers uses mantissa & exponent – 0.256 X 105
    Mantissa = 256 Exponent = 5
  • Characters – ASCII allocates a different binary code to each letter, A = 00100001
  • Instructions, machine code – Binary instructions the processor can understand 10101011101
  • Graphics bit-mapped and vector
    • Bit-mapped graphics are made up of pixels
    • Vector graphics are described in text <rect width=”300″ height=”100″ style=”fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)”>

Basic computer architecture:

  • Processor (CU Ah Luv U Right)
    • Registers – temporary storage locations holding data being processed
    • ALU – deals with comparisons and arithmetic calculations
    • control unit – controls all other parts of the processor, ensures instructions are carried out in the correct order
  • Memory
    • Random Access Memory – temporary data storage only held as long as the computer is switched on.
    • Read only memory – Permanent memory not lost when the computer is switched off, can’t be changed.
  • Buses
    • data – carries data to and from the processor, memory and other devices. Bi-directional
    • address – carries address info from processor to the memory.
    • control – made up of a number of separate wires.
  • Interfaces
    • allows a processor to send and receive data to and from peripherals like printers, scanners, keyboards and projectors.
    • Bluetooth – Wireless
    • USB – Wired

Higher – Design Notations (Revision)

Make sure you read the N5 post on design notations for examples of Structure Diagrams, Flow Charts and Pseudocode.

Wire-Framing: A wireframe can show how a website will look and how its navigations structure works; can be as simple as a rough sketch or can be a detailed design showing colour combinations and images

Entity Relationship Diagrams

Relationships can be represented graphically using an Entity-Relationship (ER) diagram.

There are many different notations for ER diagrams, we will use crow’s foot notation.
• The names of entities are written in boxes joined by straight lines.
• At the “many” end the line forks.
• At the “one” end the line it judt joins the box.

ERD

Data dictionaries

A data dictionary is a design notation used to show the fields required in each table of a relational database, including field types, validation required, etc.

dd

Thank you to C O’Toole & A Madill from Braidhurst High School for allowing me to edit and publish this here.

National 5 – Design Notations (Revision)

N4

  • graphical to illustrate selection and iteration
  • other contemporary design notations

N5

  • pseudocode to exemplify programming constructs other contemporary design notations

 

Flow Chart
Flow Chart

You read a flow chart from the START block and follow the arrows (normally downward). In the example above you can see selection taking place in the first diamond, while the second diamond allows for iteration (repetition) to take place.

Structure Diagram
Structure Diagram

A structure diagram shows how the program is structured and in some cases how data can be passed from one part to the other.

Pseudocode

Pseudocode is an informal text description of the working of a program it is written using English words but not in a sentence structure. There are no syntax rules due to its informal nature, sometime they are numbered and sometimes they are not.

The SQA can sometimes refer to pseudocode in the exam when describing a program. However, they are often referring to Standard Reference Language. Rule of thumb, if they are asking you to read pseudocode it will be SRL, if they are asking you to write psuedocode then they mean psuedocode. Hopefully they will start using the correct terms in future papers.

Example 1

  1. set total = 0
  2. set count =0
  3. while count less than 10
  4.     get nextInput from user
  5.     add nextInput to total
  6.     add one to count
  7. end while
  8. display total/10

Example 2

get age from user
while age < 0 or age >130
    display error
    get age from user

display age

Higher – Algorithm Specification (Revision)

Input Validation: making sure that the data input by the user is acceptable e.g. in a suitable format and within the upper and lower limits of the data required by the software

RECEIVE userInput FROM (INTEGER) KEYBOARD
WHILE userInput < lowerLimit OR userInput > uperLimit DO
    SEND “Input must be between” & lowerLimit & “and” & upperLimit TO DISPLAY
    RECEIVE userInput FROM (INTEGER) KEYBOARD
END WHILE

Linear Search (efficient): sets a Boolean variable to false initially and uses an unconditional loop to set it to true when the item is found; the loop terminates when the item is found or the end of the array is reached

RECEIVE itemToFind FROM (INTEGER) KEYBOARD
SET found to false
SET arraySize to higestIndex
SET counter TO 0

WHILE counter <= arraySize AND found = false
    SET counter to counter + 1
    IF array[counter] = itemToFind THEN
        found=true
    END IF
END WHILE

IF found = true THEN
    SEND itemToFind & “found at position” & counter TO DISPLAY
ELSE
    SEND “Item not found” TO DISPLAY
END IF

Finding Minimum: sets an initial value to the first item in the array then compares it to the remaining items

SET maxiumValue to numbers[0]

FOR counter FROM 1 TO 9 DO
    IF maximumValue < numbers[counter] THEN
        SET maximumValue to numbers[counter]
    END IF
END FOR

SEND “The largest value was” & maximumValue to DISPLAY

Finding Maximum: sets an initial value to the first item in the array then compares it to the remaining items

SET miniumValue to numbers[0]

FOR counter FROM 1 TO 9 DO
    IF minimumValue > numbers[counter] THEN
        SET minimumValue to numbers[counter]
    END IF
END FOR

SEND “The smallest value was” & minimumValue to DISPLAY

Count Occurrences: sets a total to zero at the beginning and increments it as items are found to match the search item

RECEIVE itemToFind FROM (INTEGER) KEYBOARD
SET numberFound to 0

FOR EACH number FROM numbers DO
    IF number=itemToFind THEN
        SET numberFound to numberFound+1
    END IF
END FOR EACH

SEND “There were” & numberFound & “occurreneces of” & itemToFind & “in the list” TO DISPLAY

Thank you to C O’Toole & A Madill from Braidhurst High School for allowing me to edit and publish this here.

Higher – Testing and Documenting Solutions (Revision)

  •  Constructing a Test Plan: A set of test data which has been created to systematically and comprehensively to test the software; makes use of the following test data
    • normal – ensures the program works when used normally
    • extreme – ensures the program works when data is used that is on the boundaries of what is considered normal
    • exceptional – ensures a program can handle situations that it has not been designed to cope with; out with the boundaries
  • Comprehensive Testing: when every aspect of the software is tested
  • Syntax Error: a misspelling of a keyword or mistake in the structure of a program such as missing an ‘end if’
  • Logic Error: program will run but not as the programmer intended it to; for example when calculating the average it should be (a+b)/2 instead of a+b/2
  • Execution Error: an error occurs when the program is run, causing it to crash
  • Dry Runs: manual run through of pseudocode or source code of program, taking notes of the values of variables at various points in the process
  • Trace Tables: similar to the table used during a dry run but is often used to test an algorithm for a specific sub program
  • Breakpoints: a set point in a program where it will stop execution so that the values of variables can be examined

Thank you to C O’Toole & A Madill from Braidhurst High School for allowing me to edit and publish this here.

National 5 – Algorithm Specification (Revision)

Input validation – checking that what is entered by the user is acceptable.

The following program checks that age is a positive number.

1. SEND “Please enter age” TO DISPLAY
3. RECEIVE age FROM (INTEGER) KEYBOARD
4. WHILE age < 0 DO
5.         SEND “re-enter data” TO DISPLAY
6.         RECEIVE age FROM (INTEGER) KEYBOARD
7. END WHILE

Note that acceptable does not mean accurate, just sensible.

Higher – Reading Standard Reference Language

I would like to remind you that there is no requirement to write answers using Standard Reference Language (SRL). The SQA can sometimes refer to Standard Reference Language as “Pseudocode”, however, as I have previously explained this is not the case. Pseudocode is an informal design that explains a programs function using English like structure.

Examples

Read in a number representing a temperature in degrees Celsius and write it out as a value in degrees Fahrenheit. If the Celsius value is c, then the Fahrenheit value, f, is calculated as follows: f = ( 9 / 5 ) * c + 32.

RECEIVE c FROM (INTEGER) KEYBOARD 
DECLARE f INITIALLY ( 9.0 / 5.0 ) * c + 32 
SEND f TO DISPLAY

Read in 10 numbers and write out the average of those numbers.

DECLARE total INITIALLY 0 
DECLARE count INITIALLY 0 
WHILE count < 10 DO 
    RECEIVE nextInput FROM (INTEGER) KEYBOARD 
    SET total TO total + nextInput 
    SET count TO count + 1 
END WHILE 
SEND total / 10.0 TO DISPLAY

When reading SRL start at the top, working down each line. Take a note on scrap paper of the values given to variables. In SRL constructs start with their NAME and finish with an END and their name. Subprograms can either be a PROCEDURE or FUNCTION, these are named and have parameters (arguments) in parenthesises, functions will have one or more RETURN statements.

Tips

  • If you are asked for the results of the program then pay attention to the IF statements to make sure that you branch the program correctly. Check the number of repetitions on loops as well.
  • If you are asked to spot an error in the code it will more than likely be a logical error rather than a syntax error.

There is an online Haggis (SRL) checker here, remember you don’t need to write SRL just read it.

National 5 – Testing and documenting solutions (Revision)

Test Data

For an exam out of 100

  • Normal (data within expected range) – 78, 45,67, 85, 44
  • Extreme (data at limits of expected range)– 0, 100
  • Exceptional (data out with expected range) – -89, bob

Errors

  • Syntax – The rules of the programming language have been broken. E.g. a typing mistake Displya rather than Display
  • Execution – using Average = total / 0 would give an execution error.
  • Logic –will only show up when you run the program. Please see below

counter = 0
while counter < 0:
counter = counter + 1

Readability of code

  • Internal commentary – information about what the program does written by the programmer alongside the actual code. #Green in python.
  • Meaningful identifiers – Calling variable names that mean something length or height rather than L or H
  • Indentation starting parts of the code slightly into the middle of the page making it easier to read.

Higher – Data Types and Structures (Revision)

  • String: text (str)
  • Integer: whole numbers (int)
  • Real: decimal numbers (float)
  • Boolean: one of two possible values e.g. True/False
  • 1-D Arrays: two or more values of the same data type stored in the same construct
  • Records: two or more values of different data types stored in the same construct
  • Sequential Files: text files that can be opened, closed, read from, written to, created or deleted; identified by a path and filename which is treated as a STRING e.g. “n:\myfiles\testfile.txt” would identify the file testfile.txt in the folder n:\myfiles.

 

Thank you to C O’Toole & A Madill from Braidhurst High School for allowing me to publish this here.

National 5 – Data types and structures (Revision)

String – text variable like name
Integer – a whole number used for numberOfPeople or items
Real – contains decimals used for distances or measurements
Graphical objects – pictures
Boolean variables – True or False
One Dimensional (1D) arrays – used for a data structure with many pieces of data all of the same data type, such as a list of names. Pupilname[20]