2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:



Similar documents
Creating Basic Excel Formulas

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Performing Simple Calculations Using the Status Bar

Exponents. Exponents tell us how many times to multiply a base number by itself.

Direct Translation is the process of translating English words and phrases into numbers, mathematical symbols, expressions, and equations.

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

Accentuate the Negative: Homework Examples from ACE

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

ALGORITHMS AND FLOWCHARTS

PL / SQL Basics. Chapter 3

VB.NET Programming Fundamentals

Flowcharting, pseudocoding, and process design

Order of Operations More Essential Practice

The Order of Operations Redesigned. Rachel McCloskey Dr. Valerie Faulkner

2 SYSTEM DESCRIPTION TECHNIQUES

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Chapter One Introduction to Programming

Flowchart Techniques

Exponential Notation and the Order of Operations

Programming Logic and Design Eighth Edi(on

Chapter 8 Selection 8-1

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Please Excuse My Dear Aunt Sally

1.4 Compound Inequalities

Chapter 2: Linear Equations and Inequalities Lecture notes Math 1010

Chapter 3 Problem Solving

Algorithms, Flowcharts & Program Design. ComPro

Make sure you look at the reminders or examples before each set of problems to jog your memory! Solve

Pre-Algebra - Order of Operations

Notes on Algorithms, Pseudocode, and Flowcharts

Chapter 1 An Introduction to Computers and Problem Solving

3.GETTING STARTED WITH ORACLE8i

Review of Fundamental Mathematics

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed

Visual Logic Instructions and Assignments

Summer Assignment for incoming Fairhope Middle School 7 th grade Advanced Math Students

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Problem Solving Basics and Computer Programming

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Informatica e Sistemi in Tempo Reale

MATLAB Programming. Problem 1: Sequential

1.2 Linear Equations and Rational Equations

Semester Exam Review ANSWERS. b. The total amount of money earned by selling sodas in a day was at least $1, F 200 F

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

The Center for Teaching, Learning, & Technology

Linear Equations in One Variable

Brain Game. 3.4 Solving and Graphing Inequalities HOW TO PLAY PRACTICE. Name Date Class Period. MATERIALS game cards

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

I PUC - Computer Science. Practical s Syllabus. Contents

2.6 Exponents and Order of Operations

Basic Use of the TI-84 Plus

Warm-Up. Today s Objective/Standards: Students will use the correct order of operations to evaluate algebraic expressions/ Gr. 6 AF 1.

CS 241 Data Organization Coding Standards

The Order of Operations Redesigned. Rachel McCloskey Dr. Valerie Faulkner

Quick Reference ebook

JavaScript: Control Statements I

To Evaluate an Algebraic Expression

My EA Builder 1.1 User Guide

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Formulas, Functions and Charts

The Little Man Computer

Spreadsheets Hop-around Cards

Unit 6 Number and Operations in Base Ten: Decimals

Sources: On the Web: Slides will be available on:

Using Casio Graphics Calculators

Section 1.5 Exponents, Square Roots, and the Order of Operations

Grade 7/8 Math Circles Sequences and Series

Properties of Real Numbers

Basic Formulas in Excel. Why use cell names in formulas instead of actual numbers?

Introduction to Python

Pseudo code Tutorial and Exercises Teacher s Version

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Algebra Cheat Sheets

7 th Grade Integer Arithmetic 7-Day Unit Plan by Brian M. Fischer Lackawanna Middle/High School

Answers to Review Questions Chapter 7

Kids College Computer Game Programming Exploring Small Basic and Procedural Programming

Session 7 Fractions and Decimals

Accredited Specimen Mark Scheme

Expanding Expression Tool

Clock Arithmetic and Modular Systems Clock Arithmetic The introduction to Chapter 4 described a mathematical system

HFCC Math Lab Beginning Algebra 13 TRANSLATING ENGLISH INTO ALGEBRA: WORDS, PHRASE, SENTENCES

LINEAR INEQUALITIES. less than, < 2x + 5 x 3 less than or equal to, greater than, > 3x 2 x 6 greater than or equal to,

TEST FOR EXECUTIVE SECRETARY

26 Integers: Multiplication, Division, and Order

Conditionals: (Coding with Cards)

Click on the links below to jump directly to the relevant section

Q&As: Microsoft Excel 2013: Chapter 2

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming

=

Toothpick Squares: An Introduction to Formulas

COLLEGE ALGEBRA 10 TH EDITION LIAL HORNSBY SCHNEIDER 1.1-1

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Grade 4 - Module 5: Fraction Equivalence, Ordering, and Operations

Accuplacer Arithmetic Study Guide

Multiplication Rules! Tips to help your child learn their times tables

Transcription:

Pseudocode: An Introduction Flowcharts were the first design tool to be widely used, but unfortunately they do t very well reflect some of the concepts of structured programming. Pseudocode, on the other hand, is a newer tool and has features that make it more reflective of the structured concepts. Unfortunately, the narrative presentation is t as easy to understand and follow. RULES FOR PSEUDOCODE 1. Write only one stmt per line Each stmt in your 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. EX: TASK LIST: Read name, hourly rate, hours worked, deduction rate Perform calculations gross = hourlyrate * hoursworked deduction = grosspay * deductionrate net pay = grosspay deduction Write name, gross, deduction, net pay PSEUDOCODE: READ name, hourlyrate, hoursworked, deductionrate grosspay = hourlyrate * hoursworked deduction = grosspay * deductionrate netpay = grosspay deduction WRITE name, grosspay, deduction, netpay 2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use: READ, WRITE, IF,,, WHILE, ENDWHILE, REPEAT, UNTIL 3. Indent to show hierarchy We will use a particular indentation pattern in each of the design structures: SEQUENCE: keep statements that are stacked in sequence all starting in the same column. SELECTION: indent the statements that fall inside the selection structure, but t the keywords that form the selection

LOOPING: indent the statements that fall inside the loop, but t the keywords that form the loop EX: In the example above, employees whose grosspay is less than 100 do t have any deduction. TASK LIST: Read name, hourly rate, hours worked, deduction rate Compute gross, deduction, net pay Is gross >= 100? YES: calculate deduction NO: deduction Write name, gross, deduction, net pay PSEUDOCODE: READ name, hourlyrate, hoursworked grosspay = hourlyrate * hoursworked IF grosspay >= 100 deduction = grosspay * deductionrate deduction = 0 netpay = grosspay deduction WRITE name, grosspay, deduction, netpay 4. End multiline structures See how the IF// is constructed above. The (or END whatever) always is in line with the IF (or whatever starts the structure). 5. Keep stmts language independent Resist the urge to write in whatever language you are most comfortable with. In the long run, you will save time! There may be special features available in the language you plan to eventually write the program in; if you are SURE it will be written in that language, then you can use the features. If t, then avoid using the special features.

SELECTION STRUCTURE We looked at this in Chap 2: amount < 1000 interestrate =.06 interestrate =.10 The pseudocode for this would be: IF amount < 1000 interestrate =.06 interestrate =.10 // the or true action // the or false action Some selections are of the do it or don t (one sided) variety. For example: DO SendWarning average < 60? The pseudocode for this is: IF average < 60 DO SendWarning

It is considered poor form to have a 1-sided IF stmt where the action is on the or side. Consider this code: IF average < 60 NULL DO GivePassingGrade This could (and should) be rewritten to eliminate the NULL part. To do that, we change the < to its opposite: >= as follows: IF average >= 60 DO GivePassingGrade NESTING IF STATEMENTS What if we wanted to put a little menu up on the screen: 1. Solitaire 2. Doom 3. Mopoly and have the user select which game to play. How would we activate the correct game? READ gamenumber IF gamenumber = 1 DO Solitaire IF gamenumber = 2 DO Doom DO Mopoly DO Solitaire READ gamenumber gamenumber = 1? gamenumber = 2? DO Doom DO Mopoly We must pay particular attention to where the IFs end. The nested IF must be completely contained in either the IF or the part of the containing IF. Watch for and line up the matching.

LOOPING STRUCTURES One of the most confusing things for students first seeing a flowchart is telling the loops apart from the selections. This is because both use the diamond shape as their control symbol. In pseudocode this confusion is eliminated. To mark our loops we will use these pairs: WHILE / ENDWHILE REPEAT / UNTIL START The loop shown here (from the last chapter) will have the following pseudocode: Count = 0 Count < 10 Add 1 to count Write The end count = 0 WHILE count < 10 ADD 1 to count WRITE count ENDWHILE WRITE The end Notice that the connector and test at the top of the loop in the flowchart become the WHILE stmt in pseudocode. The end of the loop is marked by ENDWHILE. Write count STOP What statement do we execute when the loop is over? The one that follows the ENDWHILE. Sometimes it is desirable to put the steps that are inside the loop into a separate module. Then the pseudocode might be this: Mainline count = 0 WHILE count < 10 DO Process ENDWHILE WRITE The end Process ADD 1 to count WRITE count We often use this name for the first module. Initialization comes first The processing loop uses this module Termination does clean-up Go thru these steps and then return to the module that sent you here (Mainline)

START Count = 0 Add 1 to count Write count This time we will see how to write pseudocode for an UNTIL loop: count = 0 REPEAT ADD 1 to count WRITE count UNTIL count >= 10 WRITE The end Notice how the connector at the top of the loop corresponds to the REPEAT keyword, while the test at the bottom corresponds the the UNTIL stmt. When the loop is over, control goes to the stmt following the UNTIL. Count >= 10 Write The end STOP

ADVANTAGES AND DISADVANTAGES Pseudocode Disadvantages It s t visual There is accepted standard, so it varies widely from company to company Pseudocode Advantages Can be done easily on a word processor Easily modified Implements structured concepts well Flowchart Disadvantages Hard to modify Need special software (t so much w!) Structured design elements t all implemented Flowchart Advantages Standardized: all pretty much agree on the symbols and their meaning Visual (but this does bring some limitations) HOW WE STORE AND ACCESS DATA What happens when we execute READ stmt? READ name, hoursworked, hourlyrate, deductionrate The computer stores all program data into memory locations. It kws these location by their addresses. It is perfectly able to understand code like: READ 19087, 80976, 10943, 80764 but we would have a hard time with it. So we name our storage locations using words that are descriptive to us. Every language has its own (different) set of rules about how these names are formed. We will use a simple style: variable names will start with a lowercase letter they will have spaces in them additional words in them will start with a capital names must be unique within the program consistent use of names The READ statement tells the computer to get a value from the input device (keyboard, file, ) and store it in the names memory location. When we need to compute a value in a program (like grosspay) we will use what is called an assignment stmt. variable = expression Be careful to understand the difference between these two stmts: num1 = num2 num2 = num1

The WRITE stmt is used to display information on the output device (screen, printer). To display words, enclose them in quotes. A variable s value will be displayed. So if the variable name currently contains John Smith, then the stmt WRITE Employee name:, name will output like this: Employee name: John Smith CALCULATION SYMBOLS We will often have to represent an expression like the one that computes grosspay. To symbolize the arithmetic operators we use these symbols grouping ( ) exponent ** or ^ multiply * divide / add + subtract - There is a precedence or hierarchy implied in these symbols. ORDER OF EXECUTION ( ) equations in parenthesis ** exponentiation Please Excuse My Dear Aunt Sally / * division and multiplication + - addition and subtraction Note: when operators of equal value are to be executed, the order of execution is left to right. Examples: AREA = R 2 SUM = A 2 + B 2 PERIM = 2(L + W) A A A C C B C B B A BC D 2 C B 2 D B C value = 100*2/5-3 = 200/5-3 = 40-3 = 37 value = 100*2/(5-3) = 100*2/2 = 200/2 = 100 value = 100*((2/5)-3) = 100*(.4-3) = 100*-2.6 = -260

SELECTION When we have to make a choice between actions, we almost always base that choice on a test. The test uses phrases like is less than or is equal to. There is a universally accepted set of symbols used to represent these phrases: > (greater than) < (less than) >= (greater than or equal to) <= (less than or = (equal to) <> (t equal to) It is interesting to tice that these can be paired up: SYMBOL IS OPPOSITE TO > <= < >= = <> LOGICAL OPERATORS: AND, OR, NOT AND: if any of the conditions are false, the whole expression is false. ex: IF day = Saturday AND weather = sunny WRITE Let s go to the beach! OR: if any of the conditions are true, the whole expression is true ex: IF month = June OR month = July OR month = August WRITE Yahoo! Summer vacation! NOT: reverses the outcome of the expression; true becomes false, false becomes true. ex: IF day <> Saturday AND day <> Sunday WRITE Yuk, ather work day