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.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 2: Modularization
Program Flowchart, Pseudocode & Algorithm development
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Introduction to Flowcharting
Introduction to Flowcharting
Understanding the Three Basic Structures
Chapter 1 - An Introduction to Computers and Problem Solving
Introduction to Flowcharting
An Object-Oriented Approach to Programming Logic and Design
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Programming Logic and Design Seventh Edition
1 Pseudocode For Program Design. 22 Rules for Pseudocode Write only one statement per line Capitalise initial keyword Indent to show hierarchy and structures.
What is Pseudocode? Pseudocode is "halfway" between english and a programming language. It is a description of a process in detail, though not necessarily.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Program Design and Development
Chapter 2: Input, Processing, and Output
Modules, Hierarchy Charts, and Documentation
Pseudocode.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Pseudocode.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
DCT 1123 Problem Solving & Algorithms
CIS Computer Programming Logic
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
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.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Cosc175 - Define Problem/Design Solution/Pseudocode/Trace 1 DEFINE THE PROBLEM.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
Chapter 7 Problem Solving with Loops
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
1 Introduction to Flowcharting Computer Science Principles ASFA.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
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.
Algorithms and Pseudocode
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
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.
Algorithms and Flowcharts
Decision Tables and Pseudocode
Learning outcomes 5 Developing Code – Using Flowcharts
Pseudocode An Introduction
Chapter 11 Describing Process Specifications and Structured Decisions
Chapter 2: Input, Processing, and Output
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
ALGORITHMS AND FLOWCHARTS
Designing and Debugging Batch and Interactive COBOL Programs
Pseudocode An Introduction
Unit# 9: Computer Program Development
Problem Solving Techniques
Understanding the Three Basic Structures
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Algorithm and Ambiguity
Introduction to Algorithms - 1
Chapter 2: Input, Processing, and Output
Pseudocode For Program Design.
Presentation transcript:

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 programming very well. Pseudocode, on the other hand, is a newer tool and has features that make it more reflective of the structured concepts. The drawback is that the narrative presentation is not as easy to understand and/or follow.

Rules for Pseudocode Write only one statement per line Capitalize initial keyword Indent to show hierarchy End multiline structures Keep statements language independent

One Statement Per Line Each statement in pseudocode should express just one action for the computer. If the task list is properly drawn, then in most cases each task will correspond to one line of pseudocode. Task List Read name, hours worked, rate of pay Perform calculations gross = hours worked * rate of pay Write name, hours worked, gross Pseudocode READ name, hoursWorked, payRate gross = hoursWorked * payRate WRITE name, hoursWorked, gross

Capitalize Initial Keyword In the example below note the words: READ and WRITE. These are just a few of the keywords to use, others include: READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE Pseudocode READ name, hoursWorked, payRate gross = hoursWorked * payRate WRITE name, hoursWorked, gross

Indent to Show Hierarchy Each design structure uses a particularindentation pattern Sequence: Keep statements in sequence all starting in the same column Selection: – Indent statements that fall inside selection structure, but not the keywords that form the selection Loop: – Indent statements that fall inside the loop but not keywords that form the loop

READ name, grossPay, taxes IF taxes > 0 net = grossPay – taxes ELSE net = grossPay ENDIF WRITE name, net

End Multiline Structures See the IF/ELSE/ENDIF as constructed above, the ENDIF is in line with the IF. The same applies for WHILE/ENDWHILE etc… READ name, grossPay, taxes IF taxes > 0 net = grossPay – taxes ELSE net = grossPay ENDIF WRITE name, net

Language Independence Resist the support to write in whatever language you are most comfortable with, in the long run you will save time. Remember you are describing a logic plan to develop a program, you are not programming!

The Selection Structure amount < 100 interestRate =.06interestRate =.10 yesno IF amount < 100 interestRate =.06 ELSE Interest Rate =.10 ENDIF Pseudocode 

The Looping Structure In flowcharting one of the more confusing things is to separate selection from looping. This is because each structure use the diamond as their control symbol. In pseudocode we avoid this by using specific keywords to designate looping WHILE/ENDWHILE REPEAT/UNTIL

WHILE / ENDWHILE Start count = 0 count <10 add 1 to count write count Write “The End” Stop count = 0 WHILE count < 10 ADD 1 to count WRITE count ENDWHILE WRITE “The End” Mainline count = 0 WHILE count < 10 DO Process ENDWHILE WRITE “The End” Process ADD 1 to count WRITE count  Modular

REPEAT / UNTIL Start count = 0 count <10 add 1 to count write count Write “The End” Stop count = 0 REPEAT ADD 1 to count WRITE count UNTIL count >= 10 WRITE “The End” Mainline count = 0 REPEAT DO Process UNTIL count >= 10 WRITE “The End” Process ADD 1 to count WRITE count  Modular

Advantages & Disadvantages Flowchart Advantages: Standardized Visual Pseudocode Advantages Easily modified Implements structured concepts Done easily on Word Processor Flowchart Disadvantages: Hard to modify Structured design elements not implemented Special software required Pseudocode Disadvantages: Not visual No accepted standard, varies from company to company

Access of Data The READ statement tells the computer to get a value from an input device and store it in a memory location. How to deal with memory locations? Memory locations are identified by their addresses, we give them names (field names / variable names) using words descriptive to us such as ctr as opposed to a location addresses such as

Rules for Variable Names  Begin with lowercase letter  Contain no spaces  Additional words begin with capital  Unique names within code  Consistent use of names

Working with Fields Calculations +add - subtract * multiply / divide ** or ^ exponentiation ( ) grouping Selection > greater than < less than = equal to >= greater than or equal to <= less than or equal to <> not equal to