pseudo code and flow chart

25
Problem Solving Method Introduction •Program Development Life Cycle • Selection and Looping/Iteration Structure Design • Problem Solving Examples

Upload: aryzal

Post on 12-Apr-2016

78 views

Category:

Documents


4 download

DESCRIPTION

Pseudo Code and Flow Chart

TRANSCRIPT

Page 1: Pseudo Code and Flow Chart

Problem Solving Method• Introduction

•Program Development Life Cycle

• Selection and Looping/Iteration Structure Design

• Problem Solving Examples

Page 2: Pseudo Code and Flow Chart

Introduction

Problem solving refer to a process which is used to transform problem statement to solutions by using knowledge that applicable to problem domains

Page 3: Pseudo Code and Flow Chart

Program Development Life Cycle

Program Development Life Cycle (PDLC) is a framework for each steps that are used to developed computer program.

There are 6 phase in PDLC which comprise of:1. problem understanding2. problem analysis3. algorithm design4. implementation5. testing6. maintenance

Page 4: Pseudo Code and Flow Chart

1. Problem Understanding

Before we can solved a given problem, we have to carefully understand things that will be solved

2. Problem AnalysisAnalyze the problem by determining 3 important things:1. input for the program2. processing steps to transform input to output (including

rules and constraint that will be considered and also all the formula involved)

3. output produced

Page 5: Pseudo Code and Flow Chart

Algorithms refer to a procedure to solve problem that involved steps/commands that has to be executed

Each algorithms has the following properties:• clear and unambiguousness lack of confusion) • Has a general characteristic which can accept all set of data• Accuracy in solving a problems as required• Have an ending• have input and produce output

Have 2 ways to represent algorithms1. Pseudo code – algorithm explanation in a wording form by using all

kind of language that can be understand by the programmer2. Flow chart- a graphically program logic illustration that is

connected by using arrows

3. Algorithm Design

Page 6: Pseudo Code and Flow Chart

Example of Pseudo Code

PUT the purpose of the programGET the age of the individualGET the salaryCalculate the sum of the salaries in each age groupCalculate the number (count) of individuals in each age groupPUT age, averageEND

Page 7: Pseudo Code and Flow Chart

Flow chart basic symbol

Symbol Meaning

Process –command execution that transform input to output

Input / output –data entered or result displayed

Arrow –connecting command sequence

Condition/testing –rules that determine certain path to follow

Start / End

Joint/Connecter –connect flow chart to other page

Page 8: Pseudo Code and Flow Chart
Page 9: Pseudo Code and Flow Chart

After designing algorithm, then we can write and type the program code to computer. Here we can use a computer programming language

5. TestingPrograms that has been developed must be tested first by using

several different input to ensure the needs of problem that being solved is fulfill

6. MaintenancesIn an organization that use a computer program, some programs

maybe need a change from time to time to fulfill current needs

4. Implementation

Page 10: Pseudo Code and Flow Chart

HOW TO PRODUCE THE PSEUDOCODE& THE FLOW CHART- CLASS DISCUSSION-

Page 11: Pseudo Code and Flow Chart

Problem Solving Example

Compute net salary of a worker after deducted by tax. If gross salary of worker is greater than RM1000,he/she will have tax deducted of 2% from gross salary. Worker who earn gross salary of RM1000 and below will enjoy tax waive.

Solution Step

• Understand the question, the determine input, output and formulas that will be used

• Algorithm design by developing pseudo code and flow chart

Page 12: Pseudo Code and Flow Chart

Problem Solving Example

Compute net salary of a worker after deducted by tax. If gross salary of worker is greater than RM1000,he/she will have tax deducted of 2% from gross salary. Worker who earn gross salary of RM1000 and below will enjoy tax waive.

Solution Step

• Understand the question, the determine input, output and formulas that will be used

• Algorithm design by developing pseudo code and flow chart

Page 13: Pseudo Code and Flow Chart

Problem Solving Example

Input : gross salary

Process : Compute net salary from gross salary

net salary = gross salary - tax

Output : net salary

Step 1: Analyze Problem

Page 14: Pseudo Code and Flow Chart

Problem Solving Example

Enter gross salary

If gross salary greater 1000

tax = 2/100 * gross salary

else

tax = 0

Compute net salary = gross salary - tax

Display output = net salary

Step 2: Pseudo code

Page 15: Pseudo Code and Flow Chart

Problem Solving Example

Step 2: Flow Chart

START

Gross Salary

Gross Salary >= 1000

Tax = 2/100 * Gross SalaryTax = 0

Net Salary = Gross salary - tax

Net salary

END

No Yes

Page 16: Pseudo Code and Flow Chart

Selection and Looping Structure Design

1. Sequence Structure Control

Action 1

Action 2

Action 3

Sequence structure control is used to explain action arrangement by following the given order

Page 17: Pseudo Code and Flow Chart

2. Selection Control Structure

Condition

Action 1 Action 2

Selection control structure is used when it involve conditions for example “if-else” condition. This condition must be in 2 situation which is either “yes/true” if it fulfill the condition and “no/false” if vice versa.

Page 18: Pseudo Code and Flow Chart

3. ‘CASE’ Structure Control

Situation 1

Situation 3

Situation 2

Action 1

Action 2

Action 3

yes

yes

yes

no

no

no

Condition /Case 1

Condition /Case 3

Condition /Case 2

“Case” structure control is a kind of multiple selection structure

Page 19: Pseudo Code and Flow Chart

LET’S DO IT TOGETHER...Write the problem analysis and design the flow chart.....The Fantastic Floral Company sells to wholesale buyers. The following are the discounts to the wholesale buyer:AMOUNT < RM1000 →DISCOUNT=2%AMOUNT >=RM1000 AND <RM5000 →DISCOUNT=5%AMOUNT >= RM5000 →DISCOUNT=10%

Given the amount of purchase, compute the nett amount which need to be paid by the wholesale buyer to the company.

NOTE: THE SOLUTION WILL BE DISCUSSED IN THE CLASS

Page 20: Pseudo Code and Flow Chart

Exercise

1. Compute money exchange rate from USD to RM(1 USD = RM 3.80)

2. Compute average marks for 10 students from Programming in Business Application course

3. Determine the least number from 3 number entered

4. Determine number entered by user is positive, negative or null value

5. Compute the amount paid by user for petrol quantity bought (user input is in liter quantity)

Note : 1 liter petrol = RM 1.53

Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

Page 21: Pseudo Code and Flow Chart

Exercise

6. Develop a program to display the status of current temperature. Temperature status displayed is based on the followings:

Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

Temperature (Celsius) Status0-30 Cold

30-50 Medium

50-70 Hot

70-100 Very Hot

Page 22: Pseudo Code and Flow Chart

Exercise

7. Develop an application to compute the payment of electricity consumption. Input use early meter reader and late meter reader. Payment rate required are as followings:

Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

First 100 unit RM 20.00

Exceed 100 and less than 300

RM 0.22 per unit

Greater 300 unit and above

RM 0.28 per unit

Page 23: Pseudo Code and Flow Chart

Exercise

8. Develop an application to calculate income zakat payment that are required to pay by the user. Payment rate are as followings:

Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

Annual income less than RM 4000

Income zakat waive

Annual income greater than RM 4000

Zakat subjected : 2.5% from annual income

Page 24: Pseudo Code and Flow Chart

Exercise

9. Pos Malaysia have fixed the payment cost for every posted parcel are as the following table. Develop an application to compute posted payment cost based on weight entered

Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

Weight (kg) Cost (RM)

0 - 2 2.50

2.1 - 5 3.80

5.1 - 10 6.00

10.1 - 20 10.00

Greater than 20 Void

Page 25: Pseudo Code and Flow Chart

Exercise Develop programs for the following problems: (you are required to provide problem analysis and flow charts)

10. Calculate average marks for every student from three test. Determine the grade and status for average marks produce. Grading table are as following

A 81 – 100 Distinction

B 61 – 80 Good

C 51 – 60 Satisfaction

D 40 – 50 Pass

F 0 – 39 Fail