Muhamad Rizal Bin Mohamed RazaliProgramming Concept / ISD
Introduction
Course Work BreakdownQuiz =5%Midterm =15%()Assignment=15%()Lab=15%Final =50%
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.
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
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.
Manual process for enrollment1. Go to the receptionists counter 2. Ask registration form3. Fill all the particulars4. Submit the form
Online process for enrollment1. Login to the collage website2. Click at the registration form3. Fill up the form4. Click submit button
Cont…Can you give me example algorithm how to
cook Nasi goreng ?
Cont..You have several algorithm to achieve the
same goal Every algorithm has a different cost and
time to accomplish.
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
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
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
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
Case studyWrite a pseudcedo to show how to
withdraw money at ATM machine
Insert ATM cardKey in passwordChose withdraw menuChose type of accountEnter amountRemove ATM cardKeep the money
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
Cont..
The basic flow chart symbols are as below:-
Descriptions Symbols
Start / End
Input / output
Processing / computational
Decision making /selection
Flow line
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
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
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
The sequence Control StructureIs a series of steps or statements that are
executed in order they are written in an algorithm
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.
Example…If password true
Chose withdraw menuChose account typeRemove ATM cardKeep the money
Else Reenter the password
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
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
Repetition Control structureThe repetition structure permits a
sequence of instruction be executed repeatedly until a certain condition is reached
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
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
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