SlideShare a Scribd company logo
1 of 34
Download to read offline
DFC1023
PROBLEM SOLVING & PROGRAM DESIGN
C H A P T E R 3 :
FUNDAMENTALS OF PROGRAMMING
LANGUAGE
S U B T O P I C 3 . 3 :
PROGRAM CONTROL STRUCTURES
AT THE END OF THIS CHAPTER, STUDENTS SHOULD BE ABLE
TO:
Apply program control structure
1.Control structure in problem solving :
 Sequence
 Selection
 Repetition
1.Illustrate flow of control structure using pseudo
code and flow chart.
2.Write pseudo code and flow chart using control
structure.
3. Design the algorithm for a given case study.
PROGRAM CONTROL STRUCTURE
In 1966, two researchers, C. Bohn and G.Jacopini,
demonstrated that any algorithm can be described using
only 3 control structures:
1. Sequence control structure
2. Selection/decision control structure
1. If……endif
2. If……else
3. Nested if
3. Looping control structure
1. For
2. While
3. Do……while
SEQUENCE CONTROL STRUCTURE
• In this control, every step will be executed one by
one from top to bottom.
• Every box in control structure is a process. Every
process is done sequentially.
• The beginning and end of a block of statements
can be optionally marked with the keywords
begin/start and end.
SEQUENCE CONTROL STRUCTURE
Format:
Pseudocode:
Start
Statement A;
Statement B;
End
Flowchart:
Start
Statement A
Statement B
End
SEQUENCE CONTROL STRUCTURE
PROBLEM:
Compute the total overtime wages of an employee.
 Problem Analysis:
 Input:
Hours, Basic_salary, OT_rate
 Process:
1) calculate overtime using formula:
Overtime = OT_rate * Hours
2) calculate salary using formula:
Salary = Basic_salary + Overtime
 Output:
Salary
SEQUENCE CONTROL STRUCTURE
 Algorithm:
1. Enter Hours, Basic_salary, OT_rate
2. Calculate overtime using formula:
Overtime = OT rate * Hours
3. Calculate salary using formula:
Salary = Basic_salary + Overtime
4. Display Salary
 Pseudocode:
Start
Input Hours, Basic_salary, OT_rate;
Overtime = OT_rate * Hours;
Salary = Basic_salary + Overtime;
Display Salary;
End
SEQUENCE CONTROL STRUCTURE
 Flowchart START
Input Hours,
Basic_salary, OT_rate
Overtime = OT_rate * Hours
Output Salary
END
Salary = Basic_salary + Overtime
SELECTION / DECISION CONTROL
STRUCTURE
 Usually used in structured programming.
 Control structure will execute an instruction based on result
of a condition or comparison, the result either TRUE or
FALSE.
 If the condition result is true, the control program will
execute the instruction within the TRUE loop operation.
 Otherwise, it will execute the next instruction or the
instruction within the FALSE loop operation.
SELECTION / DECISION CONTROL
STRUCTURE
Type of selection / decision control
structure:
1. If……endif
2. If……else
3. Nested if
SELECTION / DECISION CONTROL
STRUCTURE
1. If……endif
Rules:
If (condition)
Instruction (do this instruction if
condition is true)
Endif
If condition is not true, no instruction will
be executed
SELECTION / DECISION CONTROL
STRUCTURE
Pseudocode:
If (condition)
True statement
Endif
START
Condition Statement
END
False
True
• Flowchart
SELECTION / DECISION CONTROL
STRUCTURE
Problem
If student’s grade is greater than or equal to
60
Print “Passed”
Pseudocode:
if ( grade >= 60 )
print “ Passed”
endif
SELECTION / DECISION CONTROL
STRUCTURE
Flowchart
SELECTION / DECISION CONTROL
STRUCTURE
2) IF…….Else
• Rules:
If (condition)
True statement
Else
False statement
Endif
SELECTION / DECISION CONTROL
STRUCTURE
 Pseudocode:
If (condition)
True statement
Else
False statement
Endif
 Flowchart
START
Condition
END
False True
Statement 2 Statement 1
SELECTION / DECISION CONTROL
STRUCTURE
Problem
If student’s grade is greater than or equal to 60
Print “Passed” else Print “Failed”
 Pseudocode:
if ( grade >= 60 )
print “ Passed”
else
print “ Failed”
endif
SELECTION / DECISION CONTROL
STRUCTURE
 Flowchart
SELECTION / DECISION CONTROL
STRUCTURE
3. NESTED IF
 There are 3 types:
Type 1:
If (condition1)
If (condition2)
If (condition3)
True statement
Endif
Endif
Endif
SELECTION / DECISION CONTROL
STRUCTURE
• Type 2:
If (condition1)
If (condition2)
If (condition3)
Statement that will be executed if condition1,
condition2 and condition3 are true
Else
Statement that will be executed if condition1,
and condition2 are true but condition3 is false
Endif
Else
Statement that will be executed if condition1 is
true but condition2 and condition3 is false
Endif
Else
Statement that will be executed if condition1 is
false
Endif
SELECTION / DECISION CONTROL
STRUCTURE
• Type 3:
If (condition1)
Statement that will be executed if condition 1 is true
Else
If (condition 2)
Statement that will be executed if condition2 is true but condition1 is
false
Else
If (condition3)
Statement that will be executed if condition3 is true but
condition1 and condition2 are false
Else
Statement that will be executed if condition1, condition2 and
condition3 are false
Endif
Endif
SELECTION / DECISION CONTROL
STRUCTURE
Problem
 Pseudo code
If (grade >=90)
Print “A”
Else If (grade >=80)
Print “B”
Else If (grade >=70)
Print “C”
Else If (grade >=60)
Print “D”
Else
Print “F”
REPETITION CONTROL STRUCTURE
Problem : Develop a program to print “FP101 is easy” for 5
times without looping.
Solution:
Understand the problem: repeat print “DFC1023 is easy” 5
times.
1. Problem Analysis:
 Input : None
 Proses : None
 Output : print “DFC1023 is easy” for 5 times
REPETITION CONTROL STRUCTURE
2. Algorithm:
1. print “DFC1023 is easy” for 5
times.
3. Pseudocode:
START
print “DFC1023 is easy” for 5
times;
END
4. Flow Chart
Print “DFC1023 is easy”
Print “DFC1023 is easy”
Print “DFC1023 is easy”
Print “DFC1023 is easy”
Print “DFC1023 is easy”
START
END
3 BASIC TYPES OF REPETITION
CONTROL:
•From one number to
another number and
increases/decrease
by a specified value
each time
for loop
•The while loop can
be used if we don’t
know how many
times a loop must
run.
while loop
•DO..WHILE loops are
useful for things that
want to repeat at
least once.
do …
while loop
do
{
do repeat statement
} while ( condition );
while ( condition )
{
Process repeat
while the condition
is true
}
for ( variable initialization;
end condition; variable
update )
{
Repeat statement
process
}
FLOW CHART
while
is
i < 10?
print i
i = i+1
is
i < 10?
print i
i = i+1
do-while
i++
i < 10?Print i
i = 0
End
No
Yes
For
Yes
Yes
No
No
3 basic types of Repetition Control:
Start
End
Start
End
Start
i = 0 i = 0
CASE STUDY
 Problem : Develop a program can print
“DFC1023 is easy” for 5 times using
looping.
 Solution:
 Understand the problem:
 repeat print “DFC1023 is easy” 5 times .
1.SOLUTION USING FOR CONTROL LOOP
1. Problem Analysis:
Input:
None
Process:
print “FP 101 is easy”
repeat until the condition
(5 times) to exit the loop is
met
Output:
print “FP101 is easy”
2. Algorithm:
1. Set n = 0
2. Check condition (n < 5)
If true,
print “FP101 is easy”.
Go to step 3.
If false, process will end.
3. Increase counter using
formula :
n = n + 1
Go to step 2.
1. SOLUTION USING FOR CONTROL LOOP
3. Pseudo code:
Start
For (n=0; n<5; n++)
{
print “DFC1023 is easy”;
}
End
4. Flow Chart
n++
n< 5?Print “DFC1023 is
easy”
n = 0
End
Start
No
Yes
2.SOLUTION USING WHILE CONTROL LOOP
1. Problem Analysis:
Input:
None
Process:
print “DFC1023 is easy”
repeat until the condition
(5 times) to exit the loop is
met
Output:
print “FP101 is easy”
2. Algorithm:
1. Set n=0
2. Check condition (n < 5)
If true,
print “DFC1023 is easy”.
Go to step 3.
If false, process will end.
3. Increase counter using
formula :
n = n+1
Go to step 2.
2. SOLUTION USING WHILE CONTROL LOOP
3. Pseudo code:
Start
Set n = 0;
While (n < 5)
{
print “DFC1023 is easy”;
n++;
}
End while
End
4. Flow Chart
is
n < 5?
print “DFC1023 is easy”
n = n+1
Yes
No
End
Start
n = 0
3. SOLUTION USING DO…WHILE CONTROL
LOOP
1. Problem Analysis:
Input:
None
Process:
print “DFC1023 is easy”
repeat until the condition
(5 times) to exit the loop is
met
Output:
print “FP101 is easy”
2. Algorithm:
1. Set n = 0
2. Print “DFC1023 is easy”.
3. Increase counter using
formula :
n = n+1
4.Check condition (n < 5)
If true, Go to step 2.
If false, process will end.
3. SOLUTION USING DO…WHILE CONTROL
LOOP
3. Pseudo code:
Start
Set n = 0;
Do
{
print “DFC1023 is easy”;
n++;
} While (n < 5)
End
4. Flow Chart
End
Start
is
n < 5?
print “DFC1023 is
easy”
Yes
No
n = n+1
n = 0
POLITEKNIK MALAYSIA

More Related Content

What's hot

Mobile Devices and Apps in Education
Mobile Devices and Apps in EducationMobile Devices and Apps in Education
Mobile Devices and Apps in Education
Rebecca Kate Miller
 
Technology in the classroom ppt
Technology in the classroom pptTechnology in the classroom ppt
Technology in the classroom ppt
Mayraleealdrete
 
Why Integrate Technology In Teaching
Why Integrate Technology In TeachingWhy Integrate Technology In Teaching
Why Integrate Technology In Teaching
mustgo20
 
PowerPoint_WHERETO
PowerPoint_WHERETOPowerPoint_WHERETO
PowerPoint_WHERETO
Adria Hohman
 
Teaching using ict tools
Teaching using ict toolsTeaching using ict tools
Teaching using ict tools
yesvita17
 
Negative Effects of Technology pdf
Negative Effects of Technology pdfNegative Effects of Technology pdf
Negative Effects of Technology pdf
Heather
 

What's hot (20)

Technology Innovations in Teaching and Learning
Technology Innovations in Teaching and LearningTechnology Innovations in Teaching and Learning
Technology Innovations in Teaching and Learning
 
Lesson 2: Technology; Boon or bane
Lesson 2: Technology; Boon or baneLesson 2: Technology; Boon or bane
Lesson 2: Technology; Boon or bane
 
Technology for the 21st century teachers
Technology for the 21st century teachersTechnology for the 21st century teachers
Technology for the 21st century teachers
 
Role of ict in education
Role of ict in educationRole of ict in education
Role of ict in education
 
Mobile Devices and Apps in Education
Mobile Devices and Apps in EducationMobile Devices and Apps in Education
Mobile Devices and Apps in Education
 
Technology in the classroom ppt
Technology in the classroom pptTechnology in the classroom ppt
Technology in the classroom ppt
 
Managing Instruction
Managing InstructionManaging Instruction
Managing Instruction
 
ICT in Ediucation
ICT in EdiucationICT in Ediucation
ICT in Ediucation
 
21st century skills and the 4 cs
21st century skills and the 4 cs21st century skills and the 4 cs
21st century skills and the 4 cs
 
Inquiry process skills lessons (1)
Inquiry process skills lessons  (1)Inquiry process skills lessons  (1)
Inquiry process skills lessons (1)
 
Why Integrate Technology In Teaching
Why Integrate Technology In TeachingWhy Integrate Technology In Teaching
Why Integrate Technology In Teaching
 
PowerPoint_WHERETO
PowerPoint_WHERETOPowerPoint_WHERETO
PowerPoint_WHERETO
 
Student Centered Assessment
Student Centered AssessmentStudent Centered Assessment
Student Centered Assessment
 
1.-INTRODUCTORY-LESSON-TO-MTB-MLE.pptx
1.-INTRODUCTORY-LESSON-TO-MTB-MLE.pptx1.-INTRODUCTORY-LESSON-TO-MTB-MLE.pptx
1.-INTRODUCTORY-LESSON-TO-MTB-MLE.pptx
 
Teaching using ict tools
Teaching using ict toolsTeaching using ict tools
Teaching using ict tools
 
The impact of ICT on education
The impact of ICT on educationThe impact of ICT on education
The impact of ICT on education
 
Integrating technology
Integrating technologyIntegrating technology
Integrating technology
 
Technology in Early Childhood Education
Technology in Early Childhood EducationTechnology in Early Childhood Education
Technology in Early Childhood Education
 
Blended Learning PowerPoint
Blended Learning PowerPointBlended Learning PowerPoint
Blended Learning PowerPoint
 
Negative Effects of Technology pdf
Negative Effects of Technology pdfNegative Effects of Technology pdf
Negative Effects of Technology pdf
 

Similar to POLITEKNIK MALAYSIA

Lecture 6.1 flow control selection
Lecture 6.1  flow control selectionLecture 6.1  flow control selection
Lecture 6.1 flow control selection
alvin567
 
Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01
VincentAcapen1
 
Pengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstrukturPengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstruktur
Unit Kediaman Luar Kampus
 

Similar to POLITEKNIK MALAYSIA (20)

Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Lecture 6.1 flow control selection
Lecture 6.1  flow control selectionLecture 6.1  flow control selection
Lecture 6.1 flow control selection
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfVB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
 
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfVB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
 
Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01
 
Flow of control c++
Flow of control c++Flow of control c++
Flow of control c++
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)
 
Pengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstrukturPengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstruktur
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptx
 
Penyelesaian masalah
Penyelesaian masalahPenyelesaian masalah
Penyelesaian masalah
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilization
 

More from Aiman Hud

More from Aiman Hud (20)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

POLITEKNIK MALAYSIA

  • 1. DFC1023 PROBLEM SOLVING & PROGRAM DESIGN C H A P T E R 3 : FUNDAMENTALS OF PROGRAMMING LANGUAGE S U B T O P I C 3 . 3 : PROGRAM CONTROL STRUCTURES
  • 2. AT THE END OF THIS CHAPTER, STUDENTS SHOULD BE ABLE TO: Apply program control structure 1.Control structure in problem solving :  Sequence  Selection  Repetition 1.Illustrate flow of control structure using pseudo code and flow chart. 2.Write pseudo code and flow chart using control structure. 3. Design the algorithm for a given case study.
  • 3. PROGRAM CONTROL STRUCTURE In 1966, two researchers, C. Bohn and G.Jacopini, demonstrated that any algorithm can be described using only 3 control structures: 1. Sequence control structure 2. Selection/decision control structure 1. If……endif 2. If……else 3. Nested if 3. Looping control structure 1. For 2. While 3. Do……while
  • 4. SEQUENCE CONTROL STRUCTURE • In this control, every step will be executed one by one from top to bottom. • Every box in control structure is a process. Every process is done sequentially. • The beginning and end of a block of statements can be optionally marked with the keywords begin/start and end.
  • 5. SEQUENCE CONTROL STRUCTURE Format: Pseudocode: Start Statement A; Statement B; End Flowchart: Start Statement A Statement B End
  • 6. SEQUENCE CONTROL STRUCTURE PROBLEM: Compute the total overtime wages of an employee.  Problem Analysis:  Input: Hours, Basic_salary, OT_rate  Process: 1) calculate overtime using formula: Overtime = OT_rate * Hours 2) calculate salary using formula: Salary = Basic_salary + Overtime  Output: Salary
  • 7. SEQUENCE CONTROL STRUCTURE  Algorithm: 1. Enter Hours, Basic_salary, OT_rate 2. Calculate overtime using formula: Overtime = OT rate * Hours 3. Calculate salary using formula: Salary = Basic_salary + Overtime 4. Display Salary  Pseudocode: Start Input Hours, Basic_salary, OT_rate; Overtime = OT_rate * Hours; Salary = Basic_salary + Overtime; Display Salary; End
  • 8. SEQUENCE CONTROL STRUCTURE  Flowchart START Input Hours, Basic_salary, OT_rate Overtime = OT_rate * Hours Output Salary END Salary = Basic_salary + Overtime
  • 9. SELECTION / DECISION CONTROL STRUCTURE  Usually used in structured programming.  Control structure will execute an instruction based on result of a condition or comparison, the result either TRUE or FALSE.  If the condition result is true, the control program will execute the instruction within the TRUE loop operation.  Otherwise, it will execute the next instruction or the instruction within the FALSE loop operation.
  • 10. SELECTION / DECISION CONTROL STRUCTURE Type of selection / decision control structure: 1. If……endif 2. If……else 3. Nested if
  • 11. SELECTION / DECISION CONTROL STRUCTURE 1. If……endif Rules: If (condition) Instruction (do this instruction if condition is true) Endif If condition is not true, no instruction will be executed
  • 12. SELECTION / DECISION CONTROL STRUCTURE Pseudocode: If (condition) True statement Endif START Condition Statement END False True • Flowchart
  • 13. SELECTION / DECISION CONTROL STRUCTURE Problem If student’s grade is greater than or equal to 60 Print “Passed” Pseudocode: if ( grade >= 60 ) print “ Passed” endif
  • 14. SELECTION / DECISION CONTROL STRUCTURE Flowchart
  • 15. SELECTION / DECISION CONTROL STRUCTURE 2) IF…….Else • Rules: If (condition) True statement Else False statement Endif
  • 16. SELECTION / DECISION CONTROL STRUCTURE  Pseudocode: If (condition) True statement Else False statement Endif  Flowchart START Condition END False True Statement 2 Statement 1
  • 17. SELECTION / DECISION CONTROL STRUCTURE Problem If student’s grade is greater than or equal to 60 Print “Passed” else Print “Failed”  Pseudocode: if ( grade >= 60 ) print “ Passed” else print “ Failed” endif
  • 18. SELECTION / DECISION CONTROL STRUCTURE  Flowchart
  • 19. SELECTION / DECISION CONTROL STRUCTURE 3. NESTED IF  There are 3 types: Type 1: If (condition1) If (condition2) If (condition3) True statement Endif Endif Endif
  • 20. SELECTION / DECISION CONTROL STRUCTURE • Type 2: If (condition1) If (condition2) If (condition3) Statement that will be executed if condition1, condition2 and condition3 are true Else Statement that will be executed if condition1, and condition2 are true but condition3 is false Endif Else Statement that will be executed if condition1 is true but condition2 and condition3 is false Endif Else Statement that will be executed if condition1 is false Endif
  • 21. SELECTION / DECISION CONTROL STRUCTURE • Type 3: If (condition1) Statement that will be executed if condition 1 is true Else If (condition 2) Statement that will be executed if condition2 is true but condition1 is false Else If (condition3) Statement that will be executed if condition3 is true but condition1 and condition2 are false Else Statement that will be executed if condition1, condition2 and condition3 are false Endif Endif
  • 22. SELECTION / DECISION CONTROL STRUCTURE Problem  Pseudo code If (grade >=90) Print “A” Else If (grade >=80) Print “B” Else If (grade >=70) Print “C” Else If (grade >=60) Print “D” Else Print “F”
  • 23. REPETITION CONTROL STRUCTURE Problem : Develop a program to print “FP101 is easy” for 5 times without looping. Solution: Understand the problem: repeat print “DFC1023 is easy” 5 times. 1. Problem Analysis:  Input : None  Proses : None  Output : print “DFC1023 is easy” for 5 times
  • 24. REPETITION CONTROL STRUCTURE 2. Algorithm: 1. print “DFC1023 is easy” for 5 times. 3. Pseudocode: START print “DFC1023 is easy” for 5 times; END 4. Flow Chart Print “DFC1023 is easy” Print “DFC1023 is easy” Print “DFC1023 is easy” Print “DFC1023 is easy” Print “DFC1023 is easy” START END
  • 25. 3 BASIC TYPES OF REPETITION CONTROL: •From one number to another number and increases/decrease by a specified value each time for loop •The while loop can be used if we don’t know how many times a loop must run. while loop •DO..WHILE loops are useful for things that want to repeat at least once. do … while loop do { do repeat statement } while ( condition ); while ( condition ) { Process repeat while the condition is true } for ( variable initialization; end condition; variable update ) { Repeat statement process }
  • 26. FLOW CHART while is i < 10? print i i = i+1 is i < 10? print i i = i+1 do-while i++ i < 10?Print i i = 0 End No Yes For Yes Yes No No 3 basic types of Repetition Control: Start End Start End Start i = 0 i = 0
  • 27. CASE STUDY  Problem : Develop a program can print “DFC1023 is easy” for 5 times using looping.  Solution:  Understand the problem:  repeat print “DFC1023 is easy” 5 times .
  • 28. 1.SOLUTION USING FOR CONTROL LOOP 1. Problem Analysis: Input: None Process: print “FP 101 is easy” repeat until the condition (5 times) to exit the loop is met Output: print “FP101 is easy” 2. Algorithm: 1. Set n = 0 2. Check condition (n < 5) If true, print “FP101 is easy”. Go to step 3. If false, process will end. 3. Increase counter using formula : n = n + 1 Go to step 2.
  • 29. 1. SOLUTION USING FOR CONTROL LOOP 3. Pseudo code: Start For (n=0; n<5; n++) { print “DFC1023 is easy”; } End 4. Flow Chart n++ n< 5?Print “DFC1023 is easy” n = 0 End Start No Yes
  • 30. 2.SOLUTION USING WHILE CONTROL LOOP 1. Problem Analysis: Input: None Process: print “DFC1023 is easy” repeat until the condition (5 times) to exit the loop is met Output: print “FP101 is easy” 2. Algorithm: 1. Set n=0 2. Check condition (n < 5) If true, print “DFC1023 is easy”. Go to step 3. If false, process will end. 3. Increase counter using formula : n = n+1 Go to step 2.
  • 31. 2. SOLUTION USING WHILE CONTROL LOOP 3. Pseudo code: Start Set n = 0; While (n < 5) { print “DFC1023 is easy”; n++; } End while End 4. Flow Chart is n < 5? print “DFC1023 is easy” n = n+1 Yes No End Start n = 0
  • 32. 3. SOLUTION USING DO…WHILE CONTROL LOOP 1. Problem Analysis: Input: None Process: print “DFC1023 is easy” repeat until the condition (5 times) to exit the loop is met Output: print “FP101 is easy” 2. Algorithm: 1. Set n = 0 2. Print “DFC1023 is easy”. 3. Increase counter using formula : n = n+1 4.Check condition (n < 5) If true, Go to step 2. If false, process will end.
  • 33. 3. SOLUTION USING DO…WHILE CONTROL LOOP 3. Pseudo code: Start Set n = 0; Do { print “DFC1023 is easy”; n++; } While (n < 5) End 4. Flow Chart End Start is n < 5? print “DFC1023 is easy” Yes No n = n+1 n = 0