Page 268 - Computer_Science_F5
P. 268

Exercise 4.10

              1.  Write a C++ program
                  that can enable  a user                                                          Chapter Four: Object oriented programming with C++
                  to convert Fahrenheit to
          FOR ONLINE READING ONLY
                  Centigrade degree. Use the
                  formula,  Centigrade=5/9
                  (Fahrenheit-32).
              2.  Write the following program                    Figure 4.36: Output
                  on C++ text editor; then,        6.  Construct a C++ program that takes a
                  display the output.                  character as an input from the keyboard

                                                       and converts it into a capital letter or small
                      #include<iostream>
                                                       letter depending on its form. A program
                     using namespace std;              should check the validity of the entered

                          int main()                   character and display a message “The
                              {
                                                       entered character is not an alphabetical
                        cout<<”2%3 = “<<2%3;           letter” if the input is not a letter.
                              return 0;            7.  Give the output of the given program
                              }

              3.  Write a C++ program that             #include <iostream>
                  enables the user to calculate        using namespace std;
                  the gradient (slope) of the          int main()
                  straight line. A program will     {
                  prompt the user to enter two         cout << “1 + 5 = “ << 1 + 5 << endl;
                  points (x1, y1) and (x2, y2).
                  Then,  a  program  will  find        cout << “13 + 89 = “ << 13 + 89 << endl;
                  and display a slope. Use the         cout << “30 - 20 = “ << 30 - 20 << endl;
                  formula:                             cout << “4 - 90 = “ << 46 - 90 << endl;
                          y –y
                           2
                      Slope= x –x 1                    cout << “2 * 7 = “ << 2 * 7 << endl;
                           2   1                       cout << “5 / 2 = “ << 5 / 2 << endl;
              4.  What are the functions of
                  “cout” and “cin” in writing a        cout << “21 / 7 = “ << 21 / 7 << endl;
                  C++ program?                         cout << “35 % 6 = “ << 35 % 6 << endl;

              5.  Using output stream “cout”           cout << “4 % 6 = “ << 4 % 6 << endl;
                  , write a C++ program that           return 0;
                  displays  the following table
                  as shown in Figure 4.36:          }


                                                    259
               Student’s Book  Form Five



     Computer Science Form 5.indd   259                                                     23/07/2024   12:34
   263   264   265   266   267   268   269   270   271   272   273