Lecture 04
Lecture 04
1
Lecture 4 Objectives
4.1 Introduction
4.2 Algorithm Design
4.3 Summary
Lecture 4 4.1 Introduction
____________________________________________________________________________________________________________________________________
Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education
Lecture 4 4.1 Introduction
System
Requirements
____________________________________________________________________________________________________________________________________
_
I Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education.
2 http://www.tiem.utk.edu/~gross/c++man/
Lecture 4 Contents
4.1 Introduction
4.2 Algorithm Design
4.3 Summary
Lecture 4 4.2 Algorithm Design
Introduction
____________________________________________________________________________________________________________________________________
Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education
Lecture 4 4.2 Algorithm Design
Pseudo-code
____________________________________________________________________________________________________________________________________
Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education
Lecture 4 4.2 Algorithm Design
Pseudo-code Example
Example 4.1: Write pseudo-code for multiplying two numbers.
Solution 4.1:
____________________________________________________________________________________________________________________________________
Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education
Lecture 4 4.2 Algorithm Design
Terminal: Indicates the start and end of a flowchart. Single flow line. Only one “Start”
and “Stop/End” terminal for each program. The end terminal for function/subroutine
must use “Return” instead of “Stop/End”.
Process: Used whenever data is being manipulated using a calculation. One flow line
enters, and one flowline exits.
Input/Output: Used whenever data is entered (input) or displayed (output). One flow
line enters, and one flow line exits.
Decision: Used to represent operations (conditions) in which there are two possible
selections. One flow line enters and two flow lines, labelled as “Yes” and “No”, exit.
Function / Subroutine: Used to identify an operation in a separate flowchart segment
(module). One flow line enters, and one flow line exits.
On-page Connector: Used to connect remote flowchart portion on the same page.
Either one flow line enters, or one flow line exits.
Off-page Connector: Used to connect remote flowchart portion on different pages.
Either one flow line enters one flow line exits.
Comment: Used to add descriptions or clarification.
Start Terminal:
Example: Make a Start
Flowchart starts here
flowchart for
multiplying two Get first number,
A Input: Enter values
numbers. Get second for A and B
number, B
Calculate Resut
C=A*B Process
Display the
Result C Output
Start
Example: Flowchart
No
Stop
Lecture 4 4.2 Algorithm Design
1
Stop
2
Lecture 4 4.2 Algorithm Design
1 2
Yes 1
No End
2
Lecture 4 4.2 Algorithm Design
The details (how the function works)
Example: we put in another flowchart.
This also known as Function-Definition
Using Function-Call
Page 1 Start terminal for a Page 2
Start Function is different.
Do not use “Start”
AVRG ( result,n1, n2,n3)
Note:
Module = Function = Read
Subroutine . n1, n2 , n3
Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart
result = sum/3
Solution 4.2:
Start
Calculate Resut
Calculate volume,
C=A*B2
V= π*h*r
Display the
Display the
Result C
result V
End
Lecture 4 4.2 Algorithm Design
Celsius = (Fahrenheit-32)*5/9)
____________________________________________________________________________________________________________________________________
_
Lecture 4 4.2 Algorithm Design
Solution 4.3:
start
1. Get temp. in
Get, F
Fahrenheit, F
2. Calculate the
Calculate
temp. in Celsius, C=(F-32)*5/9
C = (F-32)*5/9
3. Display the Display C
result, C
end
Lecture 4 4.2 Algorithm Design
Solution 4.3:
start
1. Get temp. in
Get, F
Fahrenheit, F
2. Calculate the
Calculate
temp. in Celsius, C=(F-32)*5/9
C = (F-32)*5/9
3. Display the Display C
result, C
end
Lecture 4 4.2 Algorithm Design
Solution 4.3:
start
1. Get temp. in
Get F
Fahrenheit, F
2. Calculate the
Calculate
temp. in Celsius, C=(F-32)*5/9
C = (F-32)*5/9
3. Display the Display C
result, C
end
Lecture 4 Contents
4.1 Introduction
4.2 Algorithm Design
4.3 Summary
Lecture 4 4.4 Summary
____________________________________________________________________________________________________________________________________
_
Deitel, H.M. and Deitel, P.J (2013). C How to Program 7/E. United State of America: Pearson Education