Pseudocode Skill Area 305.2 Materials Prepared by Dhimas Ruswanto, BMm.

Slides:



Advertisements
Similar presentations
Algorithms CSC1310 Fall What Is Programming? Programming Programming means writing down a series of instructions that tell a computer what to do.
Advertisements

Understanding the Three Basic Structures
Programming Logic and Design Seventh Edition
 Control structures  Algorithm & flowchart  If statements  While statements.
Tutorial #6 PseudoCode (reprise)
Objectives In this chapter, you will learn about:
CMPUT101 Introduction to Computing(c) Yngvi Bjornsson & Jia You1 Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem.
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,
Program Design and Development
Pseudocode and Algorithms
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Chapter 2: Algorithm Discovery and Design
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Flow Charts. Thinking Creatively Flow Charts START END Is A==6? No A = 1 Yes Print A A = A + 1.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CS001 Introduction to Programming Day 5 Sujana Jyothi
Algorithms In general algorithms is a name given to a defined set of steps used to complete a task. For example to make a cup of tea you would fill the.
General Programming Introduction to Computing Science and Programming I.
Invitation to Computer Science, Java Version, Second Edition.
Chapter 2 - Algorithms and Design
Selection: IF Statement Damian Gordon. adsdfsdsdsfsdfs dsdlkmfsdfmsdl kfsdmkfsldfmsk dddfsdsdfsd.
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,
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
Lesson Year 1 CS112/0401/V1 LESSON 6 DESIGN TOOL PSEUDOCODE  Program Design Language (PDL)  Represent logic in English-like manner  Easier to.
Coding Design Tools Rachel Gauci. What are Coding Design Tools? IPO charts (Input Process Output) Input- Make a list of what data is required (this generally.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
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.
Basic Control Structures
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
CSCI-100 Introduction to Computing
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Sequence Damian Gordon. Pseudocode When we write programs, we assume that the computer executes the program starting at the beginning and working its.
Pseudocode An Introduction. Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Algorithms and Pseudocode
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Program Program is a collection of instructions that will perform some task.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
Sequences, Modules and Variables David Millard
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Introduction to Python Damian Gordon e:
Control Structures: Conditionals, If/Else and Loops David Millard
PROGRAMMING: What’s It All About?
ALGORITHMS AND FLOWCHARTS
Algorithms and Flowcharts
Introduction To Flowcharting
UMBC CMSC 104 – Section 01, Fall 2016
ALGORITHMS AND FLOWCHARTS
Algorithms Today we will look at: what the word algorithm means
Algorithms & Pseudocode
MSIS 655 Advanced Business Applications Programming
Programming Fundamentals (750113) Ch1. Problem Solving
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
Algorithm Discovery and Design
` Structured Programming & Flowchart
Flowcharts and Pseudo Code
Pseudocode For Program Design.
Software Development Techniques
Presentation transcript:

Pseudocode Skill Area 305.2 Materials Prepared by Dhimas Ruswanto, BMm

Lecture Overview Pseudocode Pseudocode (Sequence) Pseudocode (Selection) Pseudocode (Iteration) Examples

Pseudocode Pseudocode consists of short, English phrases used to explain specific tasks within a program’s algorithm.

Pseudocode Used to provide an outline description of the specification for the software module Contain a natural language of expressions embedded in syntactic structures taken from programming language IF…THEN…ELSE REPEAT..UNTIL Not intended to be executed by a computer, must be interpreted by people.

Pseudocode Sequence

Pseudocode (Sequence) When we write programs, we assume that the computer executes the program starting at the beginning and working its way to the end. This is a basic assumption of all algorithm design. We call this SEQUENCE.

Pseudocode (Sequence) In pseudo-code it looks like this: Statement1; Statement2; Statement3; Statement4; Statement5; Statement6; Statement7; Statement8;

Pseudocode (Sequence) For example, for making a cup of tea: 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 and/or sugar; Serve;

Pseudocode (Sequence) Or as a program: BEGIN 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 and/or sugar; Serve; END.

Pseudocode SeLECTION

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

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

Pseudocode (Selection) Or, in general: IF (<CONDITION>) THEN <Statements>; ELSE <Statements>; ENDIF;

Pseudocode (Selection) Or to check which number is biggest: IF (A > B) THEN Print A + “is bigger”; ELSE Print B + “is bigger”; ENDIF;

Pseudocode (Selection) Adding a selection statement in the program: BEGIN 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.

Pseudocode ITERATION

Pseudocode (Iteration) What if we need to tell the computer to keep doing something until some condition occurs? Let’s say we wish to indicate that the you need to keep filling the kettle with water until it is full. We need a LOOP, or ITERATION.

Pseudocode (Iteration) WHILE (a true condition) STATEMENT or STATEMENT BLOCK concluded with ENDWHILE WHILE Loop REPEAT statement UNTIL (condition is true) REPEAT UNTIL Loop FOR (starting state, final state, increment) Statement ENDFOR FOR Loop

Pseudocode (Iteration) So, we could state this as: WHILE (Kettle is not full) DO keep filling kettle; ENDWHILE; Or to print out the numbers 1 to 5: A = 1; WHILE(A > 5) DO Print A; A = A + 1; ENDWHILE;

What is the benefit of using loop? Get first entry If this is the required entry Then write down phone number Else get next entry If this is the correct entry then write done entry else get next entry if this is the correct entry Consider the problem of searching for an entry in a phone book with only condition: Get first entry; Call this entry N; WHILE N is NOT the required entry DO Get next entry; ENDWHILE; We may rewrite this as follows:

Pseudocode (Iteration) BEGIN PROGRAM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; WHILE (Kettle is not full) DO keep filling kettle; ENDWHILE; 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 Or as a program:

Pseudocode eXAMPLES

Examples So let’s say we want to express the following algorithm: Read in a number and print it out. BEGIN PROGRAM PrintNumber: Use variables: A OF TYPE Integer Read A; Print A; END

Examples So let’s say we want to express the following algorithm: Read in a number and print it out double the number BEGIN PROGRAM PrintDoubleNumber: Use variables: A,B OF TYPE Integer Read A; B = A*2; Print B; END

Examples BEGIN PROGRAM PrintBiggerOfTwo: 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. BEGIN PROGRAM PrintBiggerOfTwo: Use variables: A,B OF TYPE Integer Read A; Read B; IF (A>B) THEN Print A; ELSE Print B; ENDIF; END

Examples 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.

Examples BEGIN PROGRAM BiggerOfThree: Read A; Read B; Read C; Use variables: A,B,C OF TYPE Integer Read A; Read B; Read C; IF (A>B) THEN IF (A>C) THEN Print A; ELSE Print C; END IF; ELSE IF (B>C) THEN Print B; END

Examples So let’s say we want to express the following algorithm: Print out the numbers from 1 to 5 BEGIN PROGRAM Print1to5: Use variables: A OF TYPE Integer A = 1; WHILE (A != 6) DO Print A; A = A + 1; ENDWHILE; END

Examples BEGIN PROGRAM ComputeSum: Use variables: number1, number2, sum OF TYPE Integer DISPLAY “Enter the numbers” ACCEPT number1, number2 Sum:=number1 + number2 DISPLAY “SUM” END

Examples BEGIN PROGRAM CategoryOfInsurance: Use variables: category OF TYPE character insurance OF TYPE string ACCEPT category DO CASE of category CASE category = U DISPLAY Insurance := “not available” CASE category = A DISPLAY Insurance := “double” CASE category = B DISPLAY Insurance := “normal” CASE category = M DISPLAY Insurance := “medically dependent” OTHERWISE DISPLAY “entry is invalid” ENDCASE END

Examples BEGIN PROGRAM NumberRange0-100: Use variables: number OF TYPE Integer REPEAT DISPLAY “Enter a number between 0 and 100” ACCEPT number UNTIL number <0 or number >100 END

Examples Create a flowchart for inputting your employee’s name. If the first letter starts from A to J then display “ First Category” , if K to T then display “ Second Category” otherwise display Third Category If student's grade is greater than or equal to 60 Print "passed“ else Print "failed“ Set the counter to 0. If the counter is more than 10 then customer receives free value meal otherwise no free value meal.