Category: Revision

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

Higher – Computational Constructs (revision)

  • Parameter passing: used to pass data from one subprogram to another; can either be passed by value (data will not change) or by reference (changes to the data will be made)
  • Variable scope: where a variable can be used in a program; local (only inside the subprogram in which the variable has been created) or global (can be used in any subprogram)
  • Subprograms: named blocks of code which can be run from within another part of the program; often used to break a large program into smaller steps
    • Functions: a type of subprogram used to return a single value eg round, random
    • Procedures: a type of subprogram that will follow a set of given instructions
    • Methods: a function in an object-oriented language that is defined inside a class

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

Higher – Languages and Environments (Revision)

·         Low-level: language that a computer will understand; consists of 0s, 1s; examples include assembly code and machine code

·         High-level: language that a human will understand; use of English words such as repeat, if, loop, put

·         Procedural: code will processed logically and in a set order; passes data from one procedure to another using parameters

·         Declarative: consists of a knowledge base of facts and rules that can be queried

·         Object-Oriented: objects are created using classes that will contain code and data (encapsulation); data associated is known as attributes and its values are known as states; sub-classes can inherit attributes from a pre-defined class

·         Interpreter: takes each line of source code, translates it into machine code then passes it to processor to carry out that instruction; it works its way through the program one line at a time

Advantages Disadvantages
A program will run even if it is not finished No copy of machine code is saved meaning the source code has to be translated every time taking longer
Easy to spot errors during the translation The process of translating the program slows down the running of it
Program will run as soon as the first line is translated You will need to have a translator program or you cannot run it

·         Compiler: reads the source code and translates the entire program into machine code once; machine code then saved and kept and doesn’t need to be further translated before run

Advantages Disadvantages
The machine code is saved so the program only needs to be translated once You have to wait until the code is complete and the errors have been fixed before the translation can be finished and the machine code is run
The user does not need a translator program to run the machine code therefore the program runs quicker Each time the program is changed it needs to be re-translated

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