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

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Chapter 1 Program Design
String Escape Sequences
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
CS0004: Introduction to Programming Variables – Numbers.
Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a.
CIS Computer Programming Logic
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Cis303a_chapt03-2a.ppt Range Overflow Fixed length of bits to hold numeric data Can hold a maximum positive number (unsigned) X X X X X X X X X X X X X.
Computer Programming 12 Lesson 3 – Computer Programming Concepts By Dan Lunney.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Copyright Curt Hill Variables What are they? Why do we need them?
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
CPS120: Introduction to Computer Science Variables and Constants.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Component 1.6.
Data Types and Structures
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Visual Basic 6 (VB6) Data Types, And Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Starter Question In your jotter write the pseudocode to take in two numbers, add them together then display the answer. Declare variables RECEIVE firstNumber.
Engineering Innovation Center
Microsoft Visual Basic 2005 BASICS
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Data Types, Identifiers, and Expressions
2.1 Parts of a C++ Program.
Variables ICS2O.
Unit-1 Introduction to Java
Chapter 2: Introduction to C++.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Spreadsheets, Modelling & Databases
Understanding Variables
Variables and Constants
Programming Fundamental-1
COMPUTING.
Constants, Variables and Data Types
Introduction to Computer Science
Presentation transcript:

Data Handling in Algorithms

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

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

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?

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.

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).

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

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.

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.

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 ,456 Strings Collection of alpha- numeric characters, whitespace and punctuation. “Adsh 889wd” “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

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

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

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…) INDEX Value Visual Example of an Array: