Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University...

26
Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003 Friday 1/24/2003

Transcript of Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University...

Page 1: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

Program Flowchart, Pseudocode & Algorithm development

School of BusinessEastern Illinois University

© Abdou Illia, Spring 2003

Week 2:

Wednesday 1/22/2003

Friday 1/24/2003

Page 2: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

2Project 1

Exercise # 8, page 57Bohl & Rynn’s textbook

Due date: February 3rd, 2003

Page 3: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

3Learning Objectives

Understand the relation between Algorithm and Pseudocode or program flowchart

Draw flowcharts

Write pseudocodes

Page 4: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

4Recall form Class 2 & 3

Use of tools by analyst/programmer in SDLC

Design/Programming tools used for:– Specifying problem-solving logic

Pseudocode:

English-language statements that describe the processing steps of a

program in paragraph form.

STARTREAD EMPLOYEE DATACOMPUTE GROSS PAYCOMPUTE DEDUCTIONSCOMPUTE NET PAYWRITE EMPLOYEE PAYCHECKSTOP

Example

Page 5: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

5Algorithm ?

Step-by-step procedure to solve a problem

An algorithm can be expressed using:– A System Flowchart– A Program Flowchart– A Pseudocode, etc.

Any algorithm must meet the following requirements:– Use operations from only a given set of basic operations

(+,-,/,*,<,>…)– Produce solution in a finite number of such operations

Page 6: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

6Example of algorithm (program flowchart)

REGSALES = Regular sales amount

SALESALES = Reduced sales amount

REGCOM = Regular commission (6%)

SALESCOM = Sales commission (3%)

PAY = Total pay due

Algorithm for determining salespersons’ pay

I

P

O

Page 7: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

7Algorithm vocabulary

START

STOP

SYMBOLS NAME

Terminal interrupt symbols

USE

Terminal point (start, stop, or break)

Input/Output symbol Reading data from an input medium or writing data to an output medium

Process symbol Processing input data

Page 8: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

8Algorithm vocabulary

SYMBOLS NAME

Flowline symbol

USE

Sequence of operations and direction of data flow

Decision symbol Decision-making operations

Predefined-process symbol

Operations specified elsewhere (not in the current algorithm)

Page 9: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

9Algorithm vocabulary

SYMBOLS NAME

Connector symbol

USE

Exit to, or entry from, another part of the Flowchart

Preparation symbol Control operations: Set limit on loop-control variables, Initialize accumulators, etc.

Page 10: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

10Algorithm vocabulary

Variables

Data independence

Assignment statement

Constant

Data items whose values may change, or vary during processing

Using Variables instead of their specific values gives a program the capacity to perform processing on any set of input data.

Statement that assign a value (calculated or not) to a variable

A value that doesn’t change

REGCOM =REGSALES

*.06

READREGSALES,SALESALES

READ$1000,$3000

.06

Item Meaning Example Comment1) Variables names are place-holders for values

2) Variable names are chosen by programmer

3) Names should be descriptive

The computer will perform the calculation first, and then, assign the result to REGCOM

Page 11: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

11IFTHENELSE / DECISION SYMBOL

Is Condition

True ?

Processing 1

Processing 2

Processing 3

:

:

:

:

General form

AMOUNT> 200 ?

DISCOUNT =AMOUNT * .10

SUBBIL =AMOUNT –DISCOUNT

SUBBIL=AMOUNT

:

:

An ExampleREAD

AMOUNT

YESNO YESNO

Could be many

processings,…

Could be many processings,…

Page 12: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

12Exercise 1: Tuition bill Problem

Write the program flowchart to prepare a tuition bill. The input will contain the student name, Social Security Number, and total number of credits for which the student has enrolled. The bill will contain the student name, Social Security Number, and computed tuition. Total credits of 10 or more indicate that the student is full-time. Full-time students pay a flat rate of $1000 for tuition. Total credits of less than 10 indicate that the student is part-time. Part-time students pay $100 per credit for tuition.

Exercise 11 (Chapter 3)

Page 13: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

13Exercise 1’s solution: (Part 1: System Flowchart)

(To be done in class)

Page 14: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

14Exercise 1 solution: (Part 2: Program Flowchart)

(To be done in class)

Page 15: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

15Project 1

Write a program flowchart and corresponding pseudocode to solve the following problem: Assume the input for a student is name, student number, and three grades. Output the student name and an S (Success) if the average of the three grades is 65 or more. Otherwise (else), output the student’s name, a U (Unsuccess), and the number of additional points needed for an S.

Page 16: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

16Exercise 2: Billing problem

Look at the program flowchart on the next slide, and answer the following questions:

(a) For what variables are values read as input ?

(b) What variables’ values are output ?

(c) What constants are used ?

(d) Simulate the execution of this algorithm, assuming the values shown below are read as input for the first four variables named.

Exercise 11 (Chapter 2)

Blouse

3

49.99

Mrs. A. B. Wallace

ITEM

QTY

PRICE

AMTOD

DISCOUNT

NAME

SUBBILL

TAXES

BILL

Page 17: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

17Exercise 2: Billing problem

Exercise 11 (Chapter 2)

START

READ NAME, ITEM, QTY,

PRICE

AMTOD =

QTY * PRICE

DISCOUNT =

AMTOD * .10

SUBBILL =

AMTOD - DISCOUNT

TAXES =

SUBBILL * .05

BILL =

SUBBILL + TAXES

WRITE NAME, ITEM, BILL

STOP

Page 18: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

18Exercise 1 solution: Program Flowchart & corresponding Pseudocode

READ

NAME, SSN, CREDITS

WRITE

NAME, SSN, TUITION

CREDITS

≥ 10 ?

TUITION = 1000TUITION =

100 * CREDITS

START

STOP

Start

Read NAME, SSN, CREDITS

IF CREDITS >= 10 THEN

TUITION = 1000

ELSE

TUITION = 100 * CREDITS

ENDIF

Write NAME, SSN, TUITION

Stop

Pseudocode for Tuition problem

NO YES

Page 19: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

19Pseudocode

Other common way to represent algorithms

Similar to programming languages like Visual Basic but– Does not require strict rules as programming languages

Start

Read NAME, SSN, CREDITS

IF CREDITS >= 10 THEN

TUITION = 1000

ELSE

TUITION = 100 * CREDITS

ENDIF

Write NAME, SSN, TUITION

Stop

Pseudocode for Tuition problem (see Slide12)

UPPERCASE for variable names

UPPERCASE for Reserved words

Lowercase for non- reserved wordsTitlecase

Page 20: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

20Pseudocode

Start

Read NAME, SSN, CREDITS

IF CREDITS >= 10 THEN

TUITION = 1000

ELSE

TUITION = 100 * CREDITS

ENDIF

Write NAME, SSN, TUITION

Stop

Pseudocode for Tuition problem (see Slide12)

Use of indentation (i.e. clauses are indented a few positions) for

clarity

Page 21: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

21Exercise 3: Weekly Payroll problem

Construct a program flowchart and corresponding pseudocode to solve the following problem: ABC company needs a weekly payroll report for its salespeople. Input to the program is a salesperson’s name, number, and weekly sales. Output is the salesperson’s name, number, and pay. Each salesperson receives a base pay of $300 as well as a 10% commission on his or her total sales up to and including $500. Any sales over $500 merit a 15% commission for the employee. (For example, if sales = $600, then pay = $300 + $50 [or .10 * 500] + $15 [.15 * 100] = $350). Use a DOWHILE loop and a counter to compute the weekly payroll for exactly 20 employees.

Exercise 19 (Chapter 4)

Page 22: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

22Exercise 3’s solution: (Part 1: System Flowchart)

NAME, NUM, SALES

WEEKLY PAYROLL PROGRAM

NAME, NUM, PAY

Page 23: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

23Exercise 3 solution: (Part 2: Program Flowchart)

(To be done in class)

Page 24: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

24Exercise 3 solution: (Part 3: Pseudocode)

(To be done in class)

Page 25: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

25Algorithm Development Process

Design verification, in order to:– Prevent errors from occurring– Detect and correct errors soon

Selection of Review Team members for:– Informal design review or– Structured design review

Structured Design Review:– Selection of representative values of input (data normally expected,

extreme values, invalid data)– Following designed algorithms to determine what output are produce.

Page 26: Program Flowchart, Pseudocode & Algorithm development School of Business Eastern Illinois University © Abdou Illia, Spring 2003 Week 2: Wednesday 1/22/2003.

26Summary Questions

1. Distinguish between Algorithm on the one hand, and Program flowchart and Pseudocode on the other hand. Discuss the relations between the two.

2. (a) List the main keywords used in Pseudocodes. (b) What control structures they represent.

You should know how to design program logic using Program Flowcharts & Pseudocodes (Review Exercises 1,2,3 above & Exercise 15 Ch.4 and answer on page 339)