C++
C++ is a middle-level programming language developed by Bjarne Stroustrup in 1979 at Bell Labs.
C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming.
C++ is known as a middle-level language, as it is having features of both high-level and low-level language features.
C++ is a superset of C,C++ is derived from C Language.
Object-Oriented Programming
C++ fully supports object-oriented programming, including the four pillars of object-oriented development:
· Class
· Object
· Encapsulation
· Data Abstraction
· Inheritance
· Polymorphism
· Message Passing
Class
It is similar to structures in C language. Class can also be defined as user defined data type. Class contains data members and member functions in it. It declares & defines what data variables the object will have and what operations can be performed on the class's object.
Object
Objects are the basic run time entity. They are instances of class, which have data members and use various member functions to perform tasks. Object is also known as class type of variable.
Encapsulation
Encapsulation is the process to wrapping the data and functions into the single unit(class).It is one the most useful feature of the class. Data are not accessed outside the class and only function inside the class can access it. It is also called data hiding.
Abstraction
Abstraction is act of representing essential features without including the background details. We can create class as abstract class to perform this feature of abstraction.
Inheritance
Inheritance is the process of creating new class from the existing class. Existing class is known as base class and new class is called derived class. It is a way to reuse the code again and again. So when a class is derived from base class it can have some or all features of the base class and it can have its own feature too.
Polymorphism
One name multiple forms. With this feature we can create functions with same name but different arguments. So function name is same but definition and signature of functions is different.
Message Passing
Objects can communicate with each other. It requires creating classes, creating objects of classes and establishing communication between objects.
Benefits of object oriented programming
Code Reusability: Feature of inheritance allow to eliminate redundant code and extend the use of existing class
Data Hiding: It can help to build secure programs.
Message Passing: Message communication between objects makes interface simpler
It implements like real life scenario
It is easy to partition the work on the class and object base
Easily upgraded from small to large systems and easy to update and maintain the programs
Different between C and C++
C
|
C++
|
C is procedural oriented programming language
|
C++ is object oriented programming language
|
C is subset of c++
|
C++ is superset of c
|
C does not support data hiding
|
C++ supports data hiding
|
C is functional driven language
|
C++ is object driven language
|
Being procedure oriented programming language it has no support for polymorphism, inheritance, encapsulation
|
Being Object oriented programming language it has support for polymorphism, inheritance, encapsulation
|
C does not support function overloading and operator overloading
|
C++ support function overloading and operator overloading
|
C does not provide error handling
|
C++ provides error handling with “exception handling”
|
C does not have feature of class
|
In C++ data and functions are encapsulated together in class
|
C does not support reference variable
|
C++ supports reference variable
|
Different between Procedure Oriented and Object Oriented
Procedure Oriented
|
Object Oriented
|
C, VB, Fortron
|
C++,java,vb.net
|
Program is divided in to small parts called function
|
Program divided into parts called object
|
Functions are given more important than data
|
Data are given more important than functions
|
Data can move freely from function to function
|
Objects can move and communicate with each other
|
It follows top to bottom approach
|
It follows bottom up approach
|
It cannot hide the data
|
It can hide the data so more secure
|
It does not have any access specifier
|
It has acces specifier like public,private,protected
|
It is based on function only
|
It has various featured like overloading, encapsulation, abstraction, inheritance, message passing
|
Structure
vs Class
Structure
|
Class
|
struct keyword is used to create structure
|
class keyword is used to create structure
|
Default access is public
|
Default access is private
|
Structure is group of data members
|
Class contains data members and member functions
|
Structure variable is used to access structure members
|
Object is used to access class members
|
Example:
struct student
{
int no;
char name[20];
}
|
Example:
class student
{
int no;
char name[20];
public:
void getdata();
void putdata();
}
|
|
|