9/27/2018 1
Dr.AtifShahzad
DR ATIF SHAHZAD
Fundamentals of
Computer Systems
IE-321
LECTURE #14
9/27/2018 2
Dr.AtifShahzad
WhatWe have seen
Logic
Logical variables
Conditional, Negation, Contrapositive,Biconditional
AND, OR,NOT,XOR
Logic gates
TruthTables
BooleanAlgebra
Examples
Q&A
MicrosoftVisio
Microsoft Project
Spreadsheet Concepts:
Using Microsoft Excel
Creating Charts in Microsoft Excel
Debugging Concepts Using Microsoft Excel
Presentation Concepts Using Microsoft PowerPoint
Image Concepts
Memory
Memory Cell
CPU
Register
Program Counter
Fetch-Execute Cycle
Q&A
File Management
Word Processing Basics Using MicrosoftWord
MicrosoftWord Layout and Graphics Features
Making and using compressed Files
WinZip, 7Zip
Notepad++
Wordpad
Adobe acrobat
Sumatra PDF
MathType
Database
Flat & Relational
Database
DBMS
Tables & Fields
Creating Tables in
Access
Design view and Data
Sheet View
Primary Key &
Foreign key
Relationships & ER
Diagram
Queries &Simple SQL
Cyber Security
Security Problems
Interception
Spoofing
Falsification
Repudiation
Security Technologies
Encryption
MAC
Data Model
Algorithm
Ingredients
Variables
Constructs
Pseudocode
Flowchart
Symbols
Flowcharting
examples
Q&A
9/27/2018 3
Dr.AtifShahzad
TODAY
FlowChartTools
Execution of
FlowCharts
Example Problems
Sorting
• Selection
• Insertion
• Bubble
Searching
• Sequential
• Binary
Recursion
9/27/2018 4
Dr.AtifShahzad
Fundamentals of
Computer Systems
IE321
9/27/2018 5
Dr.AtifShahzad
Help the designer generate the diagrams
GUI to drag and drop symbols
Automatically generate start/stop symbols
Based on FC, may create pseudo code or
source code
Flow Charts Tools
9/27/2018 6
Dr.AtifShahzad
Structured Flow Chart
editor (SFC) is free
software to create and
modify flow charts
Flowgorithm and
Raptor are flow chart
editors and executers
Flow Charts Tools
9/27/2018 7
Dr.AtifShahzad
Welcome window displayed
Click OK button
9/27/2018 8
Dr.AtifShahzad
Click File, New and enter a title for diagram (Exa
mple), your name, click OK
9/27/2018 9
Dr.AtifShahzad
Lots of options
This is where the flow
chart is defined and d
isplayed
This is where the
pseudocode is dis
played
9/27/2018 10
Dr.AtifShahzad
To insert into diagram, click on location (a circle b
etween symbols) to insert then, Edit, Insert
9/27/2018 11
Dr.AtifShahzad
]
]
9/27/2018 12
Dr.AtifShahzad
Here’s a link to a video (6 mins) on using SFC
http://web.fscj.edu/Janson/COP1000/FirstProgram.mov
Often further options
You must be consistent!
9/27/2018 13
Dr.AtifShahzad
Flowgorithm Flowcharts
 Doesn't have modules, has functions
 Creating the main method is standard
Create new flow chart (File, New)
Flowgorithm puts “”Main” text in Start oval and
"End" text in the Finish oval
 Add I/O symbols and text to display
then double click on arrow between I/O
symbols…
13
9/27/2018 14
Dr.AtifShahzad14
 … then click Call symbol
9/27/2018 15
Dr.AtifShahzad
Module Call
15
Display “Howdy”
main()
showCustAddress()
Display “See ya”
End
Display “Joe Custo
mer”
showCustAddress()
Display “Enid OK,
56565”
Return
Display “1 Main Str
eet
9/27/2018 16
Dr.AtifShahzad
Flowgorithm
The variable/value to return
The return value type
Function name
9/27/2018 17
Dr.AtifShahzad
Flowgorithm
Then add function s
tatements
9/27/2018 18
Dr.AtifShahzad
Flowgorithm
Finished function
9/27/2018 19
Dr.AtifShahzad
Flowgorithm
When run
9/27/2018 20
Dr.AtifShahzad20
Flowgorithm Method Call
 In flowchart, double click Call symbol and
enter name of method followed by ()
9/27/2018 21
Dr.AtifShahzad21
Flowgorithm Function Definition
 Click Add Function button
 Specify Func
tion name
9/27/2018 22
Dr.AtifShahzad22
Flowgorithm Method Definition
 showCustAddress FC
created and displayed
 Simply add symbols to
showCustAddress
 To display Functions cl
ick drop down arrow a
nd select
9/27/2018 23
Dr.AtifShahzad23
Flowgorithm Method Definition
 Run
9/27/2018 24
Dr.AtifShahzad
Practice Problem
Create the flowchart on the left
using SFC and call it Name
Display
“What’s your name?”
Input name
msg = “Hi ”, name
Display msg
9/27/2018 25
Dr.AtifShahzad
Sample 1: Write a program that calculates the
sum of two input numbers and display the result.
Sample 2: Write a program to calculate the area
of a circle and display the result. Use the
formula:A=πr 2 where Pi is approximately equal
to 3.1416.
Sample 3: Write a program that computes the
average of three input quizzes, and then display
the result.
Flow Charts (FC)
9/27/2018 26
Dr.AtifShahzad
Sample 4: Write a program that converts the
input Fahrenheit degree into its Celsius degree
equivalent. Use the formula: C= (5/9)*F-32.
Sample 5: Create a program to compute the
volume of a sphere. Use the formula:V= (4/3)*
πr 3 where is pi equal to 3.1416 approximately.
The r 3 is the radius. Display result.
Sample 6: Write a program that converts the
input Celsius degree into its
equivalent Fahrenheit degree. Use the formula:
F= (9/5) * C+32.
Flow Charts (FC)
9/27/2018 27
Dr.AtifShahzad
Example 1
Write an algorithm in pseudocode that
finds the average of two numbers
9/27/2018 28
Dr.AtifShahzad
AverageOfTwo
Input: Two numbers
1. Add the two numbers
2. Divide the result by 2
3. Return the result by step 2
End
Solution
9/27/2018 29
Dr.AtifShahzad
Example 2
Write an algorithm to change a numeric
grade to a pass/no pass grade.
9/27/2018 30
Dr.AtifShahzad
Pass/NoPassGrade
Input: One number
1. if (the number is greater than or equal to 60)
then
1.1 Set the grade to “pass”
else
1.2 Set the grade to “nopass”
End if
2. Return the grade
End
Solution
9/27/2018 31
Dr.AtifShahzad
Example 3
Write an algorithm to change a numeric
grade to a letter grade.
9/27/2018 32
Dr.AtifShahzad
LetterGrade
Input: One number
1. if (the number is between 90 and 100, inclusiv
e)
then
1.1 Set the grade to “A”
End if
2. if (the number is between 80 and 89, inclusive)
then
2.1 Set the grade to “B”
End if Continues on the next slide
Solution
9/27/2018 33
Dr.AtifShahzad
3. if (the number is between 70 and 79, inclusive)
then
3.1 Set the grade to “C”
End if
4. if (the number is between 60 and 69, inclusive)
then
4.1 Set the grade to “D”
End if
Letter grade (continued)
Continues on the next slide
9/27/2018 34
Dr.AtifShahzad
5. If (the number is less than 60)
then
5.1 Set the grade to “F”
End if
6. Return the grade
End
Letter grade (continued)
9/27/2018 35
Dr.AtifShahzad
Example 4
Write an algorithm to find the largest of a
set of numbers. You do not know the total
number of numbers.
9/27/2018 36
Dr.AtifShahzad
FindLargest
Input: A list of positive integers
1. Set Largest to 0
2. while (more integers)
2.1 if (the integer is greater than Largest)
then
2.1.1 Set largest to the value of the integer
End if
End while
3. Return Largest
End
Find largestSolution
9/27/2018 37
Dr.AtifShahzad
Example 5
Write an algorithm to find the largest of 1000
numbers.
9/27/2018 38
Dr.AtifShahzad
FindLargest
Input: 1000 positive integers
1. Set Largest to 0
2. Set Counter to 0
3. while (Counter less than 1000)
3.1 if (the integer is greater than Largest)
then
3.1.1 Set Largest to the value of the integer
End if
3.2 Increment Counter
End while
4. Return Largest
End
Find largest of 1000 numbers
Solution
9/27/2018 39
Dr.AtifShahzadFigure 8-9
Concept of a subalgorithm
9/27/2018 40
Dr.AtifShahzad
FindLargest
Input: A list of positive integers
1. Set Largest to 0
2. while (more integers)
2.1 FindLarger
End while
3. Return Largest
End
Algorithm 8.6: Find largest
9/27/2018 41
Dr.AtifShahzad
FindLarger
Input: Largest and current integer
1. if (the integer is greater than Largest)
then
1.1 Set Largest to the value of the integer
End if
End
Subalgorithm: Find larger
9/27/2018 42
Dr.AtifShahzadFigure 8-10
Summation
BASIC
ALGORITHMS
9/27/2018 43
Dr.AtifShahzadFigure 8-11
Product
BASIC
ALGORITHMS
9/27/2018 44
Dr.AtifShahzadFigure 8-12
Selection sort
BASIC
ALGORITHMS
9/27/2018 45
Dr.AtifShahzadFigure 8-13: part I
Example of selection sort
BASIC
ALGORITHMS
9/27/2018 46
Dr.AtifShahzadFigure 8-13: part II
Example of selection sort
BASIC
ALGORITHMS
9/27/2018 47
Dr.AtifShahzadFigure 8-13: part II
Example of selection sort
BASIC
ALGORITHMS
9/27/2018 48
Dr.AtifShahzadFigure 8-14
Selection sort
algorithmBASIC
ALGORITHMS
9/27/2018 49
Dr.AtifShahzadFigure 8-15
Bubble sort
BASIC
ALGORITHMS
9/27/2018 50
Dr.AtifShahzadFigure 8-16: part I
Example of bubble sort
BASIC
ALGORITHMS
9/27/2018 51
Dr.AtifShahzadFigure 8-16: part II
Example of bubble sort
BASIC
ALGORITHMS
9/27/2018 52
Dr.AtifShahzadFigure 8-16: part II
Example of bubble sort
BASIC
ALGORITHMS
9/27/2018 53
Dr.AtifShahzadFigure 8-17
Insertion sort
BASIC
ALGORITHMS
9/27/2018 54
Dr.AtifShahzadFigure 8-18: part I
Example of insertion sort
BASIC
ALGORITHMS
9/27/2018 55
Dr.AtifShahzadFigure 8-18: part II
Example of insertion sort
BASIC
ALGORITHMS
9/27/2018 56
Dr.AtifShahzadFigure 8-18: part II
Example of insertion sort
BASIC
ALGORITHMS
9/27/2018 57
Dr.AtifShahzadFigure 8-19
Search concept
BASIC
ALGORITHMS
9/27/2018 58
Dr.AtifShahzadFigure 8-20: Part I
Example of a sequential search
BASIC
ALGORITHMS
9/27/2018 59
Dr.AtifShahzadFigure 8-20: Part II
Example of a sequential search
BASIC
ALGORITHMS
9/27/2018 60
Dr.AtifShahzadFigure 8-20: Part II
Example of a sequential search
BASIC
ALGORITHMS
9/27/2018 61
Dr.AtifShahzadFigure 8-21 Example of a binary sort
BASIC
ALGORITHMS
9/27/2018 62
Dr.AtifShahzadFigure 8-21 Example of a binary sort
BASIC
ALGORITHMS
9/27/2018 63
Dr.AtifShahzad
Develop a
flowchart for
generalTower of
Hanoi algorithm
using Flowgorithm
SUBMISSION
DEADLINE:
31-July-2018(BEFORE
LECTURE)
HomeWork–Tower of Hanoi
9/27/2018 64
Dr.AtifShahzad
RECURSION
9/27/2018 65
Dr.AtifShahzadFigure 8-22
Iterative definition of factorial
9/27/2018 66
Dr.AtifShahzadFigure 8-23
Recursive definition of factorial
9/27/2018 67
Dr.AtifShahzadFigure 8-24
Tracing recursive solution to factorial problem
9/27/2018 68
Dr.AtifShahzad
Factorial
Input: A positive integer num
1. Set FactN to 1
2. Set i to 1
3. while (i is less than or equal to num)
3.1 Set FactN to FactN x I
3.2 Increment i
End while
4. Return FactN
End
Iterative factorial
9/27/2018 69
Dr.AtifShahzad
Factorial
Input: A positive integer num
1. if (num is equal to 0)
then
1.1 return 1
else
1.2 return num x Factorial (num – 1)
End if
End
Recursive factorial
9/27/2018 70
Dr.AtifShahzad
Graphical User Interfaces (GUI)
• Which you are all familiar with
• Use mouse to tell program what to do
• Click buttons, choose list options, enter data
into text boxes
Command Line Interface (CLI)
• Enter English-like commands and data to tell
the computer to do stuff
User Interface
9/27/2018 71
Dr.AtifShahzad
Run the application program (java OilCalc)
Enter info at command prompt (250), press the Enter key
Program displays the result
Windows Command Prompt
9/27/2018 72
Dr.AtifShahzad
GUI Input
Run the program
Enter info, click Calc button
Program displays the result
GUI
9/27/2018 73
Dr.AtifShahzad
9/27/2018 74
Dr.AtifShahzad
NEVER hesitate to
contact should you
have any question
Dr.Atif Shahzad

Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2