SlideShare a Scribd company logo
1 of 36
Download to read offline
Computing in Engineering
Computers and Systems Engineering Dept
• Using Subprocesses to simplify program design
• Nested Loops
• Arrays
• Exam-like questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
• Using Subprocesses to simplify program design
• Nested Loops
• Arrays
• Exam-like questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Using Subprocesses in Flowcharts
• Flowcharts of a complex process can
be broken down into smaller sub-
processes for clarity and re-usability.
• In this case a flowchart can point to a
different sub-process within its flow.
• The predefined process symbol to the
right is used to show such
subprocesses.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
The subprocess is useful because:
• it permits the modularization of complex programs.
• it provides a means of simplifying programs by making common
processes available to a wide number of programs.
• it makes for more reliable programs since once it is shown that a
process works then it can be made a subprocess and need not be tested
again.
• In flow charts subprocesses are also useful in dealing with the
flowcharting rule that a flow chart should have no more than 15 or so
symbols on a page.
Using Subprocesses in Flowcharts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
How to decide which sub-programs are needed?
• Break the program into subtasks
• Examine each subtask and break it down if
needed into further subtasks
• Continue until the subtask cannot be broken
down into small subtasks
• Example: Baking a cake
Using Subprocesses in Flowcharts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
What are things/tasks you have to do to make a
cake?
• Ingredient preparation
• Process the ingredients
• Assemble the cake
Using Subprocesses in Flowcharts
Example 1 : Baking a cake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Using Subprocesses in Flowcharts
Example 1: Baking a cake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Using Subprocesses in Flowcharts
Example 2: Read temperature in Fahrenheit and print its
value in both Fahrenheit and Celcius
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Using Subprocesses in Flowcharts
Example 3: Maximum of 3 Integers Revisited
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
• Using Subprocesses to simplify program design
• Nested Loops
• Arrays
• Exam-like questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
•Nested loops are loops placed inside one another
creating a loop of loops.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Mock Example Revisited
Nested Loops
Pseudocode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Nested Loops
Flowchart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Problem: Design using flowchart
and pseudocode a program that
prints a figure similar to the one
on the right for a given number of rows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Problem: Design using flowchart
and pseudocode a program that
prints a figure similar to the one
on the right for a given number of rows.
Analysis:
Inputs : None.
Variables: N, Row_No, where:
1. N = No of Rows = 9
2. Row_No changes from 1:N
Steps:
For each row
1. Calculate number of stars
2. Print ‘*’ ( N - Row_No +1 ) times on the same row
3. New Line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Start
For Row_No =1 To N
No_of_stars=N-Row_No+1
For Col =1 To No_of_stars
Print ‘*’;
End For
New line
End For
Stop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Hint:
Adding an “;” at the end of the Print statement
prevents skipping to the next line after printing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
• Typically used for
working with two dimensions (or more)
such as in the above example
•When a loop is nested inside another loop,
the inner loop runs many times
inside the outer loop.
•In each iteration of the outer loop,
the inner loop will be re-started.
•The inner loop must finish all of its iterations
•before the outer loop can continue to its next iteration.
•The inner loop must have a different name for its
loop counter variable so that it will not conflict with the outer loop.
For Row_No =1,N
No_of_stars=N - Row_No +1
For Col =1, No_of_stars
Print ‘*’
End For
New line
End For
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Design a program that types the binary numbers corresponding to the integers 0 – 7
Analysis:
Inputs: None
Define 3 variables A, B, C as the binary digits needed to represent the numbers from 0 -7
Initial values: A=0, B=0, C=0
Output: 0 000
1 001
2 010
.
.
7 111
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
• Using Subprocesses to simplify program design
• Nested Loops
• Arrays
• Exam-like questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
An array is a
collection of items of
same data type stored
at consecutive
memory locations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Basic array functions:
• Assigning values to
array elements
• Reading values
from array
elements
• Simple search
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Start
Read the number of elements n
Initialize i=0
Repeat
Read element no i
increment i
Until i = n
Initialize i=0
Repeat
write element no i
increment i
Until i = n
End
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Assumption:
The array “a” is already filled
with N numbers, and N >=0
Print
largest
End
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Given an array arr[] of N elements, the task is
to write a function to search a given
element x in arr[].
Example
Input: arr[] = {10, 20, 80, 30, 60, 50,110, 100,
130, 170}, x = 110;
Output: 6
Explanation: Element x is present at index 6
Input: arr[] = {10, 20, 80, 30, 60, 50,110, 100,
130, 170}, x = 175;
Output: -1
Explanation: Element x is not present in arr[].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Input x, array
found = False
Length = array size
counter =0
WHILE found = False AND counter < length
IF array[counter] = x
THEN
Print counter
found = True
ELSE
counter = counter + 1
END IF
END WHILE
IF found = False
THEN
print 'Item not found’
END IF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Input x, array
Length = array size
counter =0
WHILE counter < length
IF array[counter] = x
THEN
Print counter
counter = length
END IF
counter = counter + 1
END WHILE
IF counter = length
THEN
print 'Item not found’
END IF
• Using Subprocesses to simplify program design
• Nested Loops
• Arrays
• Exam-like questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Exam-like Question III
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Exam-Like Problem IV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Thank You

More Related Content

Similar to CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf

Solution of matlab chapter 6
Solution of matlab chapter 6Solution of matlab chapter 6
Solution of matlab chapter 6AhsanIrshad8
 
just reference
just referencejust reference
just referenceSumin Kim
 
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)EA Clavel
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
Basic college mathematics 3rd edition by julie mille neill hyde solutions manual
Basic college mathematics 3rd edition by julie mille neill hyde solutions manualBasic college mathematics 3rd edition by julie mille neill hyde solutions manual
Basic college mathematics 3rd edition by julie mille neill hyde solutions manualtokahenrbar
 
Turning point multiply by two digits
Turning point multiply by two digitsTurning point multiply by two digits
Turning point multiply by two digitsTheresa Miller
 
UNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxUNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxRSathyaPriyaCSEKIOT
 
Counting and Sequences
Counting and SequencesCounting and Sequences
Counting and SequencesDan Stewart
 
01 - 01 January - Sorting
01 - 01 January - Sorting01 - 01 January - Sorting
01 - 01 January - SortingNeeldhara Misra
 
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...MujtabaAliKhan12
 
Sudoku
SudokuSudoku
Sudokub p
 

Similar to CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf (20)

Solution of matlab chapter 6
Solution of matlab chapter 6Solution of matlab chapter 6
Solution of matlab chapter 6
 
basics
basicsbasics
basics
 
Basic math
Basic mathBasic math
Basic math
 
upload
uploadupload
upload
 
just reference
just referencejust reference
just reference
 
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)
M1S1U2 (ADDITION STRATEGIES + DOUBLING CONCEPT)
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MNIST 10-class Classifiers
MNIST 10-class ClassifiersMNIST 10-class Classifiers
MNIST 10-class Classifiers
 
Basic college mathematics 3rd edition by julie mille neill hyde solutions manual
Basic college mathematics 3rd edition by julie mille neill hyde solutions manualBasic college mathematics 3rd edition by julie mille neill hyde solutions manual
Basic college mathematics 3rd edition by julie mille neill hyde solutions manual
 
Turning point multiply by two digits
Turning point multiply by two digitsTurning point multiply by two digits
Turning point multiply by two digits
 
UNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptxUNIT I_PSPP - Illustrative Problems (1).pptx
UNIT I_PSPP - Illustrative Problems (1).pptx
 
Counting and Sequences
Counting and SequencesCounting and Sequences
Counting and Sequences
 
Intro to maths for software eng
Intro to maths for software engIntro to maths for software eng
Intro to maths for software eng
 
R part I
R part IR part I
R part I
 
PEA 305.pdf
PEA 305.pdfPEA 305.pdf
PEA 305.pdf
 
Maths
MathsMaths
Maths
 
01 - 01 January - Sorting
01 - 01 January - Sorting01 - 01 January - Sorting
01 - 01 January - Sorting
 
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...
SCA_Module Supply Chain Data Analytics Supply Chain Data Analytics Supply Cha...
 
Sudoku
SudokuSudoku
Sudoku
 
DEL-244Chep i
DEL-244Chep iDEL-244Chep i
DEL-244Chep i
 

More from NourhanTarek23

CSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfCSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfNourhanTarek23
 
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxCSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxNourhanTarek23
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptNourhanTarek23
 
Lect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptLect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptNourhanTarek23
 
Software engineering.pptx
Software engineering.pptxSoftware engineering.pptx
Software engineering.pptxNourhanTarek23
 
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives  IOT and Big Data Era.pptxLect01 Computers Impact on Our lives  IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptxNourhanTarek23
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxNourhanTarek23
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptxNourhanTarek23
 
Introduction to Spring sec2.pptx
Introduction to Spring sec2.pptxIntroduction to Spring sec2.pptx
Introduction to Spring sec2.pptxNourhanTarek23
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptxNourhanTarek23
 
Problem set 3-solution.pptx
Problem set 3-solution.pptxProblem set 3-solution.pptx
Problem set 3-solution.pptxNourhanTarek23
 

More from NourhanTarek23 (15)

CSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdfCSE031.Lecture_05.Networks.pdf
CSE031.Lecture_05.Networks.pdf
 
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptxCSE031.Lecture_11-Operating_Systems.Part_I.pptx
CSE031.Lecture_11-Operating_Systems.Part_I.pptx
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Lect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.pptLect01 Introduction of Visual Basic.ppt
Lect01 Introduction of Visual Basic.ppt
 
Software engineering.pptx
Software engineering.pptxSoftware engineering.pptx
Software engineering.pptx
 
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives  IOT and Big Data Era.pptxLect01 Computers Impact on Our lives  IOT and Big Data Era.pptx
Lect01 Computers Impact on Our lives IOT and Big Data Era.pptx
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
 
section5.pptx
section5.pptxsection5.pptx
section5.pptx
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
 
AOP sec3.pptx
AOP sec3.pptxAOP sec3.pptx
AOP sec3.pptx
 
Introduction to Spring sec2.pptx
Introduction to Spring sec2.pptxIntroduction to Spring sec2.pptx
Introduction to Spring sec2.pptx
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
QoS.pptx
QoS.pptxQoS.pptx
QoS.pptx
 
’mobile ip.pptx
’mobile ip.pptx’mobile ip.pptx
’mobile ip.pptx
 
Problem set 3-solution.pptx
Problem set 3-solution.pptxProblem set 3-solution.pptx
Problem set 3-solution.pptx
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf

  • 1. Computing in Engineering Computers and Systems Engineering Dept
  • 2. • Using Subprocesses to simplify program design • Nested Loops • Arrays • Exam-like questions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 3. • Using Subprocesses to simplify program design • Nested Loops • Arrays • Exam-like questions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 4. Using Subprocesses in Flowcharts • Flowcharts of a complex process can be broken down into smaller sub- processes for clarity and re-usability. • In this case a flowchart can point to a different sub-process within its flow. • The predefined process symbol to the right is used to show such subprocesses. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 5. The subprocess is useful because: • it permits the modularization of complex programs. • it provides a means of simplifying programs by making common processes available to a wide number of programs. • it makes for more reliable programs since once it is shown that a process works then it can be made a subprocess and need not be tested again. • In flow charts subprocesses are also useful in dealing with the flowcharting rule that a flow chart should have no more than 15 or so symbols on a page. Using Subprocesses in Flowcharts 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 6. How to decide which sub-programs are needed? • Break the program into subtasks • Examine each subtask and break it down if needed into further subtasks • Continue until the subtask cannot be broken down into small subtasks • Example: Baking a cake Using Subprocesses in Flowcharts 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 7. What are things/tasks you have to do to make a cake? • Ingredient preparation • Process the ingredients • Assemble the cake Using Subprocesses in Flowcharts Example 1 : Baking a cake 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 8. Using Subprocesses in Flowcharts Example 1: Baking a cake 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 9. Using Subprocesses in Flowcharts Example 2: Read temperature in Fahrenheit and print its value in both Fahrenheit and Celcius 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 10. Using Subprocesses in Flowcharts Example 3: Maximum of 3 Integers Revisited 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 11. • Using Subprocesses to simplify program design • Nested Loops • Arrays • Exam-like questions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 12. •Nested loops are loops placed inside one another creating a loop of loops. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 13. Mock Example Revisited Nested Loops Pseudocode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 14. Nested Loops Flowchart 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 15. Problem: Design using flowchart and pseudocode a program that prints a figure similar to the one on the right for a given number of rows 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 16. Problem: Design using flowchart and pseudocode a program that prints a figure similar to the one on the right for a given number of rows. Analysis: Inputs : None. Variables: N, Row_No, where: 1. N = No of Rows = 9 2. Row_No changes from 1:N Steps: For each row 1. Calculate number of stars 2. Print ‘*’ ( N - Row_No +1 ) times on the same row 3. New Line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 17. Start For Row_No =1 To N No_of_stars=N-Row_No+1 For Col =1 To No_of_stars Print ‘*’; End For New line End For Stop 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Hint: Adding an “;” at the end of the Print statement prevents skipping to the next line after printing
  • 18. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 19. • Typically used for working with two dimensions (or more) such as in the above example •When a loop is nested inside another loop, the inner loop runs many times inside the outer loop. •In each iteration of the outer loop, the inner loop will be re-started. •The inner loop must finish all of its iterations •before the outer loop can continue to its next iteration. •The inner loop must have a different name for its loop counter variable so that it will not conflict with the outer loop. For Row_No =1,N No_of_stars=N - Row_No +1 For Col =1, No_of_stars Print ‘*’ End For New line End For 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 20. Design a program that types the binary numbers corresponding to the integers 0 – 7 Analysis: Inputs: None Define 3 variables A, B, C as the binary digits needed to represent the numbers from 0 -7 Initial values: A=0, B=0, C=0 Output: 0 000 1 001 2 010 . . 7 111 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 21. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 22. • Using Subprocesses to simplify program design • Nested Loops • Arrays • Exam-like questions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 23. An array is a collection of items of same data type stored at consecutive memory locations. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 24. Basic array functions: • Assigning values to array elements • Reading values from array elements • Simple search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 25. Start Read the number of elements n Initialize i=0 Repeat Read element no i increment i Until i = n Initialize i=0 Repeat write element no i increment i Until i = n End 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 26. Assumption: The array “a” is already filled with N numbers, and N >=0 Print largest End 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 27. Given an array arr[] of N elements, the task is to write a function to search a given element x in arr[]. Example Input: arr[] = {10, 20, 80, 30, 60, 50,110, 100, 130, 170}, x = 110; Output: 6 Explanation: Element x is present at index 6 Input: arr[] = {10, 20, 80, 30, 60, 50,110, 100, 130, 170}, x = 175; Output: -1 Explanation: Element x is not present in arr[]. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 28. Input x, array found = False Length = array size counter =0 WHILE found = False AND counter < length IF array[counter] = x THEN Print counter found = True ELSE counter = counter + 1 END IF END WHILE IF found = False THEN print 'Item not found’ END IF 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Input x, array Length = array size counter =0 WHILE counter < length IF array[counter] = x THEN Print counter counter = length END IF counter = counter + 1 END WHILE IF counter = length THEN print 'Item not found’ END IF
  • 29. • Using Subprocesses to simplify program design • Nested Loops • Arrays • Exam-like questions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 30. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 31. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 32. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 33. Exam-like Question III 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 34. Exam-Like Problem IV 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  • 35. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34