22
Chapter 2: Problem Solving Method Introduction •Program Development Life Cycle • Selection and Looping/Iteration Structure Design • Problem Solving Examples

Programming

Embed Size (px)

DESCRIPTION

Introduction to visual basic

Citation preview

Page 1: Programming

Chapter 2:

Problem Solving Method• Introduction

•Program Development Life Cycle

• Selection and Looping/Iteration Structure Design

• Problem Solving Examples

Page 2: Programming

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: Programming

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: Programming

1. Problem Understanding

Before we can solve 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: Programming

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. • 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: Programming

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: Programming

Flow chart basic symbol

SymbolSymbol MeaningMeaning

Process –command execution that transform Process –command execution that transform input to outputinput to output

Input / output –data entered or result displayedInput / output –data entered or result displayed

Arrow –connecting command sequenceArrow –connecting command sequence

Condition/testing –rules that determine certain Condition/testing –rules that determine certain path to followpath to follow

Start / End Start / End

Joint/Connecter –connect flow chart to other Joint/Connecter –connect flow chart to other pagepage

Page 8: Programming
Page 9: Programming

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. MaintenanceIn 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: Programming

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 11: Programming

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 12: Programming

3. ‘CASE’ Structure Control

Situation 1

Situation 3

Situation 2

Action 1

Action 2

Action 3

yes

yes

yes

no

no

no

Syarat /Case 1

Syarat /Case 3

Syarat /Case 2

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

Page 13: Programming

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 use

• Algorithm design by developing pseudo code and flow chart

Page 14: Programming

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 15: Programming

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 16: Programming

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 17: Programming

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 18: Programming

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(Celcius)Temperature(Celcius) StatusStatus0-300-30 ColdCold

30-5030-50 MediumMedium

50-7050-70 HotHot

70-10070-100 Very HotVery Hot

Page 19: Programming

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 unitFirst 100 unit RM 20.00RM 20.00

Exceed 100 and less Exceed 100 and less than 300than 300

RM 0.22 per unitRM 0.22 per unit

Greater 300 unit and Greater 300 unit and aboveabove

RM 0.28 per unitRM 0.28 per unit

Page 20: Programming

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 Annual income less than RM 4000RM 4000

Income zakat waiveIncome zakat waive

Annual income greater Annual income greater than RM 4000than RM 4000

Zakat subjected : 2.5% Zakat subjected : 2.5% from annual incomefrom annual income

Page 21: Programming

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)Weight (kg) Cost (RM) per kgCost (RM) per kg

0 - 20 - 2 2.502.50

2.1 - 52.1 - 5 3.803.80

5.1 - 105.1 - 10 6.006.00

10.1 - 2010.1 - 20 10.0010.00

Greater than 20Greater than 20 VoidVoid

Page 22: Programming

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