Slide Set - 12
Slide Set - 12
Slide Set - 12
CP & CPSA
17ME & 17PG
Contents
• Conditional control flow (LL 02)
• One-way selection (LL 02)
• Two-way selection (LL 02)
• Multi-way selection (LL 02)
• Choice-way selection(LL 02)
• Conditional control structures in C++ (LL 04)
• if statement (LL 04)
• if – else statement (LL 04)
• if – else – if statement (LL 04)
• switch statement (LL 04)
LL 02 = Learning Level 02 – Comprehension, LL 04 = Learning Level 04 – Analysis
Contents
In conditional logic:
In one-way selection:
In two-way selection:
Marks Remarks
0 Very Bad
1 Not Satisfactory
2 Slightly Satisfactory
3 Satisfactory
4 Good
5 Excellent
Choice-Way Selection
In choice-way selection:
• We make a choice.
• If choice matches with 1st option, the 1st statement set is executed.
• If choice matches with 2nd option, the 2nd statement set is executed.
• If choice matches with 3rd option, the 3rd statement set is executed.
• And the process continues up to nth option.
• If choice matches with nth option, the nth statement set is executed.
Choice-Way Selection – Flow Chart
Following is the flow of execution of choice-way (4-way) selection:
Choice-Way Selection – Example
Problem Statement: Give remarks to the student according to the marks
he/she gets out of 5 in the sessional test.
Conditional Control Structures in C++
• The statements that are needed to be executed conditionally are placed with
in the conditional structures and one or more conditions are specified.
if ( condition ) if ( condition )
{ statement ;
statement set ;
}
if Statement – Syntax
if Statement – Syntax
Problem Statement:
There are two circular grounds Ground-A and Ground-B. Ground-A is having
diameter of 15 meters and Ground-B is having diameter of 20 meters. Mohsin
is running in Ground-A and Neetesh is running in Ground-B. Write a computer
program that asks the user to input the time taken, in seconds, to complete one
compete round of the ground by both the friends and displays who is running
faster.
Program Example 02
Program Example 02
Program Example 02
Program Example 03
Problem Statement:
Write a computer program that asks the user to enter three angles of a
triangle. The program displays whether the triangle is right-angle, acute-angle
or obtuse-angle.
Program Example 03
Program Example 03
Program Example 03
Program Example 04
Problem Statement:
Write a computer program that asks the user to enter date of birth and month
of birth. The program should display the zodiac star.
Program Example 04
Program Example 04
Program Example 04
Program Example 05
Problem Statement:
Write a computer program that asks the user to enter any character. The
program should whether the entered character is a vowel or a consonant.
Program Example 05
Program Example 05
Program Example 05