UNIT-5
UNIT-5
Encapsulation also leads to data abstraction or hiding. As using encapsulation also hides the
data. In the above example, the data of any of the section like sales, finance or accounts are
hidden from any other section.
Abstraction Data abstraction is one of the most essential and important features of object-
oriented programming in C++. Abstraction means displaying only essential information and
hiding the details. Data abstraction refers to providing only essential information about the
data to the outside world, hiding the background details or implementation
Polymorphism The word polymorphism means having many forms. In simple words, we can
define polymorphism as the ability of a message to be displayed in more than one form.
A person at the same time can have different characteristic. Like a man at the same time is a
father, a husband, an employee. So the same person posses different behaviour in different
situations. This is called polymorphism.
An operation may exhibit different behaviours in different instances. The behaviour depends
upon the types of data used in the operation.
C++ supports operator overloading and function overloading.
Operator Overloading: The process of making an operator to exhibit different behaviours
in different instances is known as operator overloading.
Function Overloading: Function overloading is using a single function name to perform
different types of tasks.
Polymorphism is extensively used in implementing inheritance
Inheritance The capability of a class to derive properties and characteristics from another
class is called Inheritance. Inheritance is one of the most important features of Object-
Oriented Programming.
Sub Class: The class that inherits properties from another class is called Sub class or
Derived Class.
Super Class:The class whose properties are inherited by sub class is called Base Class or
Super class.
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create
a new class and there is already a class that includes some of the code that we want, we
can derive our new class from the existing class. By doing this, we are reusing the fields
and methods of the existing class.
Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.
Dynamic Binding: In dynamic binding, the code to be executed in response to function call is
decided at runtime. C++ has virtual functions to support this.
Message Passing: Objects communicate with one another by sending and receiving
information to each other. A message for an object is a request for execution of a procedure
and therefore will invoke a function in the receiving object that generates the desired results.
Message passing involves specifying the name of the object, the name of the function and the
information to be sent.
Features of C++
C++ is object oriented programming language and it is a very simple and easy language, It is the
enhanced form of C programming language. this language have following features and here we
discuss some important features of C++.
Important Features of C++
Simple
Every C++ program can be written in simple English language so that it is very easy to understand and
developed by programmer.
Platform dependent
A language is said to be platform dependent whenever the program is execute in the same operating
system where that was developed and compiled but not run and execute on other operating system. C++
is platform dependent language.
Portability:It is the concept of carrying the instruction from one system to another system. In C++
Language .cpp file contain source code, we can edit also this code. .exe file contain application, only we
can execute this file. When we write and compile any C++ program on window operating system that
program easily run on other window based system.
When we can copy .exe file to any other computer which contain window operating system then it
works properly, because the native code of application an operating system is same.
Powerful:C++ is a very powerful programming language, it have a wide verity of data types, functions,
control statements, decision making statements, etc.
Object oriented Programming language
This main advantage of C++ is, it is object oriented programming language. It follow concept of oops
like polymorphism, inheritance, encapsulation, abstraction.
Case sensitive
C++ is a case sensitive programming language. In C++ programming 'break and BREAK' both are
different.
If any language treats lower case latter separately and upper case latter separately than they can be
called as case sensitive programming language [Example c, c++, java, .net are sensitive programming
languages.] other wise it is called as case insensitive programming language [Example HTML, SQL
is case insensitive programming languages].
Compiler based
C++ is a compiler based programming language that means without compilation no C++ program can
be executed. First we need compiler to compile our program and then execute.
C++ is a strongly tight syntax based programming language. If any language follow rules and
regulation very strictly known as strongly tight syntax based language. Example C, C++, Java, .net
etc. If any language not follow rules and regulation very strictly known as loosely tight syntax based
language.
Example HTML.
Pointers is a variable which hold the address of another variable, pointer directly direct access to
memory address of any variable due to this performance of application is improve. In C++ language
also concept of pointer are available.
Applications of C++
Mainly C++ Language is used for Develop Desktop application and system software. Some
application of C++ language are given below.
For Develop Graphical related application like computer and mobile games.
To evaluate any kind of mathematical equation use C++ language.
C++ Language are also used for design OS. Like window xp.
Google also use C++ for Indexing
Few parts of apple OS X are written in C++ programming language.
Internet browser Firefox are written in C++ programming language
All major applications of adobe systems are developed in C++ programming language. Like
Photoshop, ImageReady, Illustrator and Adobe Premier.
Some of the Google applications are also written in C++, including Google file system and Google
Chromium.
C++ are used for design database like MySQL.
Difference Between C and C++
C++ is the extension of C language, in C++ you not only use new feature but also use C features. The
main difference between C and C++ is,C is the function or procedure oriented programming language
and C++ is the object oriented programming language.
C C++
In this programming, programs are divided In this programming, programs are divided
into modules and functions. into classes and functions.
C uses scanf() and printf() function for C++ uses cin>> and cout<< for standard
standard input and output. input and output.
Features like function overloading and C++ supports function overloading and
operator overloading is not present. operator overloading.
The following table explains how the object-oriented approach differs from the
traditional structured approach –
Program is divided into number of submodules or Program is organized by having number of classes
functions. and objects.
Structured design programming usually left until end Object oriented design programming done
phases. concurrently with other phases.
Structured Design is more suitable for offshoring. It is suitable for in-house development.
It shows clear transition from design to Not so clear transition from design to
implementation. implementation.
It is suitable for real time system, embedded system It is suitable for most business applications, game
and projects where objects are not the most useful development projects, which are expected to
level of abstraction. customize or extended.
DFD & E-R diagram model the data. Class diagram, sequence diagram, state chart
diagram, and use cases all contribute.
In this, projects can be managed easily due to In this approach, projects can be difficult to
clearly identifiable phases. manage due to uncertain transitions between
phase.
class class_name
{
data members;
user defined method;
{
..........
..........
}
};
returntype main() --> main method
{
.........
.........
}
Include section
# include is a pre-processor directive can be used to include all the predefined method of given header
files into current C program before compilation.
Syntax
#include<headerfile.h>
CLASS
Class is a blue print which is containing only list of variables and method.
C++ library is collection of header files, header files is a container which is collection of related
predefined method.
{
.......
.......
}
In the above syntax method name can be any user defined name, return type represents which type of
value it can return to its calling method.
Syntax
methodName(); // calling method
Main() method
This is starting executable block of any program (it is always executed by processor and OS ). One C+
+ program can have maximum one main() the entire statements of given program can be executed
through main(). Without main() method no C++ program will be executed.
Syntax
If return type is returntype main()
......
.....
}
void that method can not return any value to the operating system. So that void can be treated as no
return type.
Example
Output
#include<iostream.h>
#include<conio.h>
void main()
{
cout<<("Hello main";
}
Hello main
IO statements in C++
IO represents input output statements, and input statement can be used to read the input value from the
standard input device (keyboard), output statement can be used to display the output in standard output
device (Monitor) respectively. In C++ language IO statement can be achieve by using cout<< and
>>cin.