A Level Computing#BristolMet
Session Objectives#U2 S2
MUST describe the steps of an algorithm using a program flowchart
SHOULD explain the data types and basic program constructs required for a given program
COULD create a simple one function calculator in Javascript
Create a multiple function calculator with end or continue screen.
A Level Computing#BristolMet
Keywords
Selection
Data TypesVariables & Constants
Algorithm Sequence
Iteration
A Level Computing#BristolMet
Planning a programmeBefore attempting to write a programme, the solution needs to be planned. This helps the coder to see what they want to achieve and how they can best achieve it by breaking the problem down into logical steps.
Methods for planning a programme solution include the use of the flow charts and pseudocode.
FLOW CHARTS – the following symbols are used
START STOP
Area = Width x Height
Start or Stop a programme
Represent a process i.e adding
Represents input or output values
A decision symbol i.e Yes or No, or a choice of paths
START
STOP
Input Width
Input Height
Output Area
What will this programme do?
A Level Computing#BristolMet
Flow ChartsSimple flow chart with decision symbols.
START
Check the weather outside
Is it raining
?
Wear waterproof
trousers
Don’t wear waterproofsSTOP STOP
IF Yes
Else No
TASK 1: Create a flow chart for making a cup of coffee.
A Level Computing#BristolMet
3 basic program constructs
RECAP:
Can you remember what the 3 basic program constructs are?
Sequence IterationSelectionTASK 2: Prepare to explain the program constructs needed in your coffee program
A Level Computing#BristolMet
Data Types (Variable Type)In databases we already know that the software needs to know what type of data is being held in each data field. This is known as the field type.
Similarly when writing programs it is necessary to understand the type of data that will be held by the variables used in the program.
The reasons are the same as databases:i) It provides limited validation of dataii) Certain operations can only be performed on certain data types (NB: the
prompt() command in Javascript is set to string therefore it cannot automatically perform mathematical operations )
iii) Memory can be efficiently allocated to store data.
A Level Computing#BristolMet
Data Types (Variable Type)For this course, the data types you need to know about are:• Integer• Floating Point• Real• Boolean • Character • String
TASK 3: In your course folders, make notes on each type giving examples.
Data Types Resource - Teach-ICT
TASK 4: Prepare to discuss the variable types which could be used for your coffee program.
A Level Computing#BristolMet
Creating a coding solution
TASK 4: Now create a flow chart for a program that will add any two numbers and give the result.
ANSWER:
Answer = N1 + N2
START
STOP
Input Number 1
Input Number 2
Output Answer
PseudocodeDeclare variables for number1, 2 and answer
Prompt input number1 and store as variable
Prompt input number2 and store as variable
Answer of number1 + number2stored as variable
Alert user of answer as message.
A Level Computing#BristolMet
Coded SolutionNow let’s code this solution.Remember javascript goes inbetween <script>…</script> tagsTIPS:Declare variables at the start of the programvar x,var y,
parseInt()This will convert the data type to an Integer. (NB prompts are treated as string)
Var1 = parseInt(prompt(‘Enter something here?’))
Notice the 2 bracketsneeded to close the 2
open bracketsAlert() To display output
A Level Computing#BristolMet
Multiple Function CalculatorTASK 5:
Create a calculator which can perform all 4 maths operations. You must design the solution first by creating a flow chart.
EXT: How could the efficiency of this program be improved??
A Level Computing#BristolMet
Flow Chart for 4 Operations Calculator
Answer = N1 + N2
START
STOP
Input Number 1
Input Number 2
Output Answer
Answer = N1 / N2
STOP
Input Number 1
Input Number 2
Output Answer
Answer = N1 * N2
STOP
Input Number 1
Input Number 2
Output Answer
Answer = N1 - N2
STOP
Input Number 1
Input Number 2
Output Answer
Which Calculator
If = +
If = - If = *
If = /
A Level Computing#BristolMet
Keywords
Selection
Data TypesVariables & Constants
Algorithm Sequence
Iteration