OOP Language Structure
OOP Language Structure
3. Using directive
This section allows the use of namespace.
Namespace consists of data and functions which will be used in the program.
Syntax
using namespace namespace_name;
e.g.
using namespace std;
Namespace std contains declarations for cout, cin, endl, etc. statements.
4. Class declaration/definition
In this section, classes used in the program are declared and/or defined.
The body of class is enclosed by curly brackets and ends with a semicolon.
Class consists of member data and functions which are the members of that class.
Syntax For example
class classname class example
{ {
private: private:
memberdata; int a,b;
methods(); public:
public: void input();
memberdata; void displaySum();
methods(); };
protected:
memberdata;
methods();
};
5. Member function definition
Member functions can be defined inside or outside the class.
If the member function is defined outside the class, the class name to which the function belongs and scope
resolution operator (::) is used before function name.
Syntax Example
returntype classname::function_name([argument list]) void example::input()
{ {
body of function cout <<"Enter values of a and b:";
} cin >> a >> b;
}
6. Main function
Main function is the basic function that is required for the program to be executed.
This is where the program execution always begins.
Syntax
int main()
{
statements;
... ... ...
}
Note: The file extension for a C++ program source code is .CPP