basic operators & flowcharts
basic operators & flowcharts
Fundamentals
Lecture # 04
2
Introduction to Flowcharts
Name Symbol Use in flowchart
On-page Connector Denotes the connection of flow chart element on same page.
Preprocessor
4
Mathematical Operators
5
Relational Operators
6
Logical Operators
7
The Flowchart
● Dictionary Definition: A schematic representation of a sequence of
operation, as in a manufacturing process or computer program
● Technical Definition: A graphical representation of the sequence of
operations in an information system or program
○ Program flowcharts: show the sequence of instructions in a single program or
subroutine
● Different symbols are used to draw each type of flowchart
8
The Flowchart
● A flowchart
○ Shows logic of an algorithm
○ Emphasizes individual steps and their interconnections
End
10
Class Task
● Draw flow chart for the following task
● Take 3 numbers from the user and print the average and sum of these three numbers
11
If selection structure
● Generic Format
false
12
if Selection Structure
Translation into Algorithm
If student’s grade is greater than or equal to 60
Print “Passed”
if ( marks >= 60 )
print "Passed";
● if structure
○ Single-entry/single-exit
13
if Selection Structure
● Flowchart of pseudocode statement
false
Start
14
Example 2: Flow chart declare M1, M2, M3,
M4, average
Pseudocode:
1.0 Start Input M1, M2,
M3, M4
2.0 Declare M1, M2, M3, M4, average
average = (M1 +
3.0 Input M1, M2, M3, M4 M2+M3+M4)/4
4.0 average = (M1+ M2+ M3+ M4) / 4
5.0 if (average > 50) then true average >=
60
5.1 Print “PASS”
false
6.0 endif
Print
7.0 End “PASS”
End
15
if/else Selection Structure
● General Structure
endif
16
if/else Selection Structure
● if
○ Performs action if condition true
● if/else
○ Different actions if conditions true or false
Pseudocode
if student’s grade is greater than or equal to 60
print “Passed”
else
print “Failed”
if ( grade >= 50 )
Print "Passed";
else
Print "Failed";
17
if/else Selection Structure
false true
grade >= 50
print print
“Failed” “Passed”
Start
18
Example 3: Flow chart declare M1, M2, M3,
M4, average
Pseudocode:
1.0 Start Input M1, M2,
M3, M4
2.0 Declare M1, M2, M3, M4, average
3.0 Input M1, M2, M3, M4 average (M1 +
4.0 average = (M1+ M2+ M3+ M4) / 4 M2+M3+M4)/4
5.0 if (average >= 50) then
5.1 Print “PASS” true average >= false
6.0 else 50
6.1 Print “FAIL”
7.0 endif
Print “PASS” Print “FAIL”
8.0 End
End
19
Example 4
● Write a pseudocode and draw a flowchart to convert the length in feet to centimeter
● Algorithm:
○ Input the length in feet (Lft)
○ Calculate the length in cm (Lcm) by multiplying Lft with 30
○ Print length in cm (Lcm)
20
Example 5
● Draw a flowchart to calculate area of a rectangle
● The program should ask the user to input Length and Width and then display the
Area.
● Area = Length * Width
21
Example 6
Draw a flowchart that reads two values, determines the largest value and prints the largest value with an identifying message
Pseudocode
1.0 Declare VALUE1, VALUE2, MAX
2.0 Input VALUE1, VALUE2
3.0 if (VALUE1 > VALUE2) then
3.1 MAX = VALUE1
4.0 else
4.1 MAX = VALUE2
5.0 end if
6.0 Print “The largest value is”, MAX
22
Questions