Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

History of C++

 C++ language has been derived from C programming.


 Originanlly named c with classes in 1979
 Developed by Bjarne stroustrup at bell labs(AT & T)
 He borrowed features from simula,ada,clu languages and added to C
 In 1983 the name of the new language was changed to c with classe to C++
 The increment operator ‘++’ to C indicates the enhancement of C language
 Commercial release of C++ was launched in October 1985.
 All the features of C are supported by C++ also.Thus C is also subset of C++.

Introduction
 C++ is a high level programming language.
 Supports variety of platforms such as windows,mac and various version of UNIX
 It is general purpose,case-sensitive,compiled and free form of programming language that
supports procedural,object oriented and generic programming.
 C++ fully supports object oriented programming with features ,encapsulation,data
hiding,inheritance,polymorphism.

Application of C++
 Game development:IT is use to make game engine,gui based games etc
 Embedded system
 Computer aided design(CAD)
 Object oriented database
 Simulation and modeling
 Hypertext and hypermedia:hypertext and hypermedia is another area where OOP approach is
being used.As it is easy to represent real media objects with the concept of OOPs object it is
easy to use in Hypertext and Hypermedia
 Office automation system:We need various types of systems or software for office
automation.Automation system is just a type of real time system.The embedded systems make
it easy to use OOP automated system.
 Website application,desktop application
 Decision support system ,AI and Expert system.:Decision support system ,AI and Expert systm
also use real time system which are too advanced and complex system.We can use OOP to
design and develop the system to use for decision
 Real time system:A real time system is a system that gives outpur at given instant and its
parameters change every time.A real time system is a dynamic system,means the system that
changes every moment based on input to the system.OOP approach is very useful for real time
system as code changing is very easy in OOP system and its leads to toward dynamic behavior
of OOP codes.

1
Procedure oriented programming(POP)
 High level language such as COBOL,FORTRAN and C is commonly known as procedure oriented
programming (POP)
 The problem is viewed as a sequence of things to be done such as reading ,calculating and
printing.
 Many functions are written to finish the task.

Main function

Function 1 Function 2 Function 3

Function 4 Function 5

Function 8
Function 6 Function 7

Main (){

Function1();

Function2()

;}

Function1(){

Function2(){

2
 In multifunction program many important data items are placed as global so that they may be
accessed by all the functions.
 Each function may have its own local data.

DRAWBACKS

 Global data may be unintentionally changed by a function;


 Procedural coding is very difficult to maintain for larger code.
 Code reusability is difficult.
 It does not model real world problems very well.
 Difficult ot hide information to unauthorized user.

Characteristics of pop
 Emphasis is on doing things (algorithm).
 Large programs are divided into smaller program known as function.
 Most functions share global data
 Function transform data from one form to another.
 Employs top down approach in program design.

Object oriented programming as a new paradigm


 Motivating factor of OOP is some of the flaws encountered in the procedural approach.
 It ties data more closely to the functions that operate and protects it from accidental
modification form outside function.
 The central concept of object oriented programming is object,which is a kind of models
containing data and function.
 OOP allows decomposition of a problem into a number of entities called objects and then builds
data and functions around these objects.

data

function

data
data

function
function 3

Fig:communcation between objects


Characterics of OOP
 Emphasis is on data rather than procedure
 Programs are divided into what are known as objects
 Data is hidden and cannot be accessed by external function.
 New data and functions can be easily added whenever necessary.
 Follows bottom up approach in a program design.
 Functions and data area tied together in a class.the binding of functions with data is known as
encapsulation.
 Objects communicate with each other by sending message and receving message.
 Supports reusability of code.
 Supports polymorphism.(i.e same name can be assigned to different things).

Features of OOP
 CLASS
 OBJECT
 INHERITANCE
 POLYMORPHISM
 ENCAPSULATION
 DATA ABSTRACTION
 MESSAGE PASSING.

Class
 CLASS is a user defined data type which has data members and member function.
 Class is building block that leads to object oriented programming.
 Data members are the data variables and member functions are the functions to manipulate
those variables and together these data members.
 An object is an instance of a class .when a class is defined ,no memory is allocated but when it is
instantiated(an object is created) memory is allocated.

4
Structure of class
Private,public,protected
keyword
publci

properties
Class classname{

Access specifier: attributes


Member variable declaration:

Member function declaration: behaviour


}
methods

Example

#include <iostream>

Using namespace std;

Class rectangle{

private:

float len ,br;

public:

Void getdata(float l,float b)

Len =l;

Br =b;

Void calculatearea(){

Cout<<”the area is “<<(len *br);

5
};

Int main(){

rectangle r1,r2;

r1.getdata(10,20);

r2.getdata(15,10);

r1.calculatearea();

r2.calculatearea();

return 0;

Object
 An object is an class variable or instance of a class.
 Creating object of a class is lke defining a variable of a data type.
 An object doesnot exist until an instance of class has been created.
 When an object is physicall created,space for that object is allocated in primary memory.

Example

Classname o1,o2,o3 ;

Here we have created three class objects namely o1,o2 and o3 using classname.

Inheritance
 Inheritance is the ability of creating new class form existing class with new data and methods.
 The existing class is called base class and newly created class is called derived class.
 Derived class inherits all the features of except private data members.
 It supports code reusability means it can add additional features to an existing class without
modifying it.

6
Class vehicle

Apply brake()

Increase speed()

Class bus Class car

Fig:inheritance

Polymorphism
 The word polymorphism is derived from two greek words poly and morphe.The word poly
means many and morphe means forms.
 Polymorphism means the ability to take more than one form.
 OOP supports polymorphism through function overloading,operator overloading,function
overriding and template.
 An operation may exhibit different behaviours in different instances.The behavior depends on
the data types used in the operation.like ‘+’ operator can be used to add two integer data items
and also to add two objects.

Encapsulation
 Encapsulation is an ability to bind(package)functions and data together in a place and hide( or
prevent) the data from unauthorized use from other parts of the program.Thus function and
data in OOP are always together within an object that provides data hiding.Thus data is hidden
within an object.

Data

function

An object(i.e capsule containing data and functions)

Data abstraction
 Abstraction refers to an act of representing essential features without including background
details or explations.Thus ,data abstraction is a methodology that supports use of compound or
complex object without its detail knowledge.for example a class car would be made up of an
engine,gearbox,steering object and many other components .to build a car class ,one does not
know how the different components of the car work internally ,but only how to interface with
them(i.send message to them,receive message from them).

7
Message passing
Objects can communicate with each others by passing message same as people pass message with each
other.An object can send or receive message/information form /to another object.A message for an
object is a request for execution of a procedure and therefore will invoke function in receiving object
that generates the desired result.The message passing involves name of object,name of
function(message) and information to be send.

Object.functionname(parameters)

For example: student.getmarks(10);

Here,student is object name ,getmarks() is a message and 10 is information.

Following are the basic steps in message passing.

 Creating classes that define objects and its behavior


 Creating objects from class definations.
 Establishing communication among objects.

8
Difference between POP and OOP
sn Procedure oriented programming Object oriented programming

1 It is Structure oriented It is Object oriented..

2 Program is divided into functions. Program is divided into objects.

3 It follows Top-down approach. It follows Bottom-up approach.

Inheritance property is used


4 Inheritance is not allowed.

5 It doesn’t use access specifier. It uses access specifier.

6 No data hiding. Encapsulation is used to hide the data.

7 Example c,fortran,pascal Example c++,java

9
Object oriented programming as a New paradigm
Object oriented programming(OOP) is a programming paradigm that uses ‘objects ‘ and their
interactions to design software’s.An object commonly means a data structure consisting of data fields
and methods that can manipulate those fields.Typically when calling a method form some object,the
object itself should be passed as a parameter to a method.The class of ‘Dog’ defines all possible dogs by
listing the characteristics and behaviours they can have,the object ‘james’ is one particular dog with
particular version of the characteristics.A dog has fur:James has brown fur.

Procedural programming creates a step by step program that guides the application through a sequence
of instruction .Each instruction is executed in order.procedural programming also focuses on the idea
that all algorithms are excuted with functions and data that a programmer has acess to and is able to
change.object oriented programming is much more similar to the way that real world works.it is
analogous to the human brain.Each program is made up of many entities called objects.Objects become
fundamental units and have behaviours or a specific purpose associated with them.Objects cannot
directly access another objects data.Instead a message must be sent requesting data.Just like people
must ask one another for information;we cannot see inside each other’s head .some benefits of OOP
include ability to simulate real world event much more effectively,code is reusable thus less code may
have to be written and programmers are able to reach goals faster.

10
A way of viewing the world
To illustrate some of the major ideas in object oriented programming,let us consider first how we could
make the computer more closely model the techniques employed.

Suppose Ram want to send the flower to his friend shyam for his birthday.Ram lives in a city many miles
away so picking a flower and carry them to shyam’s door by himself is out of question.So sending him
the flowers in an easy way,for that ram goes to a local florist Hari,tells him kinds and no.of flowers he
want to send and gives his friend’s address.Here the agent Hari makes task so simpler by sending data
containing message to shyam.

Computation as simulation
The traditional modal describing the behavior of a computer executing a program is a process-state or
pigeon hole modal.In this view the computer is data manager flowing some pattern of instruction,pulling
values out of various slots(memory address),transforming them in same manner and pushing the result
back into the result back into other slots.

In contrast ,in the object oriented frame world,we never mention memory address,variables
,assignments or any other conventional terms.Instead we speak of objects,messages,responsibilities for
same action.The view of programming as a creating universe is in many ways similar to a style of
computer simulation called discrete event driven simulation(DES).In brief ,in a DES the user creates
computer models of various elements of the simulation,describes how they will interact with one
another,and sets their moving.This is almost identical to the average object oriented programming.In
which the user describes what various entities of the universe for the program are and how they will
interact with one another and finally sets them on motion.

Coping with complexity


In earlier concept,most programs were written in assembly language by a single individual and couldnto
be considered large by todays standards.As program becomes complex,programmers font is difficult to
remember all the information needed to know in order to develop or debug their software.

The introduction of higher level languages such as FORTRAN,COBOL,ALGOL solved difficulties while
simulataneously raising peoples of what computer can do.As a programmer attempted to solve more
complex problems using a computer.Thus teams of programmer working together on major
programming efforts become common place.

11
Non linear behavior of complexity
As programming projects become larger ,an interesting phenomena was absorbed,a task that will take
one programmer two months to perfom couldn’t be prepared by two programmers working in one
month.The region for this nonlinear behavior was complexity.In particular the connections between
software wer complicated and large quantities of information had to be communicated among various
members of the programming team.The unique feature of software system developed using
conventional technique(one that makes them among the most complex systems developed by people) is
their high degree on interconnectedness.Interconnectedness means the dependence of one person of
code to another person.

Abstraction mechanism:
Programmers have had to deal with the problem of complexity for long time.To understand more,fully
the importance of object oriented techniques,we should review the variety of mechanism programmers
have used to control complexity.Among them ,abstraction is one the ability to encapsulate and isolate
design and exaction information.object oriented techniques are not all revolutionary but can be seen as
natural outcome of a long historical progression from procedure,to modules,to abstract data types and
finally to objects.

Types of abstraction mechanism.


1)procedure and function

2)block scoping

3)modules

4)abstract data type

5)object.

1.Procedure and function


Procedure and function are the main two first abstraction mechanism to be widely used in programming
language.They allowed task that were executed repeatedly to be collected in one place and reused
rather than being duplicated several times.

Libraries of procedures and functions provided first hint of information hiding.They permit programmer
to think about operation in high level terms,concentrating on what is being done,not how it is being
implemented.

But they are entirely different mechanism of information hiding.

12
2.Block scoping
Nesting of function (one function is inside another function.)To solve problem assosciated with
procedure and function,the idea of block scoping was introduced which permits functions to be nested
with one another.

This block scoping is also not truly the solution.If a data area is shared by two or more procedure,it must
still be declared in more general scope than procedure.

3.Modules
A module is basically a mechanism that allows a programmer to encapsulate a collection of procedure
and data and supply both import and export statement to control visibility features from outside
module.

Module solved problem of encapsulation.

Parna’s principle for creation and use of modules

a>The developer of a software (s/w) component must provide intended user with all information
needed to make effective use of services provided by component and should provide no other
information

b>The development of a s/w component must be provided with all information necessary to carry out
the given responsibility assigned to component and should provide no other information

4.Abstract data type(ADT)


To solve problem of instantiation ,the problem of what to do your application needed more than one
instance o software abstraction.The key to solving this problem is ADT.An ADT is simply programmer
defined data type that can be manipulated in a manner similar to system provided data types.

5.Object
 ADT with message passing.It has characteristics as:
 Encapsulation->similar to modules
 Instantiation->similar to ADT
 Messages->dynamic binding of procedure names to behavior
 Classes and polymorphism

13
Types of classes
1. Data manager
2. Data source or data sink
3. View or observer class
4. Facilitator or helper clas

Data manager class


We know that object oriented programming largely supports largely in objects and classes.when
designing the class of any items all the data items and member function are to be placed inside the
clas.It is main class which has responsibility to maintain the data or information that may use by another
class.

Data manager class is known as data or state class that supports in software systems development.Data
manager class maintain database and arrange data values which facilitate to easy acess of data base
classe.

Data source or data sink class


A class which supports two way data interchange is known as data source class.Data sourc class accepts
osme data nd processes those data for further used is known as data sink class.this type of class does
not hold data for long period of time but it generates data and supply to other classes.

Data sink means accept data and data source means supply data therefore this type of class can supply
data and accept those supplied data requires further process.For eg a class generates random number
supplied by users range,produce two way generator and acceptor.

Here the first clas that produces random number is fall into data source class and another class which
accepts the data generated by another class fall nto data sinks categories.

View or observer class:


This type of class concerned with displaying information on the output devices such as monitor.To
display information an attractive form may need the extra code,may be complex and frequently
modified therefore,this type of class only handles display behavior of classes.

Facilitator or helper class


This class is helper class of data manager class which facilities the proper maintaining of data ,proper
display of information ,accelerate programming software and hardware too.

14

You might also like