Design notation
Design notations are used when planning and should be able to communicate the purpose of a program without the need for formal code. Commonly used design notations are:
- Pseudocode
- Flow charts
- Structure chart
Pseudocode
When designing a program, it is useful to lay out how the program might work, before writing it in a programming language,.
Pseudocode is a design notation that is closely related to the logic of how a program will work. It lets you detail what your program will do without having to worry about the particular syntax of your chosen programming language.
There is no specific standard for pseudocode and programmers often have their own version. Pseudocode can look a lot like code but it does not need to be implemented as strictly.
Programming languages like python, reference language (used by the SQA) and visual basic will have specific rules around syntax and structure, whereas pseudocode gives more freedom.
There is no strict set of rules for pseudocode, but some of the most widely recognised are:
INPUT
– indicates a user will be inputting somethingOUTPUT
– indicates that an output will appear on the screenWHILE
– a loop (iteration that has a condition at the beginning)FOR
– a counting loop (iteration)REPEAT – UNTIL
– a loop (iteration) that has a condition at the endIF – THEN – ELSE
– a decision (selection) in which a choice is made
Pseudocode can be used to plan out programs. It is similar to actual code. Planning a program that asks people what their favourite subject is could look like this in pseudocode:
REPEAT
OUTPUT 'What is the best subject you take?'
INPUT user inputs the best subject they take
STORE the user's input in the answer variable
IF answer = 'Computer Science' THEN
OUTPUT 'Of course it is!'
ELSE
OUTPUT 'Try again!'
UNTIL answer = 'Computer Science'
A programmer who uses pseudocode as part of their planning is able to take time to think about how their program will work, what variables they might need and what inputs and outputs there are.
Flow charts
Flow charts show what is going on in a program and how data flows around it. Flow charts can represent everyday processes, show decisions taken and the result of these decisions.
The diamond shape explains when there is a choice to make. The flow chart shows what happens depending on the decision made at this point. Flow charts visualise the results of decisions, showing what will happen in a program, and also when, for example an if statement, is required to make a decision.
Flow charts can be used to show iteration (repeating something).
In the above flow chart, the user is asked what their favourite subject is. If they answer 'Computing Science' they are told they are 'clearly very intelligent' and the program stops.
Any other answer results in the user being asked again. If the user does not enter 'Computing Science', the program will keep going round and round, asking them forever until they enter Computing Science.
Structure diagrams
Another way of representing a program design is to use a structure diagram. Structure diagrams break down a problem into smaller sections. These smaller sections can then be worked on one at a time.
This can be good for big projects where a large problem can be split into smaller tasks for separate groups, or individuals, to work on.
Below is an example of how a structure diagram might be used to break a large problem down.
This shows how you can take a complex problem and start breaking it down into more manageable chunks.
In reality, a complex project like building a house would have many more stages, but this example shows that structure diagrams can help to break down problems when designing a program.
You would most likely use a structure diagram if you were designing a game and wanted to break down the overall design problem into individual elements.
Algorithms
An algorithm is a step-by-step procedure for solving a problem in a finite number of steps. It is essentially some code that accomplishes a certain task.
For example, algorithms might:
- check data has been entered correctly
- test if a number is even
- calculate a person's salary
- convert a piece of text from lower case to upper case
Any bit of written code that carries out a specific task could be said to be an algorithm.
Input Validation algorithm
Input Validation means making sure a piece of data is correct. You might want someone to enter their age into your program and check that the value they enter is sensible.
You might therefore check that the value they enter is between 0 and 130. Anything outside that range will be flagged up to them as not sensible and they would then be asked to enter an appropriate value. This type of validation is often used when people fill out forms online.
Validation is such a common occurrence in programming that a standard algorithm exists.
No comments:
Post a Comment