Professional Documents
Culture Documents
2. Pseudocode
• List of instructions in correct sequence
• Must use simple language
Prepared by Assoc Prof Dr Junita Mohamad
3
Saleh
Flowchart: uses symbols
• Input/Output/
Get A, B C=319 Display C
Assignment
Print V Output M
• Process R= R1 + R2
Calculate power = I*V
Compute regression
4
Prepared by Assoc Prof Dr Junita Mohamad Saleh
(cont) Flowchart: uses symbols
• Condition: if
No/false
if C > 600 if N == 0?
Yes/true
No/false Yes/true
• Loop: while
No/false
C > 600 ? N != 0?
Yes/true
No/false Yes/true
• Function execution
• (use function name in the symbol)
6
Prepared by Assoc Prof Dr Junita Mohamad Saleh
(cont) Flowchart: uses symbols
• Control flow
– Control flow can point forward, backward or in a loop.
• Must end with the word “end”
• Words commonly used in a pseudocode:
– Input: get, enter, assign or use assignment statement e.g.
A=38
– Process: compute, calculate, sort, arrange or use equation
– Condition: if, while, for, do‐while
Prepared by Assoc Prof Dr Junita Mohamad
8
Saleh
Example 1
• Draw a flowchart and write the pseudocode for a process
to print the sentence “Learn C++ without fear”
Flowchart Pseudocode
start
start
Print “Learn C++ without fear”
Display “Learn C++
without fear” end
end
Prepared by Assoc Prof Dr Junita Mohamad
9
Saleh
Example 2: Flowchart
start
• Draw a flowchart and
write a pseudocode for get
a program which A, B
computes the addition
of two integer values, C=A+B
A and B and displays
the result.
print C
end
Prepared by Assoc Prof Dr Junita Mohamad
10
Saleh
Example 2: Pseudocode
Write a pseudocode to compute the addition of two integer
values.
Start
Get value of first integer, A
Get value of second integer, B
Compute total, C=A+B
Display C
End
Prepared by Assoc Prof Dr Junita Mohamad
11
Saleh
Quiz 1
Prepare a flowchart for a C++ program
which calculates the total resistance for
a circuit with 3 resistors in series. The
resistance values are obtained from
user. Then display the result.
Prepared by Assoc Prof Dr Junita Mohamad
12
Saleh
Answer to Quiz 1
start
get
R1, R2 and R3
Total = R1 + R2 + R3
print Total
end
13
Prepared by Assoc Prof Dr Junita Mohamad Saleh
Example1: User-defined functions
Write a program to get two numbers and print the
numbers either in ascending or descending order based
on user preference.
yes
get_number
yes
GetInputs
yes choice == no
’a’||’A’
Compute_
Compute Perimeter
_Area
Display
result end