45
UNIVERSITI TUN HUSSEIN ONN MALAYSIA OBJECTIVES At the end of the chapter, student will know: To explain control structures concept To write a C++ program using control structures AIM To acknowledge student with the concept of control structures in programming: selection control structure and repetition control structure CONTROL STRUCTURE

Chapter 6 Control Structures

Embed Size (px)

DESCRIPTION

To acknowledge student with the concept of control structures in programming: selection control structure and repetition control structure

Citation preview

PowerPoint Presentation

OBJECTIVESAt the end of the chapter, student will know:To explain control structures conceptTo write a C++ program using control structuresAIMTo acknowledge student with the concept of control structures in programming: selection control structure and repetition control structureCONTROL STRUCTUREUNIVERSITI TUN HUSSEIN ONN MALAYSIA1CONTROL STRUCTURESequence Control StructureSelection Control StructureRepetition Control Structure

Selection Control Structure3Used in programming to:

offer choice of interests to user of a system.restrict/limit to only one operation/process in a system to be executed at a timeallow user to choose only one selection of process/operation at a time from a system.execute a process/operation based on selection.

34Selection Control StructureBest example/case:

In general, the ATM processes are controlled by some restrictions or rules which is written using selection control structure (using particular programming language).The concept is "one selection, one operation".

45

Selection Control Structure56Selection Control StructureHow decision is made when user make their selection from the ATM menu?The system will check the input and compares the selection with the conditions set in the system. If the input matches the setting conditions, the corresponding menu will be displayed.

67Selection Control StructureChoose only one instruction to be executed.Selection will be done if only the conditional statement is TRUE.Types of selection control structure:

Single selection (if)Doubleselection (if-else)Multi level selection (if-else-if)7Single selection (if)8Use if statement.Used in a situation which if conditional statement is TRUE, statement will be selected.

8grade ==A Print ExcellentYesNoi) Single SelectionConvert to flowchart:UNIVERSITI TUN HUSSEIN ONN MALAYSIAcont9if (conditional expression)C++ statement;ReservedwordConsist of:Output statement/ Input statement/ expressionSingle selection (if)

FORMAT10If grade is A, print a message ExcellentConvert to valid selection statement:if ( grade = = A) cout