Top Banner
Muhamad Rizal Bin Mohamed Razali Programming Concept / ISD Introduction
30
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chap3

Muhamad Rizal Bin Mohamed RazaliProgramming Concept / ISD

Introduction

Page 2: Chap3

Course Work BreakdownQuiz =5%Midterm =15%()Assignment=15%()Lab=15%Final =50%

Page 3: Chap3

Learning GoalsAt the end of this module student will be

able:Read the C programDesign pseudocode and flow chatWrite C program using selection , looping

pointer and function command.

Page 4: Chap3

Outcome 3 Introduction & ObjectiveBefore we start writing a programming it is

essential to have a thorough understanding of the problem and carefully planned approach to solve the problem.

We can use Pseudocode Flow chartmethod how to solve the problem

Page 5: Chap3

Outcome 3Algorithm is a sequence of steps or

procedure to solve the problem.Example:-

Let say you have a friend to enroll as a student at your collage. Can u tell your friend how he/she can enroll as a student at your collouge.

Page 6: Chap3

Manual process for enrollment1. Go to the receptionists counter 2. Ask registration form3. Fill all the particulars4. Submit the form

Page 7: Chap3

Online process for enrollment1. Login to the collage website2. Click at the registration form3. Fill up the form4. Click submit button

Page 8: Chap3

Cont…Can you give me example algorithm how to

cook Nasi goreng ?

Page 9: Chap3

Cont..You have several algorithm to achieve the

same goal Every algorithm has a different cost and

time to accomplish.

Page 10: Chap3

PseudocodeAn outline of a program written in

English or the user's natural language; it is used to plan the program, and also serves as a source for test engineers doing software maintenance, it cannot be compiled.

You can write pseudocode without even knowing what programming language you will use for final implementation

Page 11: Chap3

Why needs pseudocode?1. Designing algorithms2. Communicating algorithm to users3. Implementing algorithms as programs4. Debugging logic error in programs 5. Documenting programs for future

maintenance and expansion purpose

Page 12: Chap3

How to write pseudocode1. Have a limited vocabulary2. Be easy to learn3. Produce simple instruction or simple

English like narrative notation4. Be capable of describing all algorithm ,

regardless of their complexity

Page 13: Chap3

Pseudocode Meaning

Read name Read a value from input device and store it under the specified name

Write name Write the value stored under the name to the output device

Write string Write whatever appears in the string

name = expression Evaluate the expression and store it under specified name

IF condition THEN statements In the condition is true then execute the statements otherwise ignore them

FOR counter = 1 TO n DO statements

Execute the statements ‘n’ times

REPEAT Statements UNTIL condition

Repeat the statements over and over until the condition is true

Page 14: Chap3

Case studyWrite a pseudcedo to show how to

withdraw money at ATM machine

Page 15: Chap3

Insert ATM cardKey in passwordChose withdraw menuChose type of accountEnter amountRemove ATM cardKeep the money

Page 16: Chap3

Flow ChartFlow chart is a schematic representation of

a processFlow chart is a graph consisting of

geometrical shapes that are connected by flow lines

In order to use flowcharts to communicate algorithms we must develop some convention for its symbols

Page 17: Chap3

Cont..

The basic flow chart symbols are as below:-

Page 18: Chap3

Descriptions Symbols

Start / End

Input / output

Processing / computational

Decision making /selection

Flow line

Page 19: Chap3

Cont…Draw a flow chart based on the

pseudocode below.display “enter your name”accept first _namedisplay “Enter your I/C number”accept ic_numberdisplay “enter your how many days you

works:”accept days _your _workcompute salary= 5.5 X days_your_work display first_name , days your work , “your

salary this month”,salary

Page 20: Chap3

Cont

Salary = 5.5 X how many days

Display first name I/C numbers & salary

Start

Enter first name

Read first name

Enter I/C number

Read how many days

Enter how many days

Read I/C number

End

Page 21: Chap3

Control StructureA control structure is a design that

determines the logic order of program instructions

Have 3 types of control structuresSequence control structureSelection control structureRepetition control structure

Page 22: Chap3

The sequence Control StructureIs a series of steps or statements that are

executed in order they are written in an algorithm

Page 23: Chap3

Selection control structureThe selection control structure defines two

courses of action depending on the outcome of a condition

The selection structure requires use of the keywords if and else.

Page 24: Chap3

Example…If password true

Chose withdraw menuChose account typeRemove ATM cardKeep the money

Else Reenter the password

Page 25: Chap3

Nested selection structureNested selection structure is a basic

selection structure that contains other if/else structure in it’s then part or else part

Useful for multi way decision making

Page 26: Chap3

Cont..If password true

If menu equal balance enquiry Chose account type

Else If menu equal withdrawChose account type

ElsePlease enter the correct menuEnd if

Else Reenter the password

End if

Page 27: Chap3

Repetition Control structureThe repetition structure permits a

sequence of instruction be executed repeatedly until a certain condition is reached

Page 28: Chap3

Cont..enter the password

While enter password not equal actual password

beginRepeat ask user to enter the passwordif user enter 3 times wrong password block the user

end

Page 29: Chap3

SummaryYou learn concept of problem solvingAlgorithm is sequence of a finite numbers

of step arrange in a specific logical order.Algorithm can described in term of three

basic control structure SequenceSelectionrepetition

Page 30: Chap3

QuestionsGet two numbers as input from the user

and display the sum of the two numbers to the screen.

Get a series of 5 integers and display the total

Read two numbers and compare which number is smaller and display the result

Read 3 numbers and print the largest number