Documente Academic
Documente Profesional
Documente Cultură
Instructions
• Get a partner and follow the steps below and answer each question to the best of Y
Decision Process A
your abilities
A
• Submit a single 1 whole sheet of Pad Paper with both your class numbers
• Feel free to use the previous Lecture Slides and the Internet to search for the answers
N
when you get stuck
Y
Decision Process B
Objectives B
1. To be familiar with the syntax of the two methods of implementing the Multi-Way N
Selection in C++
Y
2. To understand the limitations and advantages of the two methods Decision Process C
C
Recall the Multi-way Selection…
N
• Used for comparing a variable to different possible values
• Only one variable should be tested by all Decision Blocks – this variable is called the Control Variable
Let’s Begin!
There are codes below for you to type and execute. Run the program then answer the questions afterwards.
1
Example 1.1 Example 1.2
Given the code above, what is the output if the User enters… 5. What is the output if the User enters 1?
1. …0? 6. How many statements did it output? Why?
2. …2? 7. What is the statement that I need to insert if I wanted to output
3. …5? “I’m hot!” when the User enters 4?
4. …6? 8. Where should I insert this statement?
Change the condition (x == 2) to (x == 1) like Example 1.2
Remove the last statement of the If-else-if Ladder and return the
condition to (x == 2) like Example 1.3
2
Example 1.3
Add another variable and change the program like Example 1.4 What is the output if the User enters…
14. …3 then 3?
15. …1 then 4?
16. …2 then 0?
17. When the If-else-if Ladder has two control variables, is it a Multi-
way Selection? Why?
That’s it for the If-elise-if Ladder. Let’s try the Switch statement
instead
3
Example 2.1 Example 2.2
What is the output if the User enters… 21. What’s the difference between Example 2.1 and 2.2 aside from
18. …0? changing the 0 to 1?
19. …2?
Return the case to 0 and remove the break statements like Example
20. …4?
Change “case 0” to “case 1” like the Example 2.2 2.3
4
Example 2.3
Return the break statement and remove the default case like
Example 2.4
5
Example 2.6