
Unit 9 Key Programming concepts T1 Data types
Presentation
•
Computers
•
10th Grade
•
Practice Problem
•
Medium
Michael Harrington
Used 1+ times
FREE Resource
26 Slides • 14 Questions
1
2
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
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
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
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
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
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
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
Integer
Real
Boolean
Char
String
13
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
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
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
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
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
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
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
3
4
7
31
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
3
4
7
31
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
10
100
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
10
100
5
10
24
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
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
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
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
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?
"ReviseHard"
"HardRevise"
"Hard Revise"
"Revise Hard"
30
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
10
ond
london zoo
LONDON ZOO
32
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
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
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"
"The quality of mercy is not strained."
7
"The qua"
"The qu"
35
Multiple Choice
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?
Data Structure
Date Type
36
Multiple Choice
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
Square
None
Round
curly
37
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
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
DIV (integer division)
MOD (remainder)
LENGTH(string)
LCASE(string)
UCASE(string)
SUBSTRING(string, start, length)
+
-
*,
/
^
Integer
real / float
char / character
string
Boolean
40
Data types and operations
Unit 9 Key programming concepts
Worksheet 1
• Now complete Task 1,2 and Task 3 on Worksheet 1
Show answer
Auto Play
Slide 1 / 40
SLIDE
Similar Resources on Wayground
32 questions
Materi AI edit -suardi
Presentation
•
10th Grade
37 questions
Types of Plate Boundaries
Presentation
•
10th Grade
38 questions
Berpikir Komputasional
Presentation
•
10th Grade
36 questions
Compression
Presentation
•
10th - 11th Grade
35 questions
Similar Triangles
Presentation
•
10th Grade
35 questions
Avancemos 1 Unidad 2 leccion 2
Presentation
•
9th Grade
36 questions
Kedatangan Bangsa Eropa Ke Indonesia
Presentation
•
10th Grade
36 questions
The Brain
Presentation
•
10th Grade
Popular Resources on Wayground
20 questions
STAAR Review Quiz #3
Quiz
•
8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
6 questions
Marshmallow Farm Quiz
Quiz
•
2nd - 5th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
12 questions
What makes Nebraska's government unique?
Quiz
•
4th - 5th Grade
Discover more resources for Computers
50 questions
STAAR English 2 Review
Quiz
•
10th Grade
20 questions
Figurative Language Review
Quiz
•
10th Grade
20 questions
Grammar
Quiz
•
9th - 12th Grade
31 questions
Easter Trivia
Quiz
•
KG - 12th Grade
16 questions
Circles - Equations, Central & Inscribed Angles
Quiz
•
9th - 12th Grade
46 questions
Unit 4 Geosphere Test Review
Quiz
•
9th - 12th Grade
10 questions
Calculating Surface Area of a Triangular Prism
Interactive video
•
6th - 10th Grade
20 questions
Central Angles and Arc Measures 2
Quiz
•
10th Grade