Â

## Problem Solving

This content is no longer updated!

2016 Eduqas Spec

2020 Eduqas Spec

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 pseudocode or presented as a flowchart.

A simplified example of using computational thinking is when you try to create a program but you get dozens of run-time errors that prevent your program from even starting.

The IDE debugger should tell you the specific lines that have errors to allow you to decompose the problem.

Next you can ignore all unnecessary information in the debugger except the line number and the error type.

You could look at previous programs you have made or search for the error type online to see if there is a pattern and how you (or others) have fixed the problem before.

Lastly, if it is a large program, you need to re-design a new solution with psuedo-code or a flowchart that summarises the new solution step-by-step.

The final stage of computational thinking is the creation of algorithms. Algorithms are necessary for a programmer to design a program before they start creating it. Two methods of creating algorithms are pseudocode and flowcharts. You need to be able to design programs using both pseudocode and flowcharts, using the proper conventions and symbols.

## Programming Constructs

Â

There are three constructs of programming; these are fundamental concepts that most programs will have.

Sequence

Structuring code into a logical, sequential order.

Selection

Iteration

Decision making using if statements.

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.

â€‹

• 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.

â€‹

• 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' means 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 can code objects that are 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 understand 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 Corner

Principles of Programming Questions:

Problem Solving

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

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

3. What is pattern recognition?

4. What are the two ways of writing an algorithm?

â€‹

Programming Constructs

1. What are the three constructs of programming? Describe each construct and draw the diagram. You will not be asked to draw the diagram in the exam but ti will help you remember what the construct is.

â€‹

Variables

1. What is the difference between a local and global variable?

2. Describe two advantages of using local variables.

3. Describe two advantages of using global variables.

4. What is a constant? Give an example.

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

6. What is a count? What is a rogue value?

â€‹

Object Oriented Programming

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

a. Class

b. Object

c. Method