Selection: IF Statement Damian Gordon. adsdfsdsdsfsdfs dsdlkmfsdfmsdl kfsdmkfsldfmsk dddfsdsdfsd.

Slides:



Advertisements
Similar presentations
Slide 1 Today you will: Review knowledge and understanding of systems Understand what a system is and what it consists of Apply this understanding by working.
Advertisements

Algorithms CSC1310 Fall What Is Programming? Programming Programming means writing down a series of instructions that tell a computer what to do.
H OW TO MAKE A CUP OF T EA ! By Paris Bell. Safety Instructions Equipment Ingredients Instructions Instructions (continued) Tips.
Unit 7.6 Lesson 2 Goals Identify and use flowchart symbols. Plan a sequence of events and incorporate them into a flowchart. Create a simple flowchart.
Lab #6 Program Design.
Tutorial #6 PseudoCode (reprise)
First steps  First get out a mug from your cupboard.  Next pour cold water into your kettle.  Then press the button and wait for it to boil.
Flowcharts So let’s say we want to express the following algorithm to print out the sum of the biggest and smallest of three numbers.
place a teabag in a mug; boil some water; pour over teabag; wait until strong enough; remove the teabag; add some milk and stir. what is this?
Mark Dixon, SoCCE SOFT 131Page 1 09 – Procedures.
Flow Charting, Structured English and PseudoCode
Tutorial #7 Flowcharts (reprise) Program Design. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect,
Flow Charting Damian Gordon. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect, and a developer.
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Procedures.
MTH 091 Section 11.3/Section 11.4 Factoring Trinomials By Grouping Factoring Trinomials Using FOIL.
Flow Charts. Thinking Creatively Flow Charts START END Is A==6? No A = 1 Yes Print A A = A + 1.
CS001 Introduction to Programming Day 5 Sujana Jyothi
Mark Dixon, SoCCE SOFT 136Page 1 9 – Procedures. Mark Dixon, SoCCE SOFT 136Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,
Tea traditions in England
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
A PowerPoint about Algorithm’s. What is an algorithm? A list Of cammands / instructions to do a tasks.
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
‘How to make perfect English tea’ Ewa Pacykowska.
For this unit, you will develop a new swimming / leisure business. 2. You will need to think of a name & concept for the business. 3. Over the.
Top-Down Design Damian Gordon. Top-Down Design Top-Down Design (also known as stepwise design) is breaking down a problem into steps. In Top-down Design.
How to make a Perfect Cup of Tea Supplies Kettle Ceramic tea-pot Large ceramic mug and spoon Microwave oven.
A PowerPoint about Algorithm’s. What is an algorithm? A step by step process of instruction.
Slide 1 What makes up an information system? Input Process Output Temperature and rainfall from a variety of places Analyse the information and present.
How to Make the Perfect Homemade Pumpkin Spice Latte.
By Zoe Cornell. Mug Kettle Tea bag Milk Sugar Pour water into the kettle and switch it on.
Learn about the system life cycle Plan the outline of your project
Sequence Damian Gordon. Pseudocode When we write programs, we assume that the computer executes the program starting at the beginning and working its.
Mug Tea bag Kettle Milk Sugar (only if you like it in your tea) A spoon Biscuits A plate for the biscuits.
PI “I am the Tea Expert” Management Case Study of My Cup of Tea Organising Business Activities in the Most Effective Way PI & MSC.
Divisibility Tests How can you tell quickly whether a number can be divided exactly by another?
Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
Python: Selection Damian Gordon. Python: Selection We’ll consider two ways to do selection: The IF statement The CASE statement.
Computer Control Using computers to do tasks. What are Computers used for? ringing your alarm clock. microwaving your breakfast checking for text messages.
The Concept The Triangle Inequality Theorem states that any two sides of a triangle when added together will always be larger than the third. EX:
1.5 The Distributive Property For any numbers a, b, and c, a(b + c) = ab + ac (b + c)a = ba + ca a(b – c)=ab – ac (b – c)a = ba – ca For example: 3(2 +
Pseudocode Skill Area Materials Prepared by Dhimas Ruswanto, BMm.
PROCEDURE TEXT. Learn carefully.  Teabag  Coffee mix  Fried rice  Cake  Chili  Powder  Sugar  Pan  spoon  Cut it into pieces  Boil water 
Sequences, Modules and Variables David Millard
Comp1004: Programming in Java II Computational Thinking.
Introduction to Python Damian Gordon e:
HOW TO MAKE A GOOD CUP OF TEA SKW 3061 ENGLISH WORKPLACE MISS GURMINDERJEET KAUR MOHAMAD SHAZRYL B. MOHD SHUKOR B01SPS13F
Introduction To Flowcharting
Algorithms Today we will look at: what the word algorithm means
Algorithms Y10 Introduction.
Factors: integers or expressions that divide something exactly
Queues: Implemented using Arrays
Python: Algorithms Damian Gordon.
Flow Charts AQA - Graphic Products.
Stacks: Implemented using Linked Lists
Process/ Instruction Writing
Chapter 5: Control Structure
Build the first 5 odd numbers – each one with different colored blocks
Structured Programming
Circular Queues: Implemented using Arrays
Question 10.
When we multiply by 10 we are making the number ten times bigger.
Giving and following instructions
Queues: Implemented using Linked Lists
Speaking Presentation
Flowcharts Activity One
Algorithms TASK Outcomes What is an algorithm?
Giving and following instructions
Presentation transcript:

Selection: IF Statement Damian Gordon

adsdfsdsdsfsdfs dsdlkmfsdfmsdl kfsdmkfsldfmsk dddfsdsdfsd

Do you wish to print a receipt?

Do you wish to print a receipt? In the interests of preserving the environment, we prefer not to print a receipt, but if you want to be a jerk, go ahead.

Selection What if we want to make a choice, for example, do we want to add sugar or not to the tea?

Selection What if we want to make a choice, for example, do we want to add sugar or not to the tea? We call this SELECTION.

IF Statement So, we could state this as: IF (sugar is required) THEN add sugar; ELSE don’t add sugar; ENDIF;

IF Statement Adding a selection statement in the program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.

IF Statement Adding a selection statement in the program: PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.

IF Statement Or, in general: IF ( ) THEN ; ELSE ; ENDIF;

IF Statement Or to check which number is biggest: IF (A > B) THEN Print A; ELSE Print B; ENDIF;

Pseudocode So let’s say we want to express the following algorithm: – Read in a number, check if it is odd or even.

Pseudocode PROGRAM IsOddOrEven: Read A; IF (A/2 gives a remainder) THEN Print “It’s Odd”; ELSE Print “It’s Even”; ENDIF; END.

Pseudocode We can skip the ELSE part if there is nothing to do in the ELSE part. So: IF (sugar is required) THEN add sugar; ELSE don’t add sugar; ENDIF;

Pseudocode Becomes: IF (sugar is required) THEN add sugar; ENDIF;

START

Read in A

START Does A/2 give a remainder? Read in A

START Does A/2 give a remainder? Read in A Yes Print “It’s Odd”

START Does A/2 give a remainder? No Read in A Yes Print “It’s Odd”Print “It’s Even”

START END Does A/2 give a remainder? No Read in A Yes Print “It’s Odd”Print “It’s Even”

Pseudocode So let’s say we want to express the following algorithm to print out the bigger of two numbers: – Read in two numbers, call them A and B. Is A is bigger than B, print out A, otherwise print out B.

Pseudocode PROGRAM PrintBiggerOfTwo: Read A; Read B; IF (A>B) THEN Print A; ELSE Print B; ENDIF; END.

START

Read in A and B

START A>B? Read in A and B

START A>B? Read in A and B Yes Print A

START A>B? No Read in A and B Yes Print APrint B

START END A>B? No Read in A and B Yes Print APrint B

Pseudocode So let’s say we want to express the following algorithm to print out the bigger of three numbers: – Read in three numbers, call them A, B and C. If A is bigger than B, then if A is bigger than C, print out A, otherwise print out C. If B is bigger than A, then if B is bigger than C, print out B, otherwise print out C.

Pseudocode PROGRAM BiggerOfThree: Read A; Read B; Read C; IF (A>B) THEN IF (A>C) THEN Print A; ELSE Print C; ENDIF; ELSE IF (B>C) THEN Print B; ELSE Print C; ENDIF; END.

START

Read in A, B and C

START A>B? Read in A, B and C

START A>B? Read in A, B and C Yes A>C?

START A>B? No Read in A, B and C Yes A>C?B>C?

START A>B? No Read in A, B and C Yes A>C?B>C? Print C No

START A>B? No Read in A, B and C Yes A>C?B>C? Print APrint C Yes No

START A>B? No Read in A, B and C Yes A>C?B>C? Print APrint CPrint B Yes No

START END A>B? No Read in A, B and C Yes A>C?B>C? Print APrint CPrint B Yes No

etc.