Structure of a C++ Program

Structure of a C++ Program

Comment section
Include files
Class Declaration
Class Function Definition
Main Function
Structure of C++ Program
Comment Section:-
Comment section contains the name of the program, author of the program etc. These comments we can provide in two types.
1.Single line comment
2.Multiline Comment
Single line Comment:- It is represented with //. If you write // before any line that line is ignored by the compiler.
Multiline Comment:- It is represented with /* and */. Within /* and */ we can write many no. of lines. Those lines ignored by the compiler.
Note:- Single line or multiline comments we use in our program many no. of times according to the purpose.
Include files:-
Include files are used to include the user defined files or header files. Source file for C++ is #include
# is a preprocessor
Include is a directive
I means input
O means output
Stream is nothing but string
H means header file.
Class Declaration:-
Class declaration contains only class <classname>; . This is used in the combination of data members and member functions and friend functions.
Class Definition:- Class definition contains
class < classname >
{
<accessspecifier>:
<datamembers>;
<accessspecifier>:
<memberfunctions>;
};
We can define class functions within the class or outside the class.
main():-
Program execution starts from the main(). By default main() contains 2 arguments in c++. Those are argc,argv. Argc means argument count. Argv means argument vector list. main() contains collection of objects. Objects are used to access the data members and member functions of the class. main() is having by default return type is int. but int occupies 2 bytes space in the memory. So we use void. Because void doesn’t occupies any space in the memory.
Procedure oriented and object oriented differences
1. It follows top down approach.1. It follows bottom up approach.
2. large programs are divided into functions.2.Programs are divided into objects.
3.Most of the share global data.3. Data structures are designed such that they characterize the objects.
4. Data move openly around the system from function to function.4.Functions that operate on the data of an object are tide together in the data structure.
5.Function transform data from one form to another.5. Data is hidden and cannot be accessed by external functions.
6.Objects may communicate with each other through functions.
7.New data and functions can be easily added whenever necessary.