Category: Software Design & Devlopment

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.

National 5 – Computational Constructs (Revision)

Expressions to assign values to variables

Number=0

Expressions to return values using arithmetic operations (+ – * / ^ mod)

Average=total/5

Execution of lines of code in sequence demonstrating input – process- output

1. SEND “Enter First Number” TO DISPLAY

2. RECEIVE first_number FROM (INTEGER) KEYBOARD [input]

3. SEND “Enter Second Number” TO DISPLAY

4. RECEIVE second_number FROM (INTEGER) KEYBOARD [input]

5. SET total TO first_number + second_number [process]

6. SEND total TO DISPLAY [output]

Expressions to concatenate strings and arrays using the & operator

Bob Smith is an example of concatenation

 

firstName=”Bob”

secondName=”Smith”

print(firstName + secondName)

 

BobSmith

Use of selection constructs including simple and complex conditional statements and logical operators.

This is a simple statement as there is one conditions

1. IF pupil_mark >=50 THEN

2.    SEND pass message TO DISPLAY

3. ELSE

4. SEND fail message TO DISPLAY

5. END IF

 

This is a complex statement as there are two conditions

1. IF pupil_mark >=50 AND assessments_mark = 100 THEN

2.     SEND pass message TO DISPLAY

3. ELSE

4.      SEND fail message TO DISPLAY

5. END IF

Iteration and repetition using fixed and conditional loops

Fixed loop below as it will loop a fixed number of times depending on the users answer

number=int(input(“How many smart phones?”))

total=0.0

for phone in range(number):

                Name=input(“Please enter the name of the smart phone:”)

                cost=float(input(“Please enter the cost of the smart phone:”))

                total=total + cost

print(“Total cost = “,total)

 

Below is a Conditional Loop as it depends whether the user has any money left.

money=int(input(“Please enter your pocket money in £”))

while money>0:

    name=input(“Please enter the name of the CD you want to buy”)

    cost=float(input(“Please enter the cost of the CD”))

    money=money-cost

print(“You have ran out of pocket money”)

Pre-defined functions (with parameters) – round(22.34 ) will round numbers 22.34 becomes 22 or sqrt(4) will get the square root 2, or 9 will become 3.

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.

FizzBuzz

So I was reading a programming blog from a few years ago that was asking, why can’t programmers.. program?. The article set a challenge to

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Now technically the answer to the puzzle uses nothing more than Nat 5 constructs, so can you code a Python solution? Share it here if you get a nice one

(hint after the jump)

Read more

Higher – SSD Functions

Still a lot of confusion over the  definition of a function and procedure in Higher Computing Science and how they differ.

A procedure is a sub program that contains a block of code. It uses parameters to pass data to and from the main program.

A function is a sub program that contains a block of code. It uses parameters to get data from the main program and passes back a single piece of data using RETURN.

In the program below you can see a procedure called calcArea and a function called funcArea. Both of these sub programs do the same thing but they way the work is different. The last two lines of code could be merged into

MsgBox(“Function Area =”  & funcArea(10,11)).

The procedure is always called on it’s own. Can you name another function shown in the program below?

 

functions

 

Higher – Revision for Friday 18th of March

Please look over the following SSD areas

Be able to name and describe how the following standard algorithms work.

  • Linear Search
  • Input Validation
  • Find Maximum
  • Count Occurrences
  • Find Minimum
  • Reading from a file

Describe how the following translators work

  • Interpreters
  • Compilers

Differences between high and low level languages

How to use a subprogram

Use of parameters in subprograms

Differences between functions and procedures

 

Creating the binary background

I’ve changed my background from a stock internet photo to one I created myself.

First of all I wrote a little python program that generated a random 0 or 1

1
2
3
4
5
6
7
import random
message=""
for item in range(3000):
    number=random.randint(0,1)
    message=message + str(number)

print(message)

 

blueBinaryI then took a screenshot of the resulting console window and cropped it with IrfanView. I made a negative of the image and swapped the RGB colours before saving it as a PNG file.

I then uploaded the file and set it as a time background, it needs a little crop as it’s a couple of pixels too wide on one edge.

I’m sure you can think of a way that you could use this technique to create even better backgrounds with patterns or hidden messages.