SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
© 2016 Cengage Learning®. May not be scanned, copied or
Introduction to Programming in C++
Eighth Edition
Lesson 6.1:
More on the Selection Structure
duplicated, or posted to a publicly accessible website, in whole
or in part.
• Include anested selection structure in pseudocode andin
aflowchart
• Codeanested selection structure
• Recognizecommon logic errors in selection structures
• Include amultiple-alternative selection structure in
pseudocode and in aflowchart
• Codeamultiple-alternative selection structure in C++
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 2
Objectives
• True and false paths of aselection structure cancontain
other selection structures
• Inner selection structures are referred to asnested
selectionstructures; contained (nested) within an outer
selection structure
• Nested selection structures are used when morethan
one decision needs to be made before choosing an
instruction
• Inner (nested) selection structures are indentedwithin
their outer selectionstructures
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 3
Nested Selection Structures
Figure 6-1 Problem that requires a selection structure
Nested Selection Structures (cont’d.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 4
Nested Selection Structures (cont’d.)
Figure 6-2 Problem that requires a nested selection structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 5
Nested Selection Structures (cont’d.)
Figure 6-3 Problem that requires two nested selection structures
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 6
• Outer and inner selection structures can be thought of
asmaking primary and secondary decisions,
respectively
• Secondary decision is called such because whether it
needs to be made depends on the result of aprimary
decision
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 7
Flowcharting a Nested Selection
Structure
Flowcharting a Nested Selection
Structure (cont’d.)
Figure 6-5 Problem specification for voter eligibility problem
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 8
Figure 6-5 A correct solution to the voter eligibility problem
Flowcharting a Nested Selection
Structure (cont’d.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 9
Figure 6-6 Another correct solution to the voter eligibility problem
Flowcharting a Nested Selection
Structure (cont’d.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 10
• Codefor nested selection structures usesthe if and
else statements
• Nested selection structures can be placed in either if
or else statement blocks
• Correct tabbing makescode easier to read
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 11
Coding a Nested Selection Structure
Coding a Nested Selection Structure
(cont’d.)
Figure 6-7 Code and sample run of the voter eligibility program
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 12
• Four common logic errors made when writing selection
structures
– Usingacompound condition rather than anested
selection structure
– Reversingthe outer and nesteddecisions
– Usingan unnecessary nested selection structure
– Including an unnecessary comparison in acondition
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 13
Logic Errors in Selection Structures
Logic Errors in Selection Structures
(cont’d.)
Figure 6-8 Problem specification and a correct algorithm for the
Miller’s Car Rental
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 14
Figure 6-9 Sample data and expected results for the algorithm
shown in Figure 6-8
Figure 6-10 Result of desk-checking the correct algorithm
Logic Errors in Selection Structures
(cont’d.)
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in whole
or in part.
An Introduction to Programming with C++, Eighth Edition 15

Contenu connexe

Tendances

Chapter 5 - The Selection Structure
Chapter 5 - The Selection StructureChapter 5 - The Selection Structure
Chapter 5 - The Selection Structuremshellman
 
Chapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection StructureChapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection Structuremshellman
 
Chapter 3 - Variables and Constants
Chapter 3 - Variables and ConstantsChapter 3 - Variables and Constants
Chapter 3 - Variables and Constantsmshellman
 
Chapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving ProcessChapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving Processmshellman
 
System Concept Simulation for Concurrent Engineering
System Concept Simulation for Concurrent EngineeringSystem Concept Simulation for Concurrent Engineering
System Concept Simulation for Concurrent EngineeringFinmeccanica
 
[CapellaDay Toulouse] Designing a test mean alla capella
[CapellaDay Toulouse] Designing a test mean alla capella[CapellaDay Toulouse] Designing a test mean alla capella
[CapellaDay Toulouse] Designing a test mean alla capellaObeo
 
Portfolio control version sn_v5
Portfolio control version sn_v5Portfolio control version sn_v5
Portfolio control version sn_v5Samuel Narcisse
 
Sample instrument using lab view abhijeet agarwal-1
Sample instrument using lab view  abhijeet agarwal-1Sample instrument using lab view  abhijeet agarwal-1
Sample instrument using lab view abhijeet agarwal-1Abhijeet Agarwal
 
Capture Accurate Solution Requirements with Exploratory Modeling at SAP
Capture Accurate Solution Requirements with Exploratory Modeling at SAPCapture Accurate Solution Requirements with Exploratory Modeling at SAP
Capture Accurate Solution Requirements with Exploratory Modeling at SAPESUG
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...Publicis Sapient Engineering
 
Migrating TIMES to another modelling language - approaches, issues and problems
Migrating TIMES to another modelling language - approaches, issues and problemsMigrating TIMES to another modelling language - approaches, issues and problems
Migrating TIMES to another modelling language - approaches, issues and problemsIEA-ETSAP
 

Tendances (15)

Lesson 9.1 value returning
Lesson 9.1 value returningLesson 9.1 value returning
Lesson 9.1 value returning
 
Lesson 9.2 guessing the game program
Lesson 9.2 guessing the game programLesson 9.2 guessing the game program
Lesson 9.2 guessing the game program
 
Chapter 5 - The Selection Structure
Chapter 5 - The Selection StructureChapter 5 - The Selection Structure
Chapter 5 - The Selection Structure
 
Chapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection StructureChapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection Structure
 
Chapter 3 - Variables and Constants
Chapter 3 - Variables and ConstantsChapter 3 - Variables and Constants
Chapter 3 - Variables and Constants
 
Chapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving ProcessChapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving Process
 
System Concept Simulation for Concurrent Engineering
System Concept Simulation for Concurrent EngineeringSystem Concept Simulation for Concurrent Engineering
System Concept Simulation for Concurrent Engineering
 
Mechatronics engineer
Mechatronics engineerMechatronics engineer
Mechatronics engineer
 
[CapellaDay Toulouse] Designing a test mean alla capella
[CapellaDay Toulouse] Designing a test mean alla capella[CapellaDay Toulouse] Designing a test mean alla capella
[CapellaDay Toulouse] Designing a test mean alla capella
 
Mechatronics engineer
Mechatronics engineerMechatronics engineer
Mechatronics engineer
 
Portfolio control version sn_v5
Portfolio control version sn_v5Portfolio control version sn_v5
Portfolio control version sn_v5
 
Sample instrument using lab view abhijeet agarwal-1
Sample instrument using lab view  abhijeet agarwal-1Sample instrument using lab view  abhijeet agarwal-1
Sample instrument using lab view abhijeet agarwal-1
 
Capture Accurate Solution Requirements with Exploratory Modeling at SAP
Capture Accurate Solution Requirements with Exploratory Modeling at SAPCapture Accurate Solution Requirements with Exploratory Modeling at SAP
Capture Accurate Solution Requirements with Exploratory Modeling at SAP
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
 
Migrating TIMES to another modelling language - approaches, issues and problems
Migrating TIMES to another modelling language - approaches, issues and problemsMigrating TIMES to another modelling language - approaches, issues and problems
Migrating TIMES to another modelling language - approaches, issues and problems
 

Similaire à Lesson 6.1 more on selection structure

Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programmingmshellman
 
Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Kamran Zafar
 
Omni channel network design
Omni channel network designOmni channel network design
Omni channel network designfaiza20202880
 
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxCHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxketurahhazelhurst
 
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxCHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxrobertad6
 
QMB12ch01.pptx
QMB12ch01.pptxQMB12ch01.pptx
QMB12ch01.pptxJeseMadrid
 
HMK - Building Successful Information Systems
HMK - Building Successful Information SystemsHMK - Building Successful Information Systems
HMK - Building Successful Information SystemsMavisKnox1
 
Business Applications of Predictive Modeling at Scale
Business Applications of Predictive Modeling at ScaleBusiness Applications of Predictive Modeling at Scale
Business Applications of Predictive Modeling at ScaleSongtao Guo
 
Project 12 power point
Project 12 power pointProject 12 power point
Project 12 power pointaggie519
 
Functional and Non-functional Test automation
Functional and Non-functional Test automationFunctional and Non-functional Test automation
Functional and Non-functional Test automationDr Ganesh Iyer
 
Mc0084 software project management & quality
Mc0084 software project management & qualityMc0084 software project management & quality
Mc0084 software project management & qualitysmumbahelp
 
Chapter 7 QFD.ppt
Chapter 7 QFD.pptChapter 7 QFD.ppt
Chapter 7 QFD.pptGulaHangus
 
Xsemble - Make software like they make cars!
Xsemble - Make software like they make cars!Xsemble - Make software like they make cars!
Xsemble - Make software like they make cars!Ashish Belagali
 
How to Create a Cognos Analytics Dashboard
How to Create a Cognos Analytics DashboardHow to Create a Cognos Analytics Dashboard
How to Create a Cognos Analytics DashboardSenturus
 
Ci tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsCi tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsLinards Liep
 

Similaire à Lesson 6.1 more on selection structure (20)

Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
 
Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)
 
Omni channel network design
Omni channel network designOmni channel network design
Omni channel network design
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxCHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
 
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docxCHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
CHAPTER 4Distribution and Omni-Channel Network DesignSu.docx
 
Pp 14-new
Pp 14-newPp 14-new
Pp 14-new
 
Sql9e ppt ch08
Sql9e ppt ch08Sql9e ppt ch08
Sql9e ppt ch08
 
QMB12ch01.pptx
QMB12ch01.pptxQMB12ch01.pptx
QMB12ch01.pptx
 
HMK - Building Successful Information Systems
HMK - Building Successful Information SystemsHMK - Building Successful Information Systems
HMK - Building Successful Information Systems
 
Business Applications of Predictive Modeling at Scale
Business Applications of Predictive Modeling at ScaleBusiness Applications of Predictive Modeling at Scale
Business Applications of Predictive Modeling at Scale
 
Sql9e ppt ch05
Sql9e ppt ch05 Sql9e ppt ch05
Sql9e ppt ch05
 
Sql9e ppt ch07
Sql9e ppt ch07 Sql9e ppt ch07
Sql9e ppt ch07
 
Project 12 power point
Project 12 power pointProject 12 power point
Project 12 power point
 
Functional and Non-functional Test automation
Functional and Non-functional Test automationFunctional and Non-functional Test automation
Functional and Non-functional Test automation
 
Mc0084 software project management & quality
Mc0084 software project management & qualityMc0084 software project management & quality
Mc0084 software project management & quality
 
Chapter 7 QFD.ppt
Chapter 7 QFD.pptChapter 7 QFD.ppt
Chapter 7 QFD.ppt
 
Xsemble - Make software like they make cars!
Xsemble - Make software like they make cars!Xsemble - Make software like they make cars!
Xsemble - Make software like they make cars!
 
How to Create a Cognos Analytics Dashboard
How to Create a Cognos Analytics DashboardHow to Create a Cognos Analytics Dashboard
How to Create a Cognos Analytics Dashboard
 
Ci tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsCi tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepins
 

Plus de MLG College of Learning, Inc (20)

PC111.Lesson2
PC111.Lesson2PC111.Lesson2
PC111.Lesson2
 
PC111.Lesson1
PC111.Lesson1PC111.Lesson1
PC111.Lesson1
 
PC111-lesson1.pptx
PC111-lesson1.pptxPC111-lesson1.pptx
PC111-lesson1.pptx
 
PC LEESOON 6.pptx
PC LEESOON 6.pptxPC LEESOON 6.pptx
PC LEESOON 6.pptx
 
PC 106 PPT-09.pptx
PC 106 PPT-09.pptxPC 106 PPT-09.pptx
PC 106 PPT-09.pptx
 
PC 106 PPT-07
PC 106 PPT-07PC 106 PPT-07
PC 106 PPT-07
 
PC 106 PPT-01
PC 106 PPT-01PC 106 PPT-01
PC 106 PPT-01
 
PC 106 PPT-06
PC 106 PPT-06PC 106 PPT-06
PC 106 PPT-06
 
PC 106 PPT-05
PC 106 PPT-05PC 106 PPT-05
PC 106 PPT-05
 
PC 106 Slide 04
PC 106 Slide 04PC 106 Slide 04
PC 106 Slide 04
 
PC 106 Slide no.02
PC 106 Slide no.02PC 106 Slide no.02
PC 106 Slide no.02
 
pc-106-slide-3
pc-106-slide-3pc-106-slide-3
pc-106-slide-3
 
PC 106 Slide 2
PC 106 Slide 2PC 106 Slide 2
PC 106 Slide 2
 
PC 106 Slide 1.pptx
PC 106 Slide 1.pptxPC 106 Slide 1.pptx
PC 106 Slide 1.pptx
 
Db2 characteristics of db ms
Db2 characteristics of db msDb2 characteristics of db ms
Db2 characteristics of db ms
 
Db1 introduction
Db1 introductionDb1 introduction
Db1 introduction
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 
Lesson 3.1
Lesson 3.1Lesson 3.1
Lesson 3.1
 
Lesson 1.6
Lesson 1.6Lesson 1.6
Lesson 1.6
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 

Dernier

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Dernier (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.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)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Lesson 6.1 more on selection structure

  • 1. © 2016 Cengage Learning®. May not be scanned, copied or Introduction to Programming in C++ Eighth Edition Lesson 6.1: More on the Selection Structure duplicated, or posted to a publicly accessible website, in whole or in part.
  • 2. • Include anested selection structure in pseudocode andin aflowchart • Codeanested selection structure • Recognizecommon logic errors in selection structures • Include amultiple-alternative selection structure in pseudocode and in aflowchart • Codeamultiple-alternative selection structure in C++ © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 2 Objectives
  • 3. • True and false paths of aselection structure cancontain other selection structures • Inner selection structures are referred to asnested selectionstructures; contained (nested) within an outer selection structure • Nested selection structures are used when morethan one decision needs to be made before choosing an instruction • Inner (nested) selection structures are indentedwithin their outer selectionstructures © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 3 Nested Selection Structures
  • 4. Figure 6-1 Problem that requires a selection structure Nested Selection Structures (cont’d.) © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 4
  • 5. Nested Selection Structures (cont’d.) Figure 6-2 Problem that requires a nested selection structure © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 5
  • 6. Nested Selection Structures (cont’d.) Figure 6-3 Problem that requires two nested selection structures © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 6
  • 7. • Outer and inner selection structures can be thought of asmaking primary and secondary decisions, respectively • Secondary decision is called such because whether it needs to be made depends on the result of aprimary decision © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 7 Flowcharting a Nested Selection Structure
  • 8. Flowcharting a Nested Selection Structure (cont’d.) Figure 6-5 Problem specification for voter eligibility problem © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 8
  • 9. Figure 6-5 A correct solution to the voter eligibility problem Flowcharting a Nested Selection Structure (cont’d.) © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 9
  • 10. Figure 6-6 Another correct solution to the voter eligibility problem Flowcharting a Nested Selection Structure (cont’d.) © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 10
  • 11. • Codefor nested selection structures usesthe if and else statements • Nested selection structures can be placed in either if or else statement blocks • Correct tabbing makescode easier to read © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 11 Coding a Nested Selection Structure
  • 12. Coding a Nested Selection Structure (cont’d.) Figure 6-7 Code and sample run of the voter eligibility program © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 12
  • 13. • Four common logic errors made when writing selection structures – Usingacompound condition rather than anested selection structure – Reversingthe outer and nesteddecisions – Usingan unnecessary nested selection structure – Including an unnecessary comparison in acondition © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 13 Logic Errors in Selection Structures
  • 14. Logic Errors in Selection Structures (cont’d.) Figure 6-8 Problem specification and a correct algorithm for the Miller’s Car Rental © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 14
  • 15. Figure 6-9 Sample data and expected results for the algorithm shown in Figure 6-8 Figure 6-10 Result of desk-checking the correct algorithm Logic Errors in Selection Structures (cont’d.) © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 15