Page 234 - Computer_Science_F5
P. 234
Program Example 4.1:
Simple program to display text
Simple C++ program to display text “Introduction to C++ programming” Chapter Four: Object oriented programming with C++
FOR ONLINE READING ONLY
#include<iostream>
using namespace std;
int main()
{
// Display text Introduction to C++ program
cout<<”Introduction to C++ program”<<endl;
system(“PAUSE”);
return 0;
}
Description of line of codes in a program
Table 4.2 shows the application of each line from the given C++ programs as
presented in Program Example 4.1.
Table 4.2: Defining the structure of the C++ program
Line Description
#include<iostream> It is a preprocessor directive that tells the compiler to
include iostream, to support input and output operation.
N.B: - Sometime iostream is known as header file because
it is included at the head of a program.
using namespace std; This alerts the compiler to find the names in the standard
library, for a example, “cout” and “cin” are defined in the
standard library.
int main() The main function “main()” defines the body of the
program to which a program execution takes place. The
statements within the function should be enclosed by curl
brackets”{}.” Every statement in the main function of
the C++ program should end with a semicolon “;” as the
statement terminator.
225
Student’s Book Form Five
Computer Science Form 5.indd 225 23/07/2024 12:33

