Programming Principles

Exam Board:

Eduqas / WJEC

Specification:

2016 + 

Problem Solving

There are four stages to computational thinking (smart problem solving).

Decomposition is when you break a problem down into smaller tasks so that it is easier to solve.

Pattern Recognition is the process of identifying similar patterns within a problem.

Abstraction is when you ignore unnecessary information and focus only on the important facts.

Algorithms are the final stage as step-by-step rules are created to solve the problem. An algorithm is usually written as psuedo-code or presented as a flowchart.

Programming Constructs

There are three constructs (ideas) of programming that most programs will contain:

Sequence

Structuring code into a logical, sequential order.

Selection

Decision making using if statements.

Iteration

Repeating code using for or while loops.

Variables

Large programs are often modular - split into subroutines with each subroutine having a dedicated purpose.

 

Local variables are declared within a specific subroutine and can only be used within that subroutine.

Global variables can be used at any point within the whole program.

Local variable advantages

  • Saves memory - only uses memory when that local variable is needed - global variables use memory whether they are used or not.

  • Easier to debug local variables as they can only be changed within one subroutine. 

  • You can reuse subroutines with local variables in other programs.

Global variable advantages

  • Variables can be used anywhere in the whole program (and in multiple subroutines).

  • Makes maintenance easier as they are only declared once.

  • Can be used for constants - values that remain the same.

Local & Global Variables

Constants

A variable is data that can change in value as a program is being run.

A constant is data that does not change in value as the program is run - it is fixed and remains the same.

An example of a constant in maths programs is pi - it will constantly remain at 3.14159 and never change.

π

π

Counts & Rogue Values

When using iteration (looping) the loop must eventually be able to stop. A count is a variable that is used to record the current iteration (loop number).

A rogue value is an unexpected value that will cause the loop to end. For example by typing "Stop" into a loop that asks for numbers.

Self-documenting Identifiers

An efficient program will use variables with sensible names that immediately state their purpose in the program.

Using variable names like 'TotalNum' and 'Profit' rather than 'num1' and 'num2' mean that other programmers will be able to work out the purpose of the code without the need for extensive comments.

Object-Oriented Programming (OOP)

Java is an example of object-oriented programming (OOP) where a programmer is able to code objects that can be visually placed onto a background. Greenfoot is an IDE for Java that you should recognise and must be able to code in.

You need to know some OOP keywords and be able to recognise them.

Superclass

A class from which other 'subclasses' will inherit characteristics; e.g. hippos, crocodiles and polar bears will inherit properties from the Animals superclass.

Object

A single object from a class; e.g. one crocodile object from the Crocodile class.

Class

A set of objects which share the same properties; e.g. all PolarBears will behave in a similar way.

Comment

Two / symbols will allow you to write a comment to explain the code.

Method

A series of instructions that an object will follow. The act() method will loop in Greenfoot when the play button is pressed.

Questo's Questions

Programming Principles:

Problem Solving

1. What is meant by 'decomposition'? Why is it important? [2]

2. What does the term 'abstraction' mean? Why is it important?  [2]

3. What is pattern recognition?  [2]

4a. What is an algorithm? [1]

4b. What are the two ways of writing an algorithm?  [2]

Programming Constructs

1. Describe and draw a diagram for the 3 programming constructs. [6]

Variables

1. What is the difference between local and global variables? [4]

2. Describe two advantages of using local variables. [2]

3. Describe two advantages of using global variables. [2]

4. What is a constant? Give an example. [2]

5. Why is it important to use self-documenting identifiers when programming? [2]

6. What is a count? What is a rogue value? [2]

Object Oriented Programming

1. Describe each of the following object oriented programming (OOP) key terms:

     a. Class [2]

     b. Superclass [2]

     c. Object [2]

     d. Method [2]

© CSNewbs 2020