Search Header Logo
Unit 9 Key Programming concepts T1 Data types

Unit 9 Key Programming concepts T1 Data types

Assessment

Presentation

Computers

10th Grade

Practice Problem

Medium

Created by

Michael Harrington

Used 1+ times

FREE Resource

26 Slides • 14 Questions

1

media

2

media

Objectives

• Understand and use data types: integer, real, char,

string and Boolean

• Declare and use constants and variables

• Use input, output and assignment statements

• Use arithmetic operators including MOD and DIV

• Use string handling functions

3

Fill in the Blank

4

Fill in the Blank

5

Fill in the Blank

6

media

Data types and operations

Unit 9 Key programming concepts

Starter

• What is a data type?

• How many can you name?

• An arithmetic operator is a symbol

that will perform an operation on numbers

• + is an example of an arithmetic operator

that uses two numbers, e.g. 5 + 2

• How many arithmetic operators can you name?

7

media

Data types and operations

Unit 9 Key programming concepts

Starter

• What is a data type?

The kind of values that can be used in a data item

• How many can you name?

integer, real / float, char / character, string, Boolean

• An arithmetic operator is a symbol that will perform

an operation on numbers

• + is an example of an arithmetic operator that uses

two numbers, e.g. 5 + 2

• How many arithmetic operators can you name?

+, -, *, /, ^, MOD, DIV

8

media

Data types and operations

Unit 9 Key programming concepts

IGCSE pseudo-code

• Throughout these lessons, computer code will be

written using IGCSE pseudo-code

• Sometimes the syntax may be different

or not possible in the programming
language you are studying

• Sometimes examples will

demonstrate a concept in a
real language – this will be
in Python unless
stated otherwise

9

media

Data types and operations

Unit 9 Key programming concepts

Using variables in a program

• You have probably used variables in many different

ways in programs you have already written

numberOfStudents ← numberOfStudents + 1
circleArea ← 3.142 * radius^2
WHILE NOT found…
answer ← 'Y'
OUTPUT studentName

• What are the data types of each of the

above variables?

10

media

Data types and operations

Unit 9 Key programming concepts

Data types

• Variables will typically be one of the following types:

• Integer, Boolean, real, char or string

• For the variables given, the data types would be:

numberOfStudents Integer

circleArea Real

found Boolean

answer char

studentName String

• The data type used will determine the amount of

memory that needs to be allocated for the variable

11

media

12

Match

Variables will typically be one of the following types:

Integer, Boolean, real, char or string

For the variables given, the data types would be:

numberOfStudents

circleArea

found

answer

studentName

Integer

Real

Boolean

Char

String

13

media

Data types and operations

Unit 9 Key programming concepts

Declaring variables

• Before using variables they should be declared

• Declaring a variable gets it ready for use in the program

• The data type is given to the variable – the programming

language (compiler) can check that it is being used correctly

• Examples of declaring and using variables

DECLARE sidesInShape : INTEGER
DECLARE name : STRING
sidesInShape ← 4
Name ← "Jody"

14

media

Data types and operations

Unit 9 Key programming concepts

Constants

• As well as variables, you can define constants

in a program

CONSTANT Pi ← 3.14157926535
CONSTANT VAT ← 0.2
CONSTANT MaxPlayers ← 6

• Constants are often shown in uppercase

• Words are separated with an underscore, e.g. MIN_AGE

• This is known as snake case

• Why declare a constant instead of a variable?

• Can a constant ever change its value?

15

media

Data types and operations

Unit 9 Key programming concepts

Constants

• Why declare a constant instead of a variable?

• This prevents the value from being changed accidentally by a

part of code

• It shows a programmer that the value should stay the same

throughout the program

• Can a constant ever change its value?

• A constant cannot be changed when the program is running

• A constant can be changed by a programmer before the

program is compiled or translated

16

media

Data types and operations

Unit 9 Key programming concepts

Input and output statements

• Most programs accept data from the user, process it

in some way, and output a result

OUTPUT "How many hours a night do you sleep?"

INPUT hoursPerNight

hoursPerWeek hoursPerNight * 7

OUTPUT hoursPerWeek

17

media

Data types and operations

Unit 9 Key programming concepts

INPUT statement

• In many high-level programming languages such as

Python, an input statement can have a prompt for
the user:

firstName = input("What is your name? ")

• This statement first displays the message “What is

your name?” and then waits for the user to enter
some text and press Enter

• The response is then assigned to the

variable firstName

18

media

Data types and operations

Unit 9 Key programming concepts

Arithmetic operators

• The operators +, -, * and / are used for addition,

subtraction, multiplication and division

• ^ is used for an exponent (power of)

• The operator DIV is used for integer division, also

known as quotient

• MOD (modulus) is used to find the remainder when

dividing one integer by another

• What is the result of the following operations?

• weeks 31 DIV 7

• daysLeft 31 MOD 7

19

media

Data types and operations

Unit 9 Key programming concepts

MOD and DIV

• weeks 31 DIV 7

• The variable weeks is assigned the value 4

• This is because 7 goes into 31 four times (remainder 3)

• daysLeft 31 MOD 7

• The variable daysLeft is assigned the value 3

• This is because the remainder after the division is 3

20

Multiple Choice

The operator DIV is used for integer division, also known as quotient

What is the result of the following operation?

weeks ← 31 DIV 7

1

3

2

4

3

7

4

31

5

38

21

Multiple Choice

MOD (modulus) is used to find the remainder when dividing one integer by another

What is the result of the following operation?

daysLeft ← 31 MOD 7

1

3

2

4

3

7

4

31

5

38

22

Multiple Choice

The operator DIV is used for integer division, also known as quotient

What is the result of the following operation?

digit ← 105 DIV 10

1

1

2

10

3

100

4

5

23

Multiple Choice

MOD (modulus) is used to find the remainder when dividing one integer by another

What is the result of the following operation?

remainder ← 105 MOD 10

1

1

2

10

3

100

4

5

5

10

24

media

Data types and operations

Unit 9 Key programming concepts

Orders of precedence

• Remember BIDMAS

• Brackets
• Indices
• Division
• Multiplication
• Addition
• Subtraction

• Calculate: x (5 – 2) + (16 – 6 / 2)

y 7 * 3 + 10 / 2

Are brackets needed in the first expression?

25

media

Data types and operations

Unit 9 Key programming concepts

Strings and numbers

• Strings and numbers used in calculations are

represented differently in binary

• The string "17" is represented in binary as

0011000100110111

• The integer 17 is held as in binary as

00010001

26

media

Data types and operations

Unit 9 Key programming concepts

Inputting numeric variables

• Inputs from the user are strings

• Therefore if you are inputting an integer or real

number, you have to convert it before it can be used
in a calculation

• This doesn’t matter when writing pseudocode for IGCSE, but it

is important when writing in a real language such as Python

OUTPUT "Please enter number of tickets required: "
INPUT tickets

• In Python:

tickets = int(input("Please enter number of tickets required: "))

This converts the string input into an integer

27

media

Data types and operations

Unit 9 Key programming concepts

Concatenating strings

Concatenating means joining together

• The + concatenate operator is used to join together strings

firstname "Rose"

surname "Chan"

fullname firstname + " " + surname

OUTPUT fullname

• What will be output?

• What will be output by the program?

x "6" + "3"

OUTPUT x

28

media

Data types and operations

Unit 9 Key programming concepts

Concatenating strings

firstname "Rose"

surname "Chan"

fullname firstname + " " + surname

OUTPUT fullname

• What will be output? "Rose Chan"

• What will be output by the program

x "6" + "3"

OUTPUT x

"63"

29

Multiple Choice

Concatenating strings

firstname ← “Revise"

surname ← “Hard"

fullname ← surname + " " + firstname

OUTPUT fullname

What will be output?

1

"ReviseHard"

2

"HardRevise"

3

"Hard Revise"

4

"Revise Hard"

30

media

Data types and operations

Unit 9 Key programming concepts

String handling functions

• What will be the values of a, b

and c below?

zooName "London Zoo"
a LEN(zooName)
b SUBSTRING(zooName,2,3)
c LCASE(zooName)
d UCASE(zooName)

Function

Example

Result

LENGTH(str) word "Algorithm" OUTPUT LENGTH(word) 9

SUBSTRING(str, start, length)

OUTPUT(3,6,word)

"orit"

LCASE(str)

LCASE(word)

algorithm

UCASE(str)

UCASE(word)

ALGORITHM

31

Match

Match the following substring starts with position 1

What will be the values of a, b and c and d below?

zooName ← "London Zoo"

a ← LEN(zooName)

b ← SUBSTRING(zooName,2,3)

c ← LCASE(zooName)

d ← UCASE(zooName)

a

b

c

d

10

ond

london zoo

LONDON ZOO

32

media

Data types and operations

Unit 9 Key programming concepts

Uppercase and lowercase

• In Python, a string can be converted to uppercase or

lowercase letters as follows:

phrase1 = "Good morning"
phrase2 = "HAPPY BIRTHDAY"
print(phrase1.upper())

#"GOOD MORNING"

print(phrase2.lower())

#"happy birthday"

• What is the output of the following program?

a "The quality of mercy is not strained."
b LENGTH(a) – 30
c SUBSTRING(a,1,b)
d SUBSTRING(c,1,LEN(c)-1)
OUTPUT d

33

media

Data types and operations

Unit 9 Key programming concepts

Using comments

• You should use comments in your programs:

• to describe the purpose of the program

• to state the author of the program

• to explain what the code does

• Pseudo-code comments start with a // symbol

• In Python, comments start with #

• In Java and C#, comments start with //

• In VB, comments start with '

• Comments are ignored when your program is

translated to machine code and executed

34

Match

Question image

Match the following

What is the output of the following pseudocode program?

a ← "The quality of mercy is not strained."

b ← LENGTH(a) – 30

c ← SUBSTRING(a,1,b)

d ← SUBSTRING( c, 1, LEN(c)-1 )

OUTPUT d

a

b

c

d

"The quality of mercy is not strained."

7

"The qua"

"The qu"

35

Multiple Choice

Question image

Arrays are fixed-length structures of elements of identical data type, accessible by consecutive index numbers. It is good practice to explicitly state what the lower bound of the array (i.e. the index of the first element) is because this defaults to either 0 or 1 in different systems.

Is an array a Data Structure or a Date Type?

1

Data Structure

2

Date Type

36

Multiple Choice

Question image

1D and 2D arrays are declared as follows (where l, l1, l2 are lower bounds and u, u1, u2 are upper bounds):

DECLARE <identifier> : ARRAY[<l>:<u>] OF <data type>

DECLARE <identifier> : ARRAY[<l1>:<u1>, <l2>:<u2>] OF <data type>

What type of brackets are used to indicate the array indices/indexes

1

Square

2

None

3

Round

4

curly

37

media

Data types and operations

Unit 9 Key programming concepts

Plenary

• give:

• 5 different data types

• 4 arithmetic operators

• 3 functions used for string operations

• 2 arithmetic operators used for integer division and remainder

• 1 concatenate operator

38

media

Data types and operations

Unit 9 Key programming concepts

Plenary

• 5 different data types

• Integer, real / float, char / character, string, Boolean

• 4 arithmetic operators

+, -, *, /, ^

• 3 functions used for string operations

• LENGTH(string), LCASE(string), UCASE(string),

SUBSTRING(string, start, length)

• 2 arithmetic operators used for integer division and

remainder

• DIV (integer division), MOD (remainder)

• 1 concatenate operator

+

39

Categorize

Options (16)

DIV (integer division)

  • MOD (remainder)

LENGTH(string)

LCASE(string)

 UCASE(string)

SUBSTRING(string, start, length)

+

-

*,

/

^

Integer

real / float

 char / character

string

Boolean

Organize these options into the right categories

data types
arithmetic operators
functions used for string operations
arithmetic operators division & remain

40

media

Data types and operations

Unit 9 Key programming concepts

Worksheet 1

• Now complete Task 1,2 and Task 3 on Worksheet 1

media

Show answer

Auto Play

Slide 1 / 40

SLIDE