Topics: Selection Statements. Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

Problem Solving INFORMATION TECHNOLOGY
ALGORITHMS AND FLOWCHARTS
Representing an algorithm using Flowcharts
Al-Karma Language School Computer Department Prep. 3.
Program Flowchart, Pseudocode & Algorithm development
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Introduction to Flowcharting
PSEUDOCODE & FLOW CHART
Flow Control Analysis & Design Tool: Flowcharts
Selection (decision) control structure Learning objective
Understanding the Three Basic Structures
UNIT 2. Introduction to Computer Programming
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Subject: Information Technology Grade: 10
ALGORITHMS AND FLOWCHARTS
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
Fundamentals of Algorithms MCS - 2 Lecture # 4
ITEC113 Algorithms and Programming Techniques
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
A High-Level Model For Software Development
Developing logic (Examples on algorithm and flowchart)
The Program Design Phases
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
Algorithm & Flowchart.
Chapter 1 Pseudocode & Flowcharts
ALGORITHMS AND FLOWCHARTS
CSC103: Introduction to Computer and Programming
DCT 1123 Problem Solving & Algorithms
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Problem Solving with Decisions
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
CHAPTER 3 SELECTION STRUCTURE.
1 CSC103: Introduction to Computer and Programming Lecture No 7.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
ITEC113 Algorithms and Programming Techniques
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
Agenda Basic Logic Purpose if statement if / else statement
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Introduction to Computing Dr. Nadeem A Khan. Lecture 2.
Chapter 7 Problem Solving with Loops
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
PROBLEM SOLVING. REDBLUE GREENPINK ORANGEYELLOW Exit.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Decisions: Conditional Statements (informally called If Statements) IST 256 Application Programming for Information Systems.
Introduction to Flowcharts
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney.
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
Algorithms and Flowcharts
Numbering System TODAY AND TOMORROW 11th Edition
2.0 Problem Solving PROGRAM DESIGN
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Selection Statements.
Introduction to Programming
Presentation transcript:

Topics: Selection Statements

Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’ command. The IF statement contains a condition that is made up of three parts: Variable to be tested Relational operator Variable or constant to which the variable to be tested is compared to.

Relational Operators

If statements: IF-THEN IF-THEN-ELSE Flowchart Symbols: Decision making and branching Connector or joining two parts of a program. It is also used to connect sections of a flowchart when a flowchart is long and cannot fit on a page. A letter or digit can be placed in the small circle to indicate the link on the first page. Another identically labeled connector is placed on the next page to indicate the continuation of flow.

IF-THEN When one option is available and a selection may or may not be made, the IF-THEN is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true ENDIF

Flowchart no yes Condition Statement - True

Problem 1: If a student’s grade is greater than 85%, then she is given 3 merits. Solution: Pseudocode IF (grade > 85) then merit = 3 ENDIF Flowchart no yes Examples IF-THEN grade > 85 merit = 3

Problem 2: Read the time. If the time is 11:00, output “Ring the bell”. Solution Pseudocode Read time IF (time = 11) then Print “Ring the bell” ENDIF

Problem 3: Read a number N. If N is greater than or equal to 100, add 10 to the number and display the result. Print the number. Solution: Pseudocode Read N IF (N >= 100) then result = N + 10 Print “Result is ” result ENDIF Print “Number is ” N

Problem Write a program that calculates and displays the revenue made by a minibus, which made 20 trips from Portmore to Kingston. Each passenger paid $120. If the revenue for the day exceeded $20,000.00, a bonus of 10% of the revenue is given to the driver. Compute and print the bonus amount. Input the number of passengers who traveled on each trip.

Requirements List the operations Write the Pseudocode Draw the Flowchart.

IF-THEN-ELSE When two options are available and a selection must be made, the IF-THEN-ELSE is used. Pseudocode IF (condition) then One or more instructions which will be carried out if the condition is true else One or more instructions which will be carried out if the condition is false ENDIF

Flowchart yes no Condition Statement - TrueStatement - False

Examples IF-THEN-ELSE Problem 1: If sales is greater than $7000, commission is $500 otherwise commission is $250 Solution: Pseudocode IF (sales > 7000) then commission = 500 else commission = 250 ENDIF Flowchart yes no Sales > 7000 Commission = 500Commission = 250

Examples IF-THEN-ELSE Problem 2: Read the age of a person. If age is greater than 35, output “old person” otherwise output “young person” Solution: Pseudocode Read age IF (age > 35) then Print “Old person” else Print “Young person” ENDIF

Problem 3: Input employee’s salary. If the salary is less than or equal to $44000, then a bonus of 15% is given, otherwise 10% is given. Calculate and display the bonus amount given. Solution: Pseudocode Read salary IF (salary <= 44000) then bonus = salary * 0.15 else bonus = salary * 0.10 ENDIF Print “Bonus amount is ” bonus

Problem A credit union pays 4% interest on shares that are greater than $25000 and 3% on all other shares. No interest is paid on deposits. Write a program that prompts the user to input a share a deposit. The program should calculate and output the interest amount and the total savings (Total savings = shares + deposit + interest amount).

Operations The operations are: 1. Input the number of passengers on each trip 2. Calculate the total number of passengers 3. Calculate the revenue for the day 4. Print the revenue 5. Determine if the bonus will be given 6. If the bonus is given, calculate the bonus amount 7. Print the bonus amount

Requirements List the operations Write the Pseudocode Draw Flowchart

Home Work Cambridge – Information Technology for CSEC Exercise 22 – Numbers 1 - 5

THE END