Page 242 - Computer_Science_F5
P. 242

Program Example 4.3:

               Finding average

               The following is a C++ program that finds the average of 50, 70, 100 and 80.        Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
                    #include<iostream>
                    using namespace std;
                    int main()
                    {
                           //Find average marks of 50, 70, 100 and 80
                           cout<<”Average of the marks is “<<(50+70+100+80)/4<<endl;
                           return 0;
                    }


               The output will be average of the marks which is 75.



              Installing a Borland C++ compiler


                 Activity 4.1:

                Installation of Borland C++

                Step 1:  Download the complete version of Borland C++ Compiler.
                Step 2:  Copy the folder of Borland in the C drive.

                Step 3:  Write each step to install Borland C++ Compiler in your computer.


              Errors in computer programming
              When writing a computer program, you may make errors, such as incorrectly typing
              a keyword, or you may forget to declare a variable within a program, or initialise a
              variable with a wrong value. For example, you may write cot << “Hello, World! \n”;
              instead of cout << “Hello, World!\n”;. once you do that, the compiler will complain.
              Once an error has happened, you have failed to correctly adhere to the rules of writing
              a computer program according to the language rules, and the compiler finds it.
              If the compiler finds one or more errors during the compilation phase, it will not
              translate the program to machine code, and as a result, such a program will not
              run.  However,  once  you  fix  such  an  error  and  compile  the  program,  it  will  run
              successfully.

              There  are  four common  errors that  may  occur  when someone  write  a  computer
              program. These are syntax, semantic, logical, and run-time errors.

                                                    233
               Student’s Book  Form Five



     Computer Science Form 5.indd   233                                                     23/07/2024   12:33
   237   238   239   240   241   242   243   244   245   246   247