You are on page 1of 3

Components of a c++ program

1. Pre-processor directives
Syntax: #include <?>
o Header files/libraries
Ex. A. #include<iostream.h>
o Iostream = input output iostream
B. #include <iostream>
> using nonspace std,

2. Main Function
Syntax: data type main ()
Tells what will be the output
o Data type : int = integer
o : float = decimal point
o : double = decimal point
o : char = character for symbols
o : bool = or/not
Ex. int main()
float main()
3. Constant and type definition section
o Optional

Syntax: const data type variable name = value

Ex. const float pi = 3.1416
4. Declaration section
o Variables

Syntax: data type variable name
Data type veriable name = value
Ex. int base;
float radius = 1.5;

; = end of line

5. Statement section
o Body of the program

{
_________________;
_________________;
_________________;
}
\n = next line ^^


o Console output cout
Syntax: cout<< ;
cout<< Hello World! ;
o cin console input
syntax: cin>> variable name

ex. cin>> x ;
cin>> q1 >> q2 >> q3 ;
pause (choose one): cin.get();
system.pause();
return();






#include <iostream>
using namespace std;

int main()
{
cout<< Hello World!;
cin.get();
system.pause();
return();
}


A = (pi)r^2

#include <cmath>
#include <iostream>
using namespace std;

double main ()
{
const double pi = 3.1416;
double Area, radius;
cout<< enter radius:
cin>> radius;
Area = pi + (radius & radius);
= pow (radius, 2)
cont<< The area of a circle is: << Area <<endl ;
cont<<
Return0;
}

You might also like