CH06 - An Introduction to Programming with C+, Fifth...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to Programming with C++, Fifth Edition 6 - 1 Chapter 6 More on the Selection Structure At a Glance Instructor’s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Topics Classroom Activities/Additional Projects Key Terms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An Introduction to Programming with C++, Fifth Edition 6 - 2 Lecture Notes Chapter Overview In the previous chapter, the selection structure was introduced and implemented using the if and if/else forms of the structure. This chapter continues discussing the selection structure by introducing and implementing the third form of the selection structure, which is the switch form. The concept of nesting selection structures is also discussed and implemented. Chapter Objectives After completing the chapter, the student will be able to: Include a nested selection structure in pseudocode and in a flowchart Code a nested selection structure in C++ Recognize common logic errors in selection structures Include the switch form of the selection structure in pseudocode and in a flowchart Code the switch form of the selection structure in C++ Display a message along with the contents of one or more variables in a .NET program Instructor Notes Nested Selection Structures You can nest a selection structure within either the true path or false path of another selection structure. You would use a nested selection structure if more than one decision needs to be made before the appropriate action can be taken. The outer selection structure always represents the primary decision, while the nested (or inner) selection structure always represents the secondary decision. While nesting a selection structure seems to be fairly straight forward, students must properly design the nested structure if they want to be successful in implementing their desired logic. Also, it is imperative to properly code the structure. Following the proper indentation rules, as well as making the code readable, is a must in order for the code to execute successfully. Please review the example in Figure 6-1 on page 299. The problem is presented in pseudocode and flowchart form, as well as by implementing the actual C++ code. Another Example of a Nested Selection Structure Another example of C++ code is presented in Figure 6-5 on page 303. Both examples are very good ones to define your own rules for coding nested selection structures.
Background image of page 2
An Introduction to Programming with C++, Fifth Edition 6 - 3 Logic Errors in Selection Structures Typically, logic errors commonly made when writing selection structures are a result of one of the following mistakes: Using a logical operator rather than a nested selection structure Reversing the primary and secondary decisions Using an unnecessary nested selection structure Using a Logical Operator Rather Than a Nested Selection Structure In Figure 6-11 on page 308, you will find two algorithms. The first algorithm properly solves the
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CS 343 taught by Professor Katzman during the Spring '09 term at ITT Tech Tucson.

Page1 / 7

CH06 - An Introduction to Programming with C+, Fifth...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online