Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!

Similar presentations


Presentation on theme: "Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!"— Presentation transcript:

1 Data Handling in Algorithms

2 Activity 1 Starter Task: Quickly complete the sheet 5mins!

3 Activity 1a 1 st Starter Task: Label the code to identify where the following control structures are: Sequencing Selection Iteration

4 Activity 1b 2 nd Starter Task: What variable(s) are being used in this program? What type of data is being stored in the variable(s)? What different operators can you see are being performed on the variable?

5 Data Handling in Algorithms Introduction All imperative languages handle data in very similar ways. They all make use of variables, constants, and arrays to store data. They all deal with a range of data types. They all process data using common operations. We will now look at these similar Data Handling components. Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays.

6 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. What is a Variable? What is a Constant? ANSWER Mr Wickins 29 Sidmouth Variables are given IDs (names). Contents can change throughout the program. They can be overwritten. Variables can be thought of as storage boxes holding one piece of data (of a particular data type) at any one time. Pi 3.142… Contents cannot change throughout the program. They cannot be overwritten. Constants are also given IDs (names). Constants can also be thought of as storage boxes holding one piece of data (of a particular data type).

7 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Using Variables in Algorithms and Programming Languages? Rules for using Variables… There are several rules and conventions for naming variables: -Must be unique -Must start with an alphabetical character (a-z) -Must only contain a-z, 0-9 and underscore (no punctuation or spaces) -Should use camel case: When joining two or more words to make a meaningful variable name, start with a lower case letter, remove whitespace between subsequent words & subsequent words start with upper case: eg: totalLengthOfCar

8 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. When might we use Constants in Algorithms and Programming Languages? Because constants cannot change, they are great if we want to use a value in our program that is “set in stone”. Examples are VAT and the value of Pi. Also, they can be useful because if VAT changed in the future it will be quicker and easier to update the constant (which will be declared once) instead of every instance of the variable throughout a program.

9 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Data Types When computers deal with data they need to know what sort of data it is so that they can get the CPU memory ready to process that data type. For example, character data will only be 1 character in length therefore the CPU only needs to allocate 1 memory location for that type of data. If however a variable contains a string data type, because it could be a word / sentence etc the CPU would need to allocated much more memory in readiness to process that data. It is therefore important that we know what different data types there are so we can program our variables efficiently.

10 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Data Types Data TypeExplanationExample Integers Whole Numbers 104 21 23,456 Strings Collection of alpha- numeric characters, whitespace and punctuation. “Adsh 889wd” “sdsd34@@$” “Pea Soup” Boolean Either TRUE or FALSE TRUE / FALSE ON / OFF 1 / 0 Characters Single Character (any alphanumeric character or punctuation, but only one character) ‘1’ ‘D’ ‘%’ ‘s’ Real (float in Python) Decimal or Whole number -12 23.456 -0.34 1243.5434523

11 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Common Operations OperationDescriptionOperatorExample Addition Adds one value to another + x = y + z Subtraction Subtracts one number form another - x = y - z Multiplication Multiplies two numbers * x = y * z Division Divides one number by another. / x = y / z Modular Division Divides 2 numbers but only keeps the ‘remainder’ part of the answer MOD or %x = y % z Div Divides 2 numbers but only keeps the ‘whole number’ part of the answer DIV or //x = y // z

12 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Common Operations Boolean operations can be used to perform conditional tests for selection (IF Statements) and iterative constructs (check when to exit loops) OperationDescriptionOperatorExample AND Performs logical AND operation AND (&&) x = y AND z OR Performs logical OR operation OR (||) x = y OR z NOT Performs logical NOT operation NOT (!) x = y NOT z

13 Data Handling in Algorithms Learning Objectives: (j) define the terms variable and constant as used in an imperative language (k) use variables and constants (l) describe the data types integer, real, Boolean, character and string (m) select and justify appropriate data types for a given program (n) perform common operations on numeric and Boolean data (o) use one-dimensional arrays. Arrays An array is a data structure which contains a set of values that are all the same data type. In python we have learnt about the data structure known as a LIST This is much like an array and for the purpose of our GCSE programming we will use LISTS when creating a group of data. But unlike a list, we have to state the size of the array when we create one (lists are dynamic, they just grow as we add to them…) INDEX012345678 Value34652376645441234 Visual Example of an Array:


Download ppt "Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!"

Similar presentations


Ads by Google