Lesson 2 Programming constructs Algorithms Scratch Variables Intro

Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro

COMPUTER SCIENCE Lesson 2 Starter: student as teacher recap. (Difference between Computing and ICT; Why do we need Binary? What is Binary – in a nutshell? Two types of languages (low and high) What did we do in Scratch? ) Inspiration: So what is Programming? How do our Brains work – an analysis of what we do automatically! Algorithms as sequences of instructions Introducing the 3 main programming constructs Using the SEQUENCE and SELECTION (IF) programming constructs Using Scratch to program using Sequence and IF Scratch Task Plenary: (AFL) In pairs discuss the different PROGRAMMING CONSTRUCTS you have used in your scratch program. Use technical terms like: ALGORITHIM; SEQUENCE OF INSTRUCTIONS; SELECTION CONSTRUCT = IF.

At the end You should know. . . What is Programming? What is an Algorithm? What are three programming constructs!? SEQUENCE SELECTION ITERATION Using scratch to create simple programs and use programming principles How have you used TWO of the THREE constructs (SEQUENCE AND SELECTION (IF STATEMENTS) today? The use of a Variable in Scratch

Introduction to Programming

Human cells contain DNA – Have you heard of the term the GENETIC CODE? !

Remember Binary = Base 2 Decimal = Base 10 Quite mysteriously – the genetic CODE is just that – a CODE – a type of programming language that we find inside our cells. Can you guess what BASE it is? !?

Remember Binary = Base 2 Decimal = Base 10 GENETIC CODE = 4 BASES! Can you guess what BASE it is? !? A T U G Our genes consist of various sequential combinations!!!

You can think of the genetic code as a language. Each group of three bases or 'letters' forms a 'word' called a codon. Each codon specifies one amino acid, and proteins are made from long chains of amino acids. There also codons that mark the start and end of the gene. Inspired? Well read more on the GENETIC CODE and you’ll probably find out more in BIOLOGY

So what is Computer Programming? The process of developing and implementing various sets of instructions to enable a computer to do a certain task. These instructions are considered computer programs and help the computer to operate smoothly. The language used to program computers is not understood by an untrained eye. Computer programming continues to be a necessary process as the Internet continues to expand. more: http: //www. businessdictionary. com/definition/computer -programming. html#ixzz 1 j. FC 1 Lf 99

What is a Computer Program A computer program (also software, or just a program) is a sequence of instructions written to perform a specified task with a computer. FYI A Computer Virus = is just a nasty little computer program (a bit of a code that does something mean!)

A computer programmer basically thinks about and then types loads of clever instructions to CREATE something In mathematics and computer science, an algorithm i/ˈælɡərɪðəm/ (from Algoritmi, the Latin form of Al. Khwārizmī) is an effective method expressed as a finite list of well-defined instructions. In simple words an algorithm is a step-by-step list of instructions (that tell a program what to do)

The 3 main programming constructs Any programmer needs to know about the following three things. In this lesson We will only be looking at the first two. • SEQUENCE • SELECTION (IF STATEMENTS • ITERATION (these are loops – there are 3 main types (FOR loops, While – Next and Repeat – Until LOOPS - - More on these later) (basically a sequence or set of instructions put in order) and CASE Statements. We will only be looking at the first one in this session)

Very very clever people in the early days of computing realised that they could use a special number system called BINARY • Binary is a language of • 1 • 0

Two type of Programming 1. Ways we communicate with computers 2. LOW LEVEL (Binary / Assembly Language) 3. HIGH LEVEL Languages (like Java, VB, Scratch)

Remember that all a computer can really understand is BINARY (1 s and 0 s) This means that ultimately all code (high level language code) needs to be CONVERTED into Binary. This is done by means of COMPILERS, INTERPRETERS AND TRANSLATORS These are computer programs that are used to convert high level instructions or language into a form that can be understood by the computer. (Binary) Read more: http: //www. differencebetween. com/difference-between-compiler-and-vs -interpreter/#ixzz 1 s. TXxdq. WI

TRANSLATORS! The idea of using a computer to TRANSLATE human like language to machine language (1 s and 0 s) was first suggested by Grace Hopper (in 1952) She is often credited with the title of being the world’s first FEMALE PROGRAMMER!

PROGARMMERS= COOL GUY! He was the first to come up with a difference engine And had figured out that you could use BINARY to communicate with computers In fact – he believed the entire universe was Programmed and that GOD was the ultimate Programmer.

heh

Imagine trying to program in Binary

Instead we use HIGH Level languages that resemble English or languages we can understand

LAST WEEK YOU CREATED A SIMPLE PROGRAM IN SCRATCH

Let’s Analyze the Programming Constructs in use

See if you can find: SEQUENCE SELECTION: IF STATEMENTS ITERATION: LOOPS The use of a VARIABLE

See if you can find: SEQUENCE SELECTION: IF STATEMENTS ITERATION: LOOPS The use of a VARIABLE

But what, really is a program? -A Sequence of Instructions And what is a variable?

HOW OUR BRAINS WORK Algorithms – (in our brain) are inbuilt We eat, drink, speak, respond appear to have been pre-programmed to do so. There is ‘Free Will’ too, but that’s a more philosophical discussion. DEFINITION: Algorithm = sequence of instructions which performs a meaningful task

How our brains work We don’t often realize it but our brains are pretty awesome. The brain is storing values and processing data (as well as producing outputs) all the time Think of any system as comprising of these 3 parts

Inputs need to be “stored” And this is where “Variables” come in. Variables are about allocating a little memory space to store a value.
![What is a Variable? Name of Box [Variable] =Age 26 Sample Subroutine A storage What is a Variable? Name of Box [Variable] =Age 26 Sample Subroutine A storage](http://slidetodoc.com/presentation_image_h2/94d65bdce704da3d8585e37ef1afbaf2/image-29.jpg)
What is a Variable? Name of Box [Variable] =Age 26 Sample Subroutine A storage box for Values Dim age as integer Console. writeline(“Enter age”) Age=Console. Readline Console. Writeline(age) The value ’ 26’ can go into the box The box is called ‘Age’

What is a Variable ? All variables must be declared before they are used in a program Dim number 1 as Integer Dim number 2 as Real Dim number 3 as Double Dim answer as Boolean Dim result as char etc

When I give you two numbers your brain stores it automatically… 15 47 Number 1 Number 2 You don’t consciously say – “right, now I am going to store number 1 and assign it a value of 15 and number 2 and assign it a value of 47…” it just happens instantly!”

In a computer you need to declare variables …. Example of declaring variables in VB 15 47 Number 1 Number 2 Dim num 1 as integer Dim num 2 as integer Num 1=15 Num 2 =47 Dim answer as integer Answer = num 1+num 2 Think of it like a block of space (MEMORY ALLOCATION) for the inputs You are going to be processing

TASK PACMAN GAME – Scratch Skills: Using -SEQUENCE, SELECTION, ITERATION (LOOPS) AND VARIABLES (SCORE)

Create the following program in SCRATCH. Then see if you could add a SCORE FUNCTION

Adding a Variable: SCORE Click on “blocks” Variables Click “Make a Variable” Name your variable = Score Look at the blocks avaialble for score. What do you want to make the SCORE DO?

A little more on Algorithms Pseudocode or Flow Charts are often used to show the structure and functionality of a program. In Pseudocode the individual actions to be carried out by the program are stated in plain English … they can be visually represented in a Flow Chart using symbols and arrows.

Sample Pseudocode or Flowchart Pseudocode – is like “fake” code – resembles English in this case. Read Number 1 Read Number 2 No READ NUMBER 1 READ NUMBER 2 IF NUM 1 > NUM 2 Then ADD NUMBERS PRINT THE SUM Num 1 > Num 2? Yes Add Numbers Print the Sum

Plenary: (AFL) In pairs discuss the different PROGRAMMING CONSTRUCTS you have used in your scratch program. Use technical terms like: ALGORITHIM; SEQUENCE OF INSTRUCTIONS; SELECTION CONSTRUCT = IF.
- Slides: 38