Decision Making Statements in C++ Notes | Basic Computer Engineering | RGPV BTech First Year

Decision Making Statements in C++ Notes | Basic Computer Engineering | RGPV BTech First Year


Decision Making Statements in C++

Programming рдореЗрдВ рдХрдИ рдмрд╛рд░ рдРрд╕реА рдкрд░рд┐рд╕реНрдерд┐рддрд┐рдпрд╛рдБ рдЖрддреА рд╣реИрдВ рдЬрд╣рд╛рдБ Program рдХреЛ рдХрд┐рд╕реА Condition рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдЕрд▓рдЧ-рдЕрд▓рдЧ рдирд┐рд░реНрдгрдп (Decision) рд▓реЗрдирд╛ рдкрдбрд╝рддрд╛ рд╣реИред C++ рдореЗрдВ рдРрд╕реЗ рдирд┐рд░реНрдгрдп рд▓реЗрдиреЗ рдХреЗ рд▓рд┐рдП Decision Making Statements рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред рдЗрди Statements рдХреА рд╕рд╣рд╛рдпрддрд╛ рд╕реЗ Program рдпрд╣ рддрдп рдХрд░рддрд╛ рд╣реИ рдХрд┐ рдХреМрди-рд╕рд╛ Block Execute рд╣реЛрдЧрд╛ рддрдерд╛ рдХреМрди-рд╕рд╛ Skip рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ред

Decision Making Statements рд▓рдЧрднрдЧ рдкреНрд░рддреНрдпреЗрдХ Software Application рдХрд╛ рдорд╣рддреНрд╡рдкреВрд░реНрдг рднрд╛рдЧ рд╣реИрдВред Banking Software, Student Management System, Online Shopping, ATM Machine, Login System рддрдерд╛ Result Processing рдЬреИрд╕реЗ Applications рдореЗрдВ Conditions рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдирд┐рд░реНрдгрдп рд▓рд┐рдП рдЬрд╛рддреЗ рд╣реИрдВред


Introduction

рдпрджрд┐ Program рдореЗрдВ рдХреЗрд╡рд▓ Sequential Statements рд╣реЛрдВ рддреЛ рд╕рднреА Statements рдПрдХ рдХреЗ рдмрд╛рдж рдПрдХ Execute рд╣реЛрддреА рд╣реИрдВред рд▓реЗрдХрд┐рди рд╡рд╛рд╕реНрддрд╡рд┐рдХ рдЬреАрд╡рди рдХреА рд╕рдорд╕реНрдпрд╛рдУрдВ рдореЗрдВ рдЕрд▓рдЧ-рдЕрд▓рдЧ рдкрд░рд┐рд╕реНрдерд┐рддрд┐рдпреЛрдВ рдХреЗ рдЕрдиреБрд╕рд╛рд░ рдЕрд▓рдЧ-рдЕрд▓рдЧ рдирд┐рд░реНрдгрдп рд▓реЗрдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реЛрддреА рд╣реИред рдЗрд╕реА рдХрд╛рд░рдг Decision Making Statements рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

Decision Making рдХрд╛ рдЖрдзрд╛рд░ Boolean Expression рд╣реЛрддрд╛ рд╣реИред рдпрджрд┐ Condition true рд╣реЛрддреА рд╣реИ рддреЛ рдПрдХ Block Execute рд╣реЛрддрд╛ рд╣реИ, рдЕрдиреНрдпрдерд╛ рджреВрд╕рд░рд╛ Block Execute рд╣реЛрддрд╛ рд╣реИред


Definition of Decision Making Statements

Decision Making Statements рд╡реЗ Statements рд╣реИрдВ рдЬрд┐рдирдХреА рд╕рд╣рд╛рдпрддрд╛ рд╕реЗ Program рдХрд┐рд╕реА Condition рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдЙрдЪрд┐рдд рдирд┐рд░реНрдгрдп рд▓реЗрдХрд░ рдЕрд▓рдЧ-рдЕрд▓рдЧ Statements Execute рдХрд░рддрд╛ рд╣реИред

Decision Making = Execute Statements According to a Condition

Need of Decision Making

  • Program рдореЗрдВ Logical Decisions рд▓реЗрдиреЗ рдХреЗ рд▓рд┐рдПред
  • Different Conditions Handle рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдПред
  • Dynamic Program Execution рдХреЗ рд▓рд┐рдПред
  • User Input рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдЕрд▓рдЧ-рдЕрд▓рдЧ Output рджреЗрдиреЗ рдХреЗ рд▓рд┐рдПред
  • Real World Problems Solve рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдПред
  • Program рдХреЛ Intelligent рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдПред

Characteristics of Decision Making Statements

  • Based on Boolean Conditions.
  • Improves Program Logic.
  • Supports Multiple Execution Paths.
  • Reduces Unnecessary Statements.
  • Used in Almost Every Program.
  • Essential for Real World Applications.

Types of Decision Making Statements

  1. Simple if Statement
  2. if-else Statement
  3. Nested if Statement
  4. else-if Ladder
  5. switch Statement

1. Simple if Statement

Simple if Statement рд╕рдмрд╕реЗ рд╕рд░рд▓ Decision Making Statement рд╣реИред рдпрджрд┐ Condition True рд╣реЛрддреА рд╣реИ рддреЛ Statement Execute рд╣реЛрддрд╛ рд╣реИ, рдЕрдиреНрдпрдерд╛ Program рдЕрдЧрд▓реЗ Statement рдкрд░ рдЪрд▓рд╛ рдЬрд╛рддрд╛ рд╣реИред

Syntax

if(condition) {   // Statements }

Example

int marks = 80; if(marks >= 33) {   cout << "Pass"; }

Flow of Execution

  • Condition Check рд╣реЛрддреА рд╣реИред
  • True рд╣реЛрдиреЗ рдкрд░ Block Execute рд╣реЛрддрд╛ рд╣реИред
  • False рд╣реЛрдиреЗ рдкрд░ Block Skip рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред

2. if-else Statement

рдпрджрд┐ Program рдХреЛ Condition True рддрдерд╛ False рджреЛрдиреЛрдВ рд╕реНрдерд┐рддрд┐рдпреЛрдВ рдореЗрдВ рдЕрд▓рдЧ-рдЕрд▓рдЧ Statements Execute рдХрд░рдиреА рд╣реЛрдВ, рддрдм if-else Statement рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

Syntax

if(condition) {   // True Block } else {   // False Block }

Example

int age = 20; if(age >= 18) {   cout << "Eligible"; } else {   cout << "Not Eligible"; }

Advantages of if-else

  • Handles Two Conditions Easily.
  • Easy to Read.
  • Improves Program Logic.
  • Suitable for Simple Decision Making.

3. Nested if Statement

рдЬрдм рдПрдХ if Statement рдХреЗ рдЕрдВрджрд░ рджреВрд╕рд░рд╛ if Statement рд▓рд┐рдЦрд╛ рдЬрд╛рддрд╛ рд╣реИ, рддрдм рдЙрд╕реЗ Nested if рдХрд╣рд╛ рдЬрд╛рддрд╛ рд╣реИред рдЗрд╕рдХрд╛ рдЙрдкрдпреЛрдЧ Multiple Conditions Check рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

Syntax

if(condition1) {   if(condition2)   {     // Statements   } }

Example

int marks = 85; if(marks >= 33) {   if(marks >= 75)   {     cout << "Distinction";   } }

Advantages of Nested if

  • Supports Multiple Conditions.
  • Suitable for Complex Logic.
  • Provides Better Decision Control.
  • Easy to Extend.

4. else-if Ladder

рдЬрдм Program рдореЗрдВ рджреЛ рд╕реЗ рдЕрдзрд┐рдХ Conditions рдХреЛ рдХреНрд░рдорд╡рд╛рд░ Check рдХрд░рдирд╛ рд╣реЛ, рддрдм else-if Ladder рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред Compiler рдКрдкрд░ рд╕реЗ рдиреАрдЪреЗ рдкреНрд░рддреНрдпреЗрдХ Condition рдХреЛ Check рдХрд░рддрд╛ рд╣реИред рдЬреЛ рдкрд╣рд▓реА Condition true рд╣реЛрддреА рд╣реИ, рдЙрд╕реА рдХрд╛ Block Execute рд╣реЛрддрд╛ рд╣реИ рдФрд░ рдмрд╛рдХреА Conditions Skip рдХрд░ рджреА рдЬрд╛рддреА рд╣реИрдВред

Syntax

if(condition1) {   // Statements } else if(condition2) {   // Statements } else if(condition3) {   // Statements } else {   // Default Statements }

Example

int marks = 82; if(marks >= 75) {   cout << "Distinction"; } else if(marks >= 60) {   cout << "First Division"; } else if(marks >= 45) {   cout << "Second Division"; } else if(marks >= 33) {   cout << "Pass"; } else {   cout << "Fail"; }

Advantages of else-if Ladder

  • Supports Multiple Conditions.
  • Easy Decision Making.
  • Improves Program Readability.
  • Suitable for Grading Systems.
  • Reduces Nested Conditions.

5. switch Statement

switch Statement рдХрд╛ рдЙрдкрдпреЛрдЧ рддрдм рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдЬрдм рдХрд┐рд╕реА Variable рдХреА рд╡рд┐рднрд┐рдиреНрди рдирд┐рд╢реНрдЪрд┐рдд (Fixed) Values рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдЕрд▓рдЧ-рдЕрд▓рдЧ Statements Execute рдХрд░рдиреЗ рд╣реЛрдВред рдпрд╣ Multiple Selection Statement рд╣реИред

Syntax

switch(expression) { case value1:   // Statements   break; case value2:   // Statements   break; default:   // Statements }

Example

int day = 2; switch(day) { case 1:   cout << "Monday";   break; case 2:   cout << "Tuesday";   break; default:   cout << "Invalid Day"; }

break Statement

break Statement рдХрд╛ рдЙрдкрдпреЛрдЧ switch Block рд╕реЗ рдмрд╛рд╣рд░ рдЖрдиреЗ рдХреЗ рд▓рд┐рдП рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред рдпрджрд┐ break рдХрд╛ рдЙрдкрдпреЛрдЧ рдирд╣реАрдВ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рддреЛ Program рдЕрдЧрд▓реЗ Case рдХреЛ рднреА Execute рдХрд░ рджреЗрддрд╛ рд╣реИ рдЬрд┐рд╕реЗ Fall Through рдХрд╣рд╛ рдЬрд╛рддрд╛ рд╣реИред

case 1:   cout << "One";   break;

default Statement

рдпрджрд┐ рдХрд┐рд╕реА рднреА case рдХреА Value Match рдирд╣реАрдВ рд╣реЛрддреА, рддрдм default Block Execute рд╣реЛрддрд╛ рд╣реИред рдпрд╣ Optional рд╣реЛрддрд╛ рд╣реИ рд▓реЗрдХрд┐рди Program рдХреА Reliability рдмрдврд╝рд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдЗрд╕рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рдЙрдЪрд┐рдд рдорд╛рдирд╛ рдЬрд╛рддрд╛ рд╣реИред

default:   cout << "Invalid Choice";

Difference between if-else and switch

Basis if-else switch
Condition Boolean Expression Constant Expression
Range Checking Supported Not Supported
Complex Conditions Supported Limited
Execution Speed Comparatively Slower Usually Faster
Best Use Logical Decisions Menu Driven Programs

Flowchart of Decision Making

Decision Making рдореЗрдВ рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ Condition Evaluate рд╣реЛрддреА рд╣реИред рдпрджрд┐ рдкрд░рд┐рдгрд╛рдо true рд╣реЛрддрд╛ рд╣реИ рддреЛ рд╕рдВрдмрдВрдзрд┐рдд Block Execute рд╣реЛрддрд╛ рд╣реИ, рдЕрдиреНрдпрдерд╛ рдЕрдЧрд▓реА Condition рдпрд╛ else/default Block Execute рд╣реЛрддрд╛ рд╣реИред


Common Errors

  • Using Assignment (=) instead of Comparison (==).
  • Missing Curly Braces.
  • Forgetting break in switch.
  • Incorrect Logical Conditions.
  • Using Duplicate case Labels.
  • Ignoring default Case.

Best Practices

  • Write Simple Conditions.
  • Always Use Meaningful Comparisons.
  • Include default in switch.
  • Use break in Every Case.
  • Avoid Deeply Nested if Statements.
  • Indent Code Properly.

Advantages

  • Supports Intelligent Decision Making.
  • Improves Program Logic.
  • Provides Multiple Execution Paths.
  • Essential for Real World Applications.
  • Easy User Interaction.

Limitations

  • Complex Nested Conditions Reduce Readability.
  • Incorrect Conditions Produce Wrong Results.
  • switch Cannot Evaluate Floating Point Expressions.

Applications

  • Login Authentication.
  • ATM Machine Software.
  • Student Result Processing.
  • Menu Driven Programs.
  • Banking Applications.
  • Hospital Management Systems.
  • Online Shopping Systems.
  • Game Development.
  • Compiler Design.

Industrial Importance

Decision Making Statements рдкреНрд░рддреНрдпреЗрдХ Professional Software рдХрд╛ рдЖрдзрд╛рд░ рд╣реИрдВред Enterprise Applications, Banking Systems, ERP Software, Operating Systems рддрдерд╛ Artificial Intelligence Programs рд╕рднреА User Input рдПрд╡рдВ Business Rules рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдирд┐рд░реНрдгрдп рд▓реЗрдиреЗ рдХреЗ рд▓рд┐рдП if, else-if рддрдерд╛ switch Statements рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реИрдВред


Viva Questions

  1. What is Decision Making?
  2. Explain Simple if Statement.
  3. What is if-else Statement?
  4. What is Nested if?
  5. Explain else-if Ladder.
  6. What is switch Statement?
  7. What is the purpose of break?
  8. What is default Statement?
  9. Differentiate if-else and switch.
  10. Where is switch Statement commonly used?

Exam Oriented Important Questions

  1. Explain Decision Making Statements in C++.
  2. Describe if, if-else and Nested if with examples.
  3. Explain else-if Ladder.
  4. Write the syntax and example of switch Statement.
  5. Differentiate if-else and switch Statement.
  6. Explain the role of break and default.
  7. Discuss the applications of Decision Making Statements.
  8. Explain the Industrial Importance of Decision Making.

Conclusion

Decision Making Statements C++ Programming рдХрд╛ рдЕрддреНрдпрдВрдд рдорд╣рддреНрд╡рдкреВрд░реНрдг рднрд╛рдЧ рд╣реИрдВ рдХреНрдпреЛрдВрдХрд┐ рдЗрдирдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ Program рд╡рд┐рднрд┐рдиреНрди рдкрд░рд┐рд╕реНрдерд┐рддрд┐рдпреЛрдВ рдХреЗ рдЕрдиреБрд╕рд╛рд░ рдЙрдЪрд┐рдд рдирд┐рд░реНрдгрдп рд▓реЗ рд╕рдХрддрд╛ рд╣реИред if, if-else, Nested if, else-if Ladder рддрдерд╛ switch Statements рдХрд╛ рд╕рд╣реА рдЙрдкрдпреЛрдЧ Program рдХреЛ рдЕрдзрд┐рдХ Intelligent, Flexible рддрдерд╛ Efficient рдмрдирд╛рддрд╛ рд╣реИред рдкреНрд░рддреНрдпреЗрдХ Computer Engineering Student рдХреЗ рд▓рд┐рдП рдЗрди Statements рдХреА рдЧрд╣рди рд╕рдордЭ рдЖрд╡рд╢реНрдпрдХ рд╣реИред

Related Articles

Manipulators in C++ Notes | endl, setw, setprecision, setfill | Basic Computer Engineering | RGPV BTech First Year

0...

Read More тЖТ

Type Conversion in C++ Notes | Basic Computer Engineering | RGPV BTech First Year

Type Co...

Read More тЖТ

Assignment Operator in C++ Notes | Basic Computer Engineering | RGPV BTech First Year

Assignm...

Read More тЖТ

Copy Constructor in C++ Notes | Basic Computer Engineering | RGPV BTech First Year

Copy Co...

Read More тЖТ

this Pointer in C++ Notes | Basic Computer Engineering | RGPV BTech First Year

this Po...

Read More тЖТ