Worksheets 4 Asal It TR

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

Worksheet 4.1: Fill in the gaps


The following algorithm should take two values as input, then output the total when:
1 the two numbers are added together
2 the two numbers are multiplied together
3 the second number is divided by the first number
4 the first number is subtracted from the second number.

Complete the gaps in the algorithm below:

INPUT number1

INPUT …………………………………………………………….

total = number1 ……………………………………………………………. number2

multiply = number1 ……………………………………………………………. number2

divide = ……………………………………………………………./ …………………………………………………………….

subtract = number2 - ……………………………………………………………

OUTPUT total

OUTPUT multiply

OUTPUT ……………………………………………………………

OUTPUT subtract

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020


CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

Worksheet 4.2: Trace the algorithm


Complete the trace table for following the algorithm.
OUTPUT "Enter first name"
INPUT firstname
OUTPUT "Enter second name"
INPUT secondname
namelength = firstname.length + secondname.length
OUTPUT "There are " & namelength & " letters in" & (firstname + " " +
secondname)

The value "James" is entered first and "Bond" is entered second.

firstname secondname namelength OUTPUT

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020


CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

Worksheet 4.3: Write a loop


Find the repeated code in the following algorithm, and re-write it using repetition.

INPUT value1
counter = 1
total = 0
total = total + value1
INPUT value1
counter = 2
total = total + value1
INPUT value1
counter = 3
total = total + value1
INPUT value1
counter = 4
total = total + value1
INPUT value1
counter = 5
total = total + value1
average = total / counter
OUTPUT average

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020


CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

Worksheet 4.4: People subroutines


Subroutines for six different students.

subroutine() subroutineOne()

jump up and down 5 times clap your hands 10 times

subroutineTwo() subroutineThree()

sit down Count from 1 to 10 out


stand up loud
sit down
stand up

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020


CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

subroutineFour() subroutineFive()

put your hands on your click your fingers 20


head times
put your hands on the
table

subroutineSix() subroutineSeven()

stand up clap your hands twice


sit down click your fingers twice
stand up clap your hands twice
sit down

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020


CAMBRIDGE INTERNATIONAL AS & A LEVEL IT

main program
subroutine()
subroutinesix()
subroutineone()
subroutinethree()
subroutineone()
subroutinetwo()
subroutinefive()
subroutinefive()
subroutineseven()
subroutineone()
subroutinefour()
subroutinefour()
subroutine()
subroutine()
subroutineseven()

Cambridge International AS & A Level IT – Ellis © Cambridge University Press 2020

You might also like