Objectives Knows and understand about another kind of flowchart’s symbols (looping) Have ability to create structured solution on simple problem(s) Have.

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
4 Control Statements: Part 1.
Chapter 5: Control Structures II (Repetition)
Advanced Piloting Cruise Plot.
Making Decisions and Working With Strings
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Arithmetic and Geometric Means
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
1) Read 2) Plan 3) Solve 4) Check Camels live in many places around the world. There are two kinds of camels. The Bactrian camel has two humps, while.
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chapter 17 Linked Lists.
Data Structures: A Pseudocode Approach with C
ABC Technology Project
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
VOORBLAD.
R.USHA TGT ( MATHEMATICS) KV,GILL NAGAR CHENNAI.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
CS101: Introduction to Computer programming
Chapter 5 Test Review Sections 5-1 through 5-4.
Control Structures Selections Repetitions/iterations
Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Addition 1’s to 20.
Decisions If statements in C.
CS 240 Computer Programming 1
25 seconds left…...
Subtraction: Adding UP
Equal or Not. Equal or Not
Slippery Slope
Januar MDMDFSSMDMDFSSS
Week 1.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
More on Algorithms and Problem Solving
Types of selection structures
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Presentation 7: JavaScript continued Control structures and functions Fundamentals of Web-Centric Development.
Data Structures Using C++ 2E
Chapter 3 Flow of Control Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Pascal Syntax. What you have learnt so far writeln() and write(); readln() and read(); variables (integers, strings, character) manipulation of variables.
1 SELECTION using IF and IF-ELSE Chapter 4. 2 Agenda Background  One Way selection (if) Two Way selection (if-else) Compound Statements Nested if-else.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Presentation transcript:

Algorithm and Programming IS-1113 Weeks – 02/1 Introduction to flowchart’s symbols for selection and looping process

Objectives Knows and understand about another kind of flowchart’s symbols (looping) Have ability to create structured solution on simple problem(s) Have ability to create structured solution using pseudo-code on simple problem(s) 1

Control Structure with flowchart 1. Simple sequence 2. Selection IF-THEN 3. Selcetion IF-THEN-ELSE Y N

4a. Nested IF 4b. CASE Structure conditioni ? Y N

No Yes Yes No 5. FOR structure 6. WHILE Structure For 7. REPEAT- UNTIL Structure No Yes

MAKING DECISIONS Most programs need to make decisions. There are several statements available in the Programming language for this. The IF statement is one of the them. The RELATIONAL OPERATORS, listed below, allow the programmer to test various variables against other variables or values. = Equal to > Greater than < Less than <> Not equal to <= Less than or equal to >= Greater than or equal to

Selection Control [1] (if) IF Statement : if condition_is_true then execute_this_program_statement; Example-1 (Flowchart): true false grade >= 60 Output “Passed” Pseudocode : If student’s grade >= to 60 then Output “Passed”

Selection Control [2] (if) condition true Statement Output will execute condition false If the condition is not true, then the program statement following the keyword then will be ignored. Statement Output will not execute then next statement Pascal Statements: if ( grade >= 60 ) then Writeln( ‘Passed’ );

Selection Control [3] (if) Example-2 (PASCAL) program IF_DEMO; {Program demonstrating IF THEN statement} var number, guess : integer; begin number := 2; writeln('Guess a number between 1 and 10'); readln( guess ); if number = guess then writeln('You guessed correctly. Good on you!'); if number <> guess then writeln('Sorry, you guessed wrong.') end.

Selection Control [4] (if-then-else) Statement if-then-else: The IF statement can also include an ELSE statement, which specifies the statement (or block or group of statements) to be executed when the condition associated with the IF statement is false. Example in pseudocode: If student’s grade is greater than or equal to 60 then Output “Passed” else Output “Failed” EndIF Example ( Flowchart) true false output“Failed” output “Passed” grade >= 60

Selection Control [5] (if…else) Pascal : if ( grade >= 60 ) then Writeln( ‘Passed’) else Writeln(‘Failed’);

Selection Control [6] (if…else) Example-2 : { Program example demonstrating IF THEN ELSE statement } program IF_ELSE_DEMO; var number, guess : integer; begin number := 2; writeln('Guess a number between 1 and 10'); readln( guess ); if number = guess then writeln('You guessed correctly. Good on you!') else writeln('Sorry, you guessed wrong.') end.

Example-3 There are times when you want to execute more than one statement when a condition is true (or false for that matter). Pascal makes provison for this by allowing you to group blocks of code together by the use of the begin and end keywords. Consider the following portion of code, if number = guess then begin writeln('You guessed correctly. Good on you!'); writeln('It may have been a lucky guess though') end {no semi-colon if followed by an else } else writeln('Sorry, you guessed wrong.'); writeln('Better luck next time') end; {semi-colon depends on next keyword }

Nested if : Example (pseudocode): The then and else block of an if statement can contain any valid statements, including other if statements. An if statement containing another if statement is called a nested-if statement. Example (pseudocode): If student’s grade is greater than or equal to 90 then output “A” else If student’s grade is greater than or equal to 80 then output “B” else If student’s grade is greater than or equal to 70 then output “C” else If student’s grade is greater than or equal to 60 then output “D” else output “F”

Flowchart Nested IF

BOOLEAN OPERATORS A boolean operator takes boolean values as its operands and returns a boolean value. The three boolean operators are X Y X AND Y T F X AND Y NOT X X NOT X T F X Y X OR Y T F X OR Y

Case Study Pemimpin sebuah perusahaan otomotif perlu menentukan besarnya bonus yang akan diberikan kepada para pegawainya yang bekerja sebagai account executive. Jika terdapat pegawai yang dalam bulan ini telah menjual mobil lebih dari dua unit, maka akan mendapatkan bonus sebesar Rp 1.000.000,- kemudian pegawai yang bisa menjual mobil tepat dua buah maka, akan mendapatkan bonus Rp 500.000,- namun jika pegawai yang dalam bulan ini penjualannya kurang dari dua unit maka, pegawai tersebut tidak mendapatkan bonus. Create flowchart

Answer to flowchart

EXERCISE-1 Which of the following is an invalid Pascal relational operator a. == b. <> c. < d. > Write a Pascal statement which compares the integer variable sum to the constant value 10, and if it is the same prints the string "Good guess"

EXERCISE-2 Write a Pascal statement which compares the character variable letter to the character variable chinput, and if it is not the same, prints the value of letter Write a Pascal statement to compare the character variable letter to the character constant 'A', and if less, prints the text string "Too low", otherwise print the text string "Too high"

Exercise-3 Write a Pascal statement to display the text string "Valve open", if the variable waterflow is equal to 1, AND the variable outputvalue is equal to 0 Write a Pascal statement which declares a constant called MAXSIZE with a value of 80 Write a Pascal statement which will display the value of the real variable degrees using a fieldwidth of 5 with three decimal places

Exercise-4 Write all of above exercise 2 to 6 in pseudocode What is the output of X and Y : IF (X < 10) AND (Y>0) THEN X  X*(X+1) ELSE X  X*X-1 ENDIF Y Y+1+X Suppose the value of X=11 and Y = 4

Exercise-5 X  3+4*5+(73 mod 9) + (53 div 9) What is the output of the following code : X  3+4*5+(73 mod 9) + (53 div 9) What is the value A now, when A=10 ? If A > 10 Then A A-5 EndIf A  A + 3

Answers-1 Which of the following is an invalid Pascal relational operator : == Write a Pascal statement which compares the integer variable sum to the constant value 10, and if it is the same prints the string "Good guess" if sum = 10 then writeln('Good guess');

Answers-2 Write a Pascal statement which compares the character variable letter to the character variable chinput, and if it is not the same, prints the value of letter if letter <> chinput then writeln( letter );

Answers-3 Write a Pascal statement to compare the character variable letter to the character constant 'A', and if less, prints the text string "Too low", otherwise print the text string "Too high" if letter < 'A' then writeln('Too low') else writeln('Too high'); Write a Pascal statement to display the text string "Valve open", if the variable waterflow is equal to 1, AND the variable outputvalue is equal to 0 if (waterflow = 1) AND (outputvalue = 0) then writeln('Valve open');

Answers-4 Write a Pascal statement which declares a constant called MAXSIZE with a value of 80 const MAXSIZE = 80; Write a Pascal statement which will display the value of the real variable degrees using a fieldwidth of 5 with three decimal places writeln('Degrees = ', degrees:5:3 );

Answer-5 No.8 Exercise 2 : Exercise 3 : Exercise 4 : if sum = 10 then Output('Good guess') Exercise 3 : if letter <> chinput then Output(letter) Exercise 4 : if letter < 'A' then output('Too low') else output('Too high');

Answer-6 No.8 MAXSIZE  80 No.9 Exercise 5 : Exercise 6 : if (waterflow = 1) AND (outputvalue = 0) then Output(‘Valve open') Exercise 6 : MAXSIZE  80 No.9 IF (X < 10) AND (Y>0) False AND True  F THEN X  X*(X+1) ELSE X  X*X-1 X= 11*11-1=120 ENDIF Y=4+1+120=125 Y Y+1+X Suppose the value of X=11 and Y = 4

Answer-7 X  3+4*5+(73 mod 9) + (53 div 9) : 3+20+1+8=32 If A > 10 Then A A-5 EndIf A  A + 3 Answer : A= 10  A> 10 is false so the value is A = 13