Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
ICT
Responsive image

LO 2 - Developing algorithms

Flowchart Symbols

A flowchart is a diagram that represents a set of instructions. Flowcharts normally use standard symbols to represent the different types of instructions. These symbols are used to construct the flowchart and show the step-by-step solution to the problem.

Flowchart Symbols

A flowchart is a diagram that represents a set of instructions. Flowcharts normally use standard symbols to represent the different types of instructions. These symbols are used to construct the flowchart and show the step-by-step solution to the problem.

Algorithm

Topic B - Standard methods and techniques used to develop algorithms

To see the BCS convention for Pseudo code click on the button below

BCS Pseudo code

Introduction

In Chapter 3 we saw the importance of sequences. In this chapter we will explore ways of representing these sequences.

In most programming languages, these structures take the form if … then … else. Our game of rock, paper, scissors also contained repetitions: when the game was over, it started again. Another name for this is a looping structure (a list of instructions to do more than once). You write this type of program to make the computer repeat a certain command or sequence of commands. The loop may run for a predetermined number of times, until a certain condition becomes true, or as long as a certain condition remains true.

You could tell the computer to:

  • do the following 20 times
  • do the following once for each word in the list
  • repeat the following until the user carries out a particular action.

Why design a program first?

To program correctly, you will need to consider program design (planning) and the actual program coding.

The name given to this planning is called control structured programming.

Structures: how things are broken down

At a basic level, structured programs comprise simple, hierarchical flow structures, which consist entirely of three types of logic structure:

  • sequence
  • selection
  • iteration

A sequence is where a set of instructions or actions is ordered, meaning that each action follows the previous action.

Using flowcharts

TThere are a lot of different design procedures and techniques for building large software projects such as a new database for a large organisation.

Basic elements of flowcharts

Responsive image
  • Basic structures

  • Responsive image
  • Sequence

  • A sequence is where a set of instructions or actions is ordered, meaning that each action follows the previous action.

    Responsive image
  • Looping / iteration

  • Iteration is where a statement is executed in a loop until the program reaches a certain state or the intended operations have been applied to every data element of an array. The diagram shows that the iteration / loop keeps on occurring until a false statement is reached.

    Responsive image
  • Top-down design

  • The best way to tackle the design of a program is to use top-down design. To do this you first map out the entire program and then identify the major components that it will require.

    Programmers then use flowcharts and general statements to represent the logical flow of the program. Once the major components have been identified, the programmer can focus on each component in greater detail.

  • Derived structures

  • As we have already suggested, all flowcharts can be represented by the basic structures shown above. However, on occasions, it is useful to use some additional structures, each of which can themselves be constructed from the basic structures above.

    Responsive image

    As you can see, the do-while structure is different from the while structure due to the process contained within the loop always executing at least once. This procedure is the same as if the process was performed once before going into a while loop. In the while structure it is possible that the process may never be executed. You should understand that although the while structure is often used, the do-while structure is sometimes used because it is more intuitive.

    Choosing between the two is hard, so let’s look at a few rules:

    • are you repeating or copying / pasting code you have already used?
    • Which way uses fewer lines of code? Normally fewer is better
    • There are times when using more lines of code is more efficient, but you should never repeat yourself when coding
  • While statements

  • While statements are efficient loops that will continue to loop until the condition is false. But you must be careful. While loops can create an infinite loop and infinite loops are not a good idea in a program. Computers can't tell if they're stuck in an infinite loop (unless you use PHP, which has a time-out limit).

  • Do-while statements

  • Do-while statements are also efficient loops that will continue to loop until the condition is false. They are identical to while statements except that they start with do and the while condition comes after the braces.

The Friendship Algorithm

Responsive image

Task - The friendship Algorithm

Your task is to turn the above flow chart into pseudo code

To see the BCS convention for Pseudo code click on the button below

BCS Pseudo code

Task - Snakes and ladders

Create a flowchart to show people how to play the game of snakes and ladders.

Pseudocode

The final step in analyzing a problem is to step from our flowchart to pseudocode. Pseudocode involves writing down all of the major steps you will use in the program as depicted in your flowchart. This is similar to writing final statements in your programming language without needing to worry about program syntax, but retaining the flexibility of program design.


Watch the following video on flowcharts and pseudocode



Task

Now, on your own, work through flowcharting, and pseudocode for the following example.

A cinema chain want a new machine that scans the ID of a user and outputs on the screen what film ratings they are able to watch from: 18 15 12A 12 PG U. It will also need to check if the person is with an adult if they are 12 or under

You have 30 minutes



  • Learning Objectives

  • I can interpret pseudocode and apply processes to calculate outcomes.
  • I can interpret pseudocode and evaluate the structure and logic of given code against given requirements.

Flowchart Symbols

A flowchart is a diagram that represents a set of instructions. Flowcharts normally use standard symbols to represent the different types of instructions. These symbols are used to construct the flowchart and show the step-by-step solution to the problem.



Copyright © 2013 - 2024 LearnITwithMrC