Free Training
C Language   |   CSS   |   MainFrame   |   VBScript   |   PHP   |   XML   |   C++ Tutorials   |   Ajax   |   JavaScript   |   CSS3   |   UML   |   jQuery   |   Microsoft AJAX

Sponsored Links

C++ Tutorials

 
Home Tutorials C++
 

Basic concepts of OOPS and Structure of C++ program

 

Basic concepts of OOPS and Structure of C++ program

In this tutorial you will learn about Objects, Classes, Inheritance, Data Abstraction, Data Encapsulation, Polymorphism, Overloading, Reusability.


Before starting to learn C++ it is essential that one must have a basic knowledge of the concepts of Object oriented programming. Some of the important object oriented features are namely:



  • Objects
  • Classes
  • Inheritance
  • Data Abstraction
  • Data Encapsulation
  • Polymorphism
  • Overloading
  • Reusability

In order to understand the basic concepts in C++, the programmer must have a command of the basic terminology in object-oriented programming. Below is a brief outline of the concepts of Object-oriented programming languages:


Objects:

Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data.



An Object is a collection of data members and associated member functions also known as methods.


Classes:

Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represent a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects becomes functions of the class and is referred to as Methods.


For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.


No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.


Inheritance:

Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.


Data Abstraction:

Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.


Data Encapsulation:

Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible.


Polymorphism:

Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.


Overloading:

Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded.


Reusability:

This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections. 


A sample program to understand the basic structure of C++


//program to read employee details and to output the data 
#include <iostream.h>                      
Preprocessor directive
class employee                             
Class Declaration    
{
   private:
     char empname[50];
     int empno;

   public:
     void getvalue()
     {
        cout<<”INPUT EMP NAME:”;
        cint>>empname;
        cout<<”INPUT EMP NO:”;
        cint>>empno;
     }


     void displayvalue()
     {
        cout<<”EMP NAME:”<<empname;
        coout<<EMP NO:”<<empno;
     }
};


main()
{
     employee e1;                             
Creation of Object
     e1.getvalue();
     e1.displayvalu();
}




Overview of the Basic Structure of C++ Programming



  • The // in first line is used for representing comment in the program.
    .
  • The second line of the program has a # symbol which represents the preprocessor directive followed by header file to be included placed between < >.
    .
  • The next structure present in the program is the class definition. This starts with the keyword class followed by class name employee. Within the class are data and functions. The data defined in the class are generally private and functions are public. These explanations we will be detailed in later sections. The class declaration ends with a semicolon.
    .
  • main() function is present in all C++ programs.
    .
  • An object e1 is created in employee class. Using this e1 the functions present in the employee class are accessed and there by data are accessed.
    .
  • The input namely ename and eno is got using the input statement namely cin and the values are outputted using the output statement namely cout.

Read Next: Variable, Constants and Data types in C++



 

 

Comments


saurabh Shah said:

  Nice to understand
November 28, 2006, 8:22 am

karthik.T said:

  It is very easy to understand.
August 28, 2007, 5:35 am

Sachin Rudraksha said:

  This is very time saving and good for understading.
September 3, 2007, 8:42 am

suruli said:

  easy learning techniques
November 2, 2007, 3:09 pm

Very gud ya said:

  Nice material
November 14, 2007, 3:37 am

Hicham said:

  Make hard stuff softer thank you
November 14, 2007, 9:48 am

Hicham said:

  Easy to understand. Very clear and concise. thank you
November 14, 2007, 9:49 am

R.A.Kalyani said:

  really superb!Anyone at the beginner level even can grasp.
November 18, 2007, 11:07 am

Ranjith kumar nuthakki said:

  good stuff for begineer's can easily understand by all the programmer's also
November 23, 2007, 3:28 am

Irshad1 said:

  These are very useful information for beginners related to oops
December 5, 2007, 3:18 am

swapna gajula said:

  Good information about OOPS concpts and very easy to understand in less time
December 7, 2007, 3:39 pm

srilakshmi said:

  easy to understand ,thank u for the information
December 10, 2007, 7:53 pm

raghavan said:

  very esay
December 15, 2007, 2:16 am

raghavan said:

  very esay to learn
December 15, 2007, 2:26 am

tera said:

  very esay & clear
December 26, 2007, 6:05 am

MMamgain said:

  It very good this one can understand and st the same time duplicate also.Thanks
January 1, 2008, 3:01 pm

therasal said:

  easy to learn
January 19, 2008, 7:35 am

vidy said:

  easy to learn
January 24, 2008, 2:31 am

chhinnappa said:

  really interesting and easily to learn
February 8, 2008, 12:23 am

sakiriyas said:

  it is very easy to understand the concepts ,,as a learner this will lead to you in a right way get in to the deep in oops
February 12, 2008, 7:50 am

raja ramesh tadi said:

  easy to learn for fresh programmers
February 25, 2008, 12:21 am

Santhosh Kharvi said:

  Very easy to learn & Understanding, Thank u for information
February 26, 2008, 6:29 pm

selvaraju.n said:

  very nice tounderstand
March 4, 2008, 10:58 am

Chandra Sekhar Puli said:

  All the oops concepts are covered in an easily understandable way.
March 15, 2008, 1:28 am

ganeshbabu said:

  very easy to learn
April 5, 2008, 3:28 am

sumit123 said:

  Very well done
April 9, 2008, 5:26 pm

prabhu1r said:

  It is very valuable to the user
April 11, 2008, 1:00 pm

ANILOVE4u said:

  It's been a gr8 time to understand the oops very well.
April 23, 2008, 1:17 pm

hdjkfhsd said:

  it is very useful for beginers
May 13, 2008, 12:34 pm

Sudhaka Reddy K said:

  Easy to understand, Good for beginesrs
May 16, 2008, 12:32 am

Mahii said:

  Very useful material ,Its has been very clearly explained.
May 20, 2008, 8:09 pm

amri665 said:

  very good!! 4 quick revision
May 28, 2008, 12:28 am

Manish.Kumarxl said:

  Very usefull info in less terms to understand the basic concept... :)
June 5, 2008, 10:56 pm

Noorjakhan said:

  easy to understand
June 8, 2008, 5:31 am

PriyaPathak said:

  This is very good.

Thanks and regards.
June 9, 2008, 9:09 am

witcos said:

  nice and easy to learn and undetstand

Thanks Great Job
June 21, 2008, 6:38 am

saurabh jindal 9868769682 said:

  i was reading with the books but i was so confused, thanks for this tutorials.
June 25, 2008, 7:04 am

seethu said:

  really superb!!
July 4, 2008, 12:52 am

Mona said:

  This topic is very productive and easy to understand for every one. Keep it up !!!!
July 10, 2008, 2:42 am

VInothSathya(Rajapalayam) said:

  Easy to understand .Thanks.....
July 11, 2008, 6:38 am

anush said:

  very useful information to students&users
July 13, 2008, 8:02 am

swapna hs said:

  it is very helpful,concepts are explained in a simple manner
July 16, 2008, 3:08 am

karan4u said:

  Great tutorials, for quick learning
July 18, 2008, 6:56 am

papa elie said:

  an important material that speeds up understanding
July 25, 2008, 1:39 am

pritt said:

  very useful and easy to learn
August 10, 2008, 4:42 am

sheetal.m.v said:

  it all depends how we use our logic
August 17, 2008, 12:39 pm

somendra said:

  it should be more allobrate
August 29, 2008, 3:11 am

MANO said:

  That is excellent material, which is used for beginers.

THANK U
September 2, 2008, 5:41 am

Desh said:

  Always Simply Superb .... illustrated with good example for objects...

Thanks
September 16, 2008, 9:39 pm

sntc99 said:

  what about dyanmic binding and message passing
September 27, 2008, 3:33 am

Ramesh Kumar A said:

  Good Explanation !!!
October 3, 2008, 4:15 am

Saaju said:

  Some examples that are needed
October 5, 2008, 8:27 pm

gouthami said:

  there are certain features in the basics they r message passing and dynamic binding you missed them.otherwise nice explanation.
October 22, 2008, 9:41 am

mammay said:

  very good stuff
October 23, 2008, 1:44 am

radhika said:

  this is excellent material and Easy to understand.
November 5, 2008, 2:23 am

Aizaz Ahmad Khan Durrani said:

  that is good for a person who don't know about basic of oop.
November 6, 2008, 11:45 am

chennarao said:

  nice material easy to understand
November 12, 2008, 7:31 am

Rahul tyagi said:

  very easy & understand language i say thanks
November 14, 2008, 1:16 am

quanghoahcm said:

  very good!!!thank very much!!!!!!!!
November 19, 2008, 10:32 pm

gagan said:

  Thank u.
very good detail of concept of c++
December 1, 2008, 9:57 am

aiyanar said:

  is very useful computer student in oop
December 5, 2008, 12:27 pm

Datta said:

  It's very nice version.simple for understand every programmer
December 11, 2008, 2:09 am

k.uday bhaskar said:

  Details is very good
December 12, 2008, 1:51 am

Priya said:

  Very easy to understand and simple.
Thank u very much
December 17, 2008, 11:52 pm

dhanesh said:

  nice and useful
December 22, 2008, 7:50 pm

jayaprakashreddy said:

  what is meant by preprocessor directive
December 28, 2008, 12:52 am

tamrez alam said:

  this matter is very easy for exams
December 30, 2008, 12:53 am

khemanand said:

  simple but not in detail .
January 2, 2009, 2:12 am

manish said:

  thanks
this is very simple and easy to understand...
thanks
January 5, 2009, 2:19 am

sanjay said:

  learn very nice
January 11, 2009, 6:54 am

aditya said:

  explain the simple method to understand the oop in full vision
January 13, 2009, 8:14 am

Deepak said:

  this is very nice way to learn..
January 18, 2009, 3:16 am

rakshita said:

  thanks!!!
its really very easy and understanding.
January 24, 2009, 7:23 am

0 said:

  exact meaning is given in brief.
it is very much helpful
February 12, 2009, 8:29 am

avinash dande said:

  It's easy n simple to understand for begineer's.But there shd be more pictures to full understand concept.
February 17, 2009, 2:55 pm

Rama said:

  nice material
February 19, 2009, 5:08 am

Ravi said:

  An object represents a particular instance of a class, what is instance of class.....over object of class.how u can relate instance with object
February 20, 2009, 1:29 am

varsha said:

  it is a very nice material
February 23, 2009, 7:11 am

vikas nema said:

  An object represents a particular instance of a class, what is instance of class.....over object of class.how u can relate instance with object
March 8, 2009, 10:56 pm

Ersalan said:

  Thanks a lot mate... One can just whisk through this to refresh their memory before an interview or something... Good Job!
April 3, 2009, 2:26 am

shazia naeem omari said:

  Thanks for making a language very easy to understand and pick good points very easily. Thanks a lot
April 11, 2009, 2:22 am

karthikeyan said:

  An object represents a particular instance of a class, what is instance of class over object of class. How you can relate instance with object.
April 22, 2009, 6:38 am

manisha said:

  its really understanding and learnable.
in which we easy to learn and understand the concept,thanx
May 28, 2009, 11:08 am

sadan Kumar said:

  "An object represents a particular instance of a class. There can be more than one instance of an object."
These two line is really confusing, Anyway it's a good material that gives quick understanding on OOPs. Thanks...
June 4, 2009, 5:34 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links