Professional Documents
Culture Documents
1ST-CHAPTER-C
1ST-CHAPTER-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 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
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.
data
function
data
data
function
function 3
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{
Example
#include <iostream>
Class rectangle{
private:
public:
Len =l;
Br =b;
Void calculatearea(){
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()
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
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)
8
Difference between POP and OOP
sn Procedure oriented programming Object oriented programming
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.
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.
2)block scoping
3)modules
5)object.
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.
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.
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
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 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 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.
14