Professional Documents
Culture Documents
5.switch Statement
5.switch Statement
INTRODUCTION TO PROGRAMMING(CS-1102)
Lecture# 05
Course Instructor: Anam Naseer
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 1
30-Nov-20
Switch Statement
Flowchart
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 6
Example 1 29-Nov-20
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 7
Example 2
8
Example 3
To find maximum
9
Example 4 To check vowel or consonant
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 10
Practice Questions
Solve all of these questions using both switch statement and if-else statement
Q#01:
Write a program that accepts the code number as an input and display the correct disk drive
manufactures as follows:
• Code Disk drive manufacture
• 1 Western Digital
• 2 3G Corporation
• 3 Maxell Corporation
• 4 Sony Corporation
• 5 Verbatim Corporation
Q#02:
• Write a program that uses the following categories of movies:
• A for Adventure movies
• C for Comedy movies
• F for Family movies
• H for Horror movies
• S for Science fiction movies
• The program inputs code for movie type and displays its category. For example if the user enter H,
it displays “Horror movies”. The program should also display a menu of movie categories.
Q#03
• Write A Program To Check Whether A Number Is Positive Negative Or Zero
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 11
29-Nov-20
C++ How to Program by Paul Deitel & Harvey Deitel, Eighth Edition 12