Page 249 - Computer_Science_F5
P. 249

Computer Science  3.  Type the program on the Dev C++ text editor.
             4.  Compile the program.
             5.  Identify errors obtained after compiling the program.
             6.  State the errors obtained after compiling the program.
          FOR ONLINE READING ONLY

               Exercise 4.7

             1.  What is wrong with the following program?


                             #include <iostream.h>
                             using namespace std; /
                             int main()
                             {
                             int y = 0;
                             cout << “xy= “ << y << endl;
                             return 0;
                             }


             2.  Compile and run the following program; thereafter, explain the output.

                  #include <iostream>
                  using namespace std;
                  int main()
                  {
                         cout << “Size of char: “ << sizeof(char) << “ byte” << endl;
                         cout << “Size of integer: “ << sizeof(int) << “ bytes” << endl;
                         cout << “Size of float: “ << sizeof(float) << “ bytes” << endl;
                          cout << “Size of double: “ << sizeof(double) << “ bytes” << endl;
                         return 0;
                  }


             3.  Examine the following C++ code and answer the questions that follows.

                   string str1;
                   string str2;
                   char ch;
                   cin >> str1;
                   str2 = str1;
                   cin >> ch;
                   str2[0] = ch;
                   cout << str1 << “ –> “ << str2 << endl;


                                                 240
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   240                                                     23/07/2024   12:33
   244   245   246   247   248   249   250   251   252   253   254