IGCSE 4 Cambridge Data types and arrays Computer Science Section 2

Slides:



Advertisements
Similar presentations
Andrew C. Samuels, Information Technology Specialist Trainer c/o Ministry of Education Mona High School, Kingston, Jamaica 1 Problem Solving Section 2:
Advertisements

CIS Computer Programming Logic
Input & Output: Console
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
C Programming Lecture 4 : Variables , Data Types
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
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 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
09/06/ Data Representation ASCII, Binary Denary Conversion, Integer & Boolean data types.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
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.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Choosing Data Types Database Administration Fundamentals
Unit 2 Technology Systems
3.1 Fundamentals of algorithms
IGCSE 1 Cambridge Algorithms and flowcharts Unit 7 Computer Science
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Data Types and Structures
Computing Fundamentals
Chapter 8 Arrays Objectives
Computational Thinking
Engineering Innovation Center
Computational Thinking
IDENTIFIERS CSC 111.
One-Dimensional Array Introduction Lesson xx
Python Lessons 9 & 10 Mr. Kalmes.
Chapter 8 Arrays Objectives
Do While (condition is true) … Loop
Variables Title slide variables.
Variables and Expressions
Coding Concepts (Data- Types)
Data Types and Data Structures
CHAPTER FOUR VARIABLES AND CONSTANTS
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Building Java Programs
Introduction to Value-Returning Functions: Generating Random Numbers
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
CS150 Introduction to Computer Science 1
Chapter 8 Arrays Objectives
CS150 Introduction to Computer Science 1
Variables Here we go.
Primitive Types and Expressions
C++ Programming Basics
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Arrays & Loops.
Arrays & Loops.
Class code for pythonroom.com cchsp2cs
Variables and Constants
COMPUTING.
Introduction to Computer Science
Section 6 Primitive Data Types
Presentation transcript:

IGCSE 4 Cambridge Data types and arrays Computer Science Section 2 Unit 7 Algorithm design and problem-solving 4

Objectives Define the terms variable and constant Use and identify variables and constants in program code Identify and use the data types integer, real, Boolean, character and string Use predefined procedures/functions Use one-dimensional arrays

What is a variable? A variable is a location in memory in which you can temporarily store text or numbers It is used like an empty box or the Memory function on a calculator You can choose a name for the box (the “variable name” or “identifier”) and change its contents in your program

Using variables in a program You have used variables in many different ways in programs you have already written Add 1 to NumberOfStudents CircleArea  3.142 * Radius * Radius WHILE NOT Found … Answer  “Y” OUTPUT StudentName What different types of variable are shown above?

Variable types Variable types typically include integer, real, Boolean, character and string In many programming languages variables have to be declared at the start of the program so that the appropriate amount of memory can be reserved for them Var NumberOfStudents : integer; CircleArea : real; Found : Boolean; Answer : char; StudentName : string;

Definitions of data types Type of data Typical amount of memory Integer Whole number such as 156, 0 -54 2 bytes Real Number with a fractional part such as 1.5276, -68.4, 20.0 4 bytes Char A single ASCII character such as A, b, 3, ! or space 1 byte String Zero or more characters 1 byte per character in the string Boolean Can only take the values True or False Theoretically just one bit, but in a high level language such as Python, Pascal etc., one byte

Constants As well as variables, you can define constants in a program PI = 3.14157926536 MonthlyTariff = 15.60 Why declare a constant instead of a variable? Can a constant ever change its value?

Predefined functions High-level programming languages have built-in functions which are part of the language Examples of common functions are: int(s) convert a string s to an integer real(s) or float(s) convert a string s to a number with a decimal point round(x,n) round a number x to n decimal places sqrt(x) return the square root of x E.g. a  round (15.168534 ,2) puts a = 15.17 What is num after the statement num  int (“57”)?

Importing modules Modules are files containing code (procedures or functions) that can be used by other programs In Python, for example, the statement import random written at the beginning of the program will allow you to use a function to generate a random number in a given range x = random.randint (1,100) will put a random number between 1 and 100 in the variable x

Worksheet 4 Now complete Task 1, questions 1 and 2

Arrays An array is a data structure that allows you to hold several variables, all of the same type, with one name. An array of 10 integers called UserName could be declared as UserName : array[1..10] of string The elements of the array are typically referred to as UserName[1], UserName[2], …. UserName[10] In some programming languages the “index” starts at 0: UserName[0], UserName[1], …. UserName[9]

Defining an array of constants If you wanted to store constant values in an array, you could write the pseudocode statement: Resort  [“Wakatobi”, “Isola Bella”, “Coolangatta”, “Paphos”, “Bentota”] You can find out whether a resort name input by a user is in the list: FOR n = 1 to 5 IF ResortName = Resort [n] THEN Found  True ENDIF ENDFOR Can you rewrite the algorithm using a WHILE loop?

Advantages of using arrays Imagine that you want to input, sort and print 100 user names. It would be very inconvenient to use 100 different variable names Using an array, you can write: FOR i = 1 TO 100 UserName[i]  USERINPUT NEXT i (Sort the names) Output (UserName[i]) Next i

Data types Now complete Worksheet 4 Task 2

Plenary In this lesson you have worked with: Variables and constants Different variable types such as integer, real and string Predefined procedures and functions such as int and round One-dimensional arrays