Page 57 - Modular_V2.0_C++_Flikpbook
P. 57

6.  Find the error in the following code and rewrite the correct code:

                          int time = 08;
                          if(time < 12)
                          {
                              cout>>"Good morning.";
                          }
                           else if(time > 20)
                          {
                              cout<<"Good night.";

                          }
                          else
                          {
                              cout<<"Good evening.";
                          }


                                                       In the lab                          21 st  Century   #Technology Literacy
                                                                                               Skills
                                                                                                   #Critical Thinking
                     Write a program to:
                         Accept a number from the user and check whether it is positive or negative.
                         Accept number of day from the week and display the day of the week.
                         Calculate the grade of an employee with the following conditions using switch statement.
                            5667                  A
                            6443                  C
                            3546                  E
                            4535                  B
                          Check whether the year entered by the user is a leap year or not. An year is a leap year if it is
                         divisible by 4 and not divisible by 100 for a century year. The century year is a leap year only if
                         it is perfectly divisible by 400.
                          Accept three numbers from the user, then print ‘You Won’ if the sum of input numbers is
                         greater than 1000.




                  Teacher's Corner

                 1.   Discuss all the conditional statements provided by C++ with the students.
                 2.   Explain the difference between switch and if…else…if ladder to the students.















                                                                                                                  55
                                                                                           Conditional Statements
   52   53   54   55   56   57   58   59   60   61   62