Page 50 - Modular_V1.1_Flipbook
P. 50

5.  If none of the expressions evaluates to true in a switch block, then which case is executed?

                           a.  Default                                      c.  Both a and b
                           b.  Break                                       d.  None of these

                  B.   Write ‘T’ for true and ‘F’ for false.
                       1.  The if…else statement is the simplest conditional statement.                   ……………………
                       2.  C++ does not allow nested if statement.                                        ……………………

                       3.  The if…else…if ladder is not a conditional statement in C++.                   ……………………
                       4.  We cannot use floating-point value in the switch statement.                    ……………………
                       5.  The if...else...if statement allows you to test multiple conditions.           ……………………

                  C.   Fill in the blanks using the words given below.



                                                             false, if, true, break, else


                       1.  The …………………… statement encloses multiple statements inside curly braces { }.
                       2.  In C++, the non-zero value is interpreted as …………………… .
                       3.  Conditional statement may give the result as true or …………………… .

                       4.  The …………………… block will be executed if and only if the provided condition evaluates to false.
                       5.  …………………… can be used inside the switch body but cannot be used inside if body.

                  D.   Short answer type questions.
                       1.  What are conditional statements?

                       2.  Define the if…else statement.
                       3.  Can ternary operator replace the if…else statement?
                       4.  Write the syntax of nested if statement.

                  E.   Long answer type questions.
                       1.  What is the purpose of if statement? Write the syntax of the if statement.

                       2.  Describe switch statement. What is the difference between if and switch statement?
                       3.  What is the purpose of default clause in a switch statement?

                       4.  Rewrite the following if-else segment using switch-case statement:
                           char code;
                           cin >> code;
                           if (code == 'A')
                           cout << "Accountant";
                           else
                           if (code == 'C' || code = 'G')
                           cout << "Grade IV";
                           else
                           if (code == 'F')
                           cout << "Financial Advisor";

                  48      Touchpad MODULAR (Version 1.1)-X
   45   46   47   48   49   50   51   52   53   54   55