0% found this document useful (0 votes)
31 views3 pages

OOP Language Structure

The document discusses the structure of C++ programs, including sections like documentation, link, using directives, class declarations, member function definitions, and the main function. It provides examples of how each section is implemented in a C++ program, such as using header files in the link section, declaring a class with data members and methods, and defining member functions inside and outside the class. Key differences between C and C++ mentioned are C++ supports classes while C does not, and C++ is an extension of the C language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

OOP Language Structure

The document discusses the structure of C++ programs, including sections like documentation, link, using directives, class declarations, member function definitions, and the main function. It provides examples of how each section is implemented in a C++ program, such as using header files in the link section, declaring a class with data members and methods, and defining member functions inside and outside the class. Key differences between C and C++ mentioned are C++ supports classes while C does not, and C++ is an extension of the C language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OBJECT ORIENTED LANGUAGE STRUCTURE

 Different OOP languages employ different programming structures.


 This unit implements OOP through the use of C++ language
 C++ is an extension of C-language
 It was previously referred to as C with classes, hence C++
 C++ shares most elements with C language but have classes in addition.
 Like C, C++ program is structurally divided into different sections as follows;
1. Documentation Section
2. Link Section
3. Using directive
4. Class declaration/definition
5. Member function definition
6. Main function
These sections are as highlighted in the sample program below
#include <iostream> /* Link Section */
using namespace std; /* Using directive */

class findsum /* Class definition */


{
private:
int a,b;
public:
void input();
void sum();
};
void findsum::input() /* Member function definition */
{
cout << "Enter values of a and b:";
cin >> a >> b;
}
void findsum::sum() /* Member function definition */
{
cout <<"Sum = "<<a+b;
}

int main() /* Main function definition */


{
findsum x;
x.input();
x.sum();
return 0;
}
1. Documentation Section
 It is a section where comments/description about the program code are written.
 Comments are not compiled by compiler i.e. they are ignored.
 Comments are used to minimize confusion and increase readability.
 There are two types of C++ comments, i.e.
a. Single line comment:
Written within a single line after ‘//’. For example;
// This is a single line comment.
b. Multiple line comment:
Written in multiple lines and is enclosed within ‘/*’ at the beginning of the comment and ‘*/’ at the end of
the comment.
.
2. Link Section
 This is a place where header files required for the program are included.
 Header files consists of built-in functions, classes, keywords, constants, operators, etc.
 These files are linked to the source code by use of the preprocessor directive “#include”.
 Some common header files include iostream, cstring, cmath, etc or user-defined.
 The links takes the formart;
#include <header_filename> //for predefined headers
or
#include "header_filename" //for user-defined headers

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

Assignment: State 5 differences between C and C++ Language

Object Oriented Programming Data Types

You might also like