Unit 8 Programming
Unit 8 Programming
Programming concepts
Programming languages and IDE
which specifically state what type of data the variable or constant will
Concatenation
1. Number= int(“123”) Means joining together. It
2. Value = string(22) joins multiple pieces of data
with a comma
3. Print (“Hello world”)
4. Print (20)
5. Print (“Hello”, name)
6. Print (“There are”, Balloon, “balloons”)
7. Print (“Enter a word”)
input word
Programming Task
1. result= DIV(33,7)
2. Result = MOD (33,7)
MOD and DIV are the library
routines
Library routines
Inputs 3 numbers
Outputs the largest of the three numbers
[3]
Answer
INPUT a, b, c
IF a > b AND a > c THEN PRINT a [1]
ELSE IF b > c THEN PRINT b [1]
ELSE PRINT c [1]
Case Statements
INPUT score
CASE OF Score:
80:
Print (“A”)
75:
Print (“B”)
OTHERWISE PRINT (“u”)
ENDCASE
Programming TASK
What is iteration?
Iteration is the process of repeating a set of instructions
until a specific condition is met. It is an important
programming concept and is used to automate repetitive
tasks.There are three main types of iteration:
» Count-controlled loops (for a set number of iterations)
» Pre-condition loops – may have no iterations
» Post-condition loops – always has at least one iteration.
Count-controlled Loops
Example in Pseudocode:
REPEAT
INPUT guess
UNTIL guess = 42
Totalling
Totalling involves adding up values, often in a loop
A total variable can be initialised to 0 and then
updated within a loop, such as:
Counting
Counting involves keeping track of the number of
times a particular event occurs
A count variable can be initialised to 0 and then
updated within a loop, such as:
Programming Task
CAIE outline
Nested Statements
Procedures
A procedure just executes commands, such
as printing something a certain number of
times.
Function
A function produces information by receiving
data from the main program and returning a
value to the main program.
PROCEDURE
EXAMPLE
DEFINING AND CALLING FUNCTIONS
EXAMPLE
Differences between procedures and
functions