SlideShare a Scribd company logo
1 of 27
Download to read offline
OOPS Concept in C++ programming Language 1
OOPS Concept in C++ Programming Language
Farouq Umar Idris
Introduction to Programming Logic (CIS142)
30/09/2013
Prof. R.K Sharma
OOPS Concept in C++ programming Language 2
ABSTRACT
OOPS concepts (object, class, encapsulation, abstraction, polymorphism and inheritance) have
tremendous programming consequences for programmers using structure languages. This project
shows how important oops concepts are in C++ and what the major difference between C
programming and C++ is. More importantly, it explains where and how to use the concepts (OOPS
concepts) by giving few self-explanatory examples. The entire project is solely based on the use of
OOPS concept in C++ and the difference between C++ and C programming.
OOPS Concept in C++ programming Language 3
Table of Contents
Acknowledgments......................................................................................................................4
Scope of project .........................................................................................................................4
Chapter 1: Introduction..............................................................................................................5
Objectives.............................................................................Error! Bookmark not defined.
Definition ...............................................................................................................................5
Difference between C Programming and C++ Based On Oops Concepts.............................6
CHAPTER 2: OPPS COMPONENTS.............................................Error! Bookmark not defined.
Object .....................................................................................................................................7
Class .....................................................................................................................................10
Example of class and object.................................................................................................11
Encapsulation .......................................................................................................................12
Data abstraction....................................................................................................................15
Difference between Encapsulation and Abstraction in Oops...............................................16
Conclusion ...............................................................................................................................17
OOPS Concept in C++ programming Language 4
ACKNOWLEDGMENTS
As a work group that we use to do in the end of a quarter, we can’t finish our work or write
our final project without expressing our great gratitude to MAII Stratford-university, that
throughout its managerial staff, by the work they are doing for education. Especially we give
also thanks to Professor R.K Sharma who led us during the course of introduction to
Programming and we come to end by giving also thanks to the entire group Member
Muhunga David Eleca, Farouq Umar Idris and Faso Mushigo Heritier.
OOPS Concept in C++ programming Language 5
1.0 INTRODUCTION
Definition
C programming is a general-purpose programming language developed between 1969 and
1973. Like most imperative languages in the ALGOL tradition, C has facilities for structured
programming and allows lexical variable scope and recursion, while a static type system
prevents many unintended operations. Its design provides constructs that map efficiently to
typical machine instructions, and therefore it has found lasting use in applications that had
formerly been coded in assembly language, most notably system software like the Unix
computer operating system.
C++ is a programming language that is general purpose, statically typed, free-form, multi-
paradigm and compiled. It is regarded as an intermediate-level language, as it comprises both
high-level and low-level language features. It was developed in 1979s and was originally
named C with Classes, adding object oriented features, such as classes, and other
enhancements to the C programming language.
OOPS Concept in C++ programming Language 6
DIFFERENCE BETWEEN C PROGRAMMING AND C++ BASED ON OOPS
CONCEPTS
First off, C++ is a non-procedural language but C programming is a totally procedural
language that doesn’t use the concepts of virtual functions in its programs. Polymorphism and
overloading concepts are also not applicable in C programming language but in C++
programming, virtual functions, polymorphism as well as operator overload are used. The
main difference between C programming and C++ is the concepts of OOPs that are used in
C++ and not in C programming.
OOPS Concept in C++ programming Language 7
2.0 OPPS CONCEPTS
2.1 Object
In fact, we are surrounded by objects. In fact, everything we know (almost) can be
considered as an object. The idea of object-oriented programming is handled in its source
code elements that are called "objects."
Imagine you want to create a complex application with many variables and functions that can
be called between them. At first view, it'll look like an experience of a scientist in which we
can’t understand anything as showed in the image below.
Sure you have created a set of code that is working but imagine that you want to publish it on
internet for everyone who wants to use it without to code again, they must be expert for
understanding directly what you have done, what function to call first, what value to send to
each function and so one. To discover all these things will take surly time, so that object
OOPS Concept in C++ programming Language 8
oriented programming became important, that is to say, all the staff represented by functions
and variables in our case will be made in a kind of cube; and this cube represent an object for
us. Let us illustrate by the image bellow.
Here, part of the cube (that represents an object) was deliberately set transparency to show
you that our chemical flasks (That represent functions and variables of our complex
application) are located inside the cube. But in reality, the cube is completely opaque; you
can’t see anything inside like represented in the next image.
OOPS Concept in C++ programming Language 9
Clearly: object-oriented programming so is to create the source code (possibly complex), but
that is masked by placing it inside a cube (representing an object) through which we see
nothing. For the programmer who will use it, he or she will work with a much simpler object
than before: he or she will just have to press buttons and to use it do not need a degree in
chemistry.
Briefly, we can define an object as a collection of functions and variables that has a name.
OOPS Concept in C++ programming Language 10
2.2 CLASS
Class is like a plan that describe object. We can compare it for example to a plan to build a
house.
The object is an instance of the class, that is to say, a concrete implementation of the plan. In
the above example, the object is the house. You can create several houses based on a
construction plan. We can therefore create multiple objects from a class.
OOPS Concept in C++ programming Language 11
Example of class and object
#include <iostream.h>
#include <conio.h>
Class Personage // creation of a class
{
int main()
{
Personnage david, goliath;
//Creation of 2 objets : david et goliath
goliath.attack(david); //goliath attack david
david.takePotionoflife(20); //david will take 20 of life in drinking a potion
goliath.attack(david); //goliath attack again david
david.attack(goliath); //david will do same
return 0;
}
}
OOPS Concept in C++ programming Language 12
2.3 ENCAPSULATION
Encapsulation can be defined as a method in which data and function are combined inside a
class. This process hides data and also protects it from being accessed from outside world or
unauthorised user. To access it, the user has to go through the functions within the class.
Encapsulation is a concept of object oriented programming which binds data and functions
together by manipulating the data and ends up keeping both the data and functions safe from
the outside world. With data encapsulation, data hiding came into existence. C++ generally
supports all properties of encapsulation and hiding data by the creation of a user defined
types which are referred to as classes. All items in C++ by default are private.
class Box
{
public:
doublegetVolume(void)
{
return length * breadth * height;
}
private:
double length; // this is the Length
double breadth; // this is the Breadth
double height; //and this, the Height
};
OOPS Concept in C++ programming Language 13
This means that access is restricted to only members of the class Box not to any other part of
a programme but just the class Box. By doing this, encapsulation is achieved. In order to
make them accessible by other members, we need to declare them public.
Example:
In C++ program where a class with public and private members are implemented are example
of example of data encapsulation and data abstraction.
#include <iostream.h>
class Adder{
public:
//this side of the programme is accessed by all
Adder(int x = 0)
{
total = x;
}
// this interface is all accessible by outside world
voidaddNum(int no)
{
total += no;
}
intgetTotal()
{
return total;
};
private:
// from here, data are hidden from outside world
OOPS Concept in C++ programming Language 14
int total;
};
int main( )
{
Adder y;
y.addNum(10);
y.addNum(20);
y.addNum(30);
cout<< "Total " <<y.getTotal() <<endl;
return 0;
}
OOPS Concept in C++ programming Language 15
2.4 DATA ABSTRACTION
Data abstraction can be considered as the process of showing only the essential part of a
program to the outside world and hiding the details. It is a process of representing only the
needed information within a program and leaving the details out. Data abstraction can be
considered also as the process or a technique used in separation of interface and
implementation.
For instance, in our television set that we use almost every day. We know how we can turn it
on and off, adjust the volume of the speaker and other external components of the television
set. But we have no idea how things inside the TV set work. How signals are sent and
received from where they are sent and how it modulates the signals. All this are not known by
us.
By this, it is seen that a television set is meant to separate its external interface from internal
implementation and we can do what we want with only the external part of it like change
channel and increase or decrease volume etc. This is a typical example of abstraction.
In terms of C++, classes are used to provide desired level of data abstraction. They provide
great level of public methods for the outside world or user to play with as well as
manipulating the object data and functionality of the object that is stating without knowing
how the class was implemented.
OOPS Concept in C++ programming Language 16
DIFFERENCE BETWEEN ENCAPSULATION AND ABSTRACTION IN OOPS
The two are a great deal in object oriented programming concepts and at some point are
interrelated.
1. Encapsulation simply means to hide something like in a capsule or something of that
nature. Therefore it is more like wrapping or simply hiding methods and properties.
Programmers use encapsulation in hiding data and codes within a single unit for the
purpose of protecting the data from outside world. Example of encapsulation is classes
while abstraction is the process of showing only what needs to be shown and hiding
details to the user. Abstraction as the name implies means abstract form of a thing. The
uses of abstraction arise in programming when we need to create an abstract class where
the abstract class represents properties of a class and methods.
2. Encapsulation is done by the use of protected and private access modifiers while
abstraction is done using abstract class and interface.
3. Integrity are enforced in OOPs by the use of encapsulation (i.e. making sure appropriate
use of data is done and in an appropriate manner), it is done by preventing programmers
access to data in an unintended manner.
4. Differentiation by example
Encapsulation
Class Encapsulation
{
Private float division;
Public float division
{
get { return division; }
OOPS Concept in C++ programming Language 17
set {division = value;}
}
}
Abstraction
abstract class Abstraction
{
public abstract void do Abstraction();
}
public class AbstractionImpl: Abstraction
{
public void doAbstraction()
{
// its Implemented it
}
}
OOPS Concept in C++ programming Language 18
2.5 INHERITANCE
Inheritance is one of main techniques used in OOOPS concept, that an Object gain the
proprieties of another without resetting to create a well-defined categories or class. This
technique also supports the hierarchical classification in which each object would not need to
be redefined by all its characteristics explicitly. It prevents the programmer's unnecessary
work and this is the concept of inheritance that does this job. Heritage gives us the
opportunity to object to inherit only the qualities that make it unique in its class. Generally it
can inherit all the attributes of its parent.
As we know there is:
1. Public Inheritance:
Is when a class is deriving from a public base class, the public members of the base class will
become the public members of the derived class and protected members of the base class
become protected members of the derived class. A base class's private members are never
accessible directly from a derived class, but can be accessed through calls to the public
and protected members of the base class.
2. Protected Inheritance:
Is when a deriving from a protected base class, public and protected members of the base
class become protected members of the derived class.
3. Private Inheritance:
Is when we deriving from a private base class, the public and the protected members of the
base class become private members of the derived class.
OOPS Concept in C++ programming Language 19
An example for better understanding.
Let specify that a class derives from another one, the class you create gain all the features of
the base class. If the derived class has some extra features but is otherwise the same as the
base class, this is a good oncoming.
access public protected private
Same class yes yes yes
Derived
classes
yes yes no
Outside classes yes no no
• • • •
OOPS Concept in C++ programming Language 20
#include <iostream>
// Base class
class Shape
{
public:
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape
{
OOPS Concept in C++ programming Language 21
public:
int getArea()
{
return (width * height);
}
};
int main(void)
{
Rectangle Rect;
Rect. setWidth(5);
Rect. setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}
OOPS Concept in C++ programming Language 22
2.6 POLYMORPHISM
In 1967 Polymorphism was identified by Christopher Strachey then developed by Hindley
and Milner. The important thing is not the understanding of it implementation but how this
concept works. C++ programming language provide us two manners of retrieving the objects
and expression when the program is in the running process. Those two ways are Run time
and Compile time. The interesting fundamental idea in polymorphism is at the compile time,
the compiler doesn’t know which function to call before. But it’s done at time of running
(Run time).by other way the run time is called as late binding.
Example where a base class has been derived by other two classes:
#include <iostream>
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
OOPS Concept in C++ programming Language 23
cout << "Parent class area :" <<endl;
return 0;
}
};
class Rectangle: public Shape{
public:
Rectangle( int a=0, int b=0)
{
Shape(a, b);
}
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};
class Triangle: public Shape{
public:
Triangle( int a=0, int b=0)
{
OOPS Concept in C++ programming Language 24
Shape(a, b);
}
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height / 2);
}
};
// Main function for the program
int main( )
{
Shape *shape;
Rectangle rec(10,7);
Triangle tri(10,5);
// store the address of Rectangle
shape = &rec;
// call rectangle area.
shape->area();
// store the address of Triangle
OOPS Concept in C++ programming Language 25
shape = &tri;
// call triangle area.
shape->area();
return 0;
}
OOPS Concept in C++ programming Language 26
3.0 CONCLUSION
OOPS is undoubtedly one of the most complicated programming techniques to explain. In
fact, it's a whole new way to see the programming rather than ‘technical’. Before
understanding OOPS, you must first understand what programming is.
At this time, the basic definition of the programming was as follows: a sequence of logical
instructions followed by the computer. In languages Object Oriented programming, the
emphasis is on data, or 'objects' used and how the programmer manipulates it. Actually with
OPPS concept, the program is now a solution to any problem that may be encountered, but
whatever it is developed in relation to the objects that define your problem and using the
functions associated with these objects.
OOPS Concept in C++ programming Language 27
Reference
1. Mark Allen Weiss, 2006, Data structures and algorithm analysis in C++ 3rd
edition
2. Henry C. Lucas jr. Information Technology for Management 7th
Edition
3. www.tutorialspot.edu
4. www.cplusplus.com

More Related Content

What's hot

Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Assembler design options
Assembler design optionsAssembler design options
Assembler design optionsMohd Arif
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activityDhruv Sabalpara
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence GrammarHarisonFekadu
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Daniyal Mughal
 

What's hot (20)

Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Assembler design options
Assembler design optionsAssembler design options
Assembler design options
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Assembler
AssemblerAssembler
Assembler
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence Grammar
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 

Similar to Oops concepts in c++ documentation

c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptxPadmaN24
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]Rome468
 
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERC++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERgroversimrans
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideSharebiyu
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++Manoj Kumar
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it securityCESAR A. RUIZ C
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentalsChaithraCSHirematt
 

Similar to Oops concepts in c++ documentation (20)

c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Oops index
Oops indexOops index
Oops index
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
C vs c++
C vs c++C vs c++
C vs c++
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
M.c.a (sem iii) paper - i - object oriented programming
M.c.a (sem   iii) paper - i - object oriented programmingM.c.a (sem   iii) paper - i - object oriented programming
M.c.a (sem iii) paper - i - object oriented programming
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
C++ & VISUAL C++
C++ & VISUAL C++ C++ & VISUAL C++
C++ & VISUAL C++
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERC++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare
 
C vs c++
C vs c++C vs c++
C vs c++
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it security
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentals
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
 
Unit i
Unit iUnit i
Unit i
 

More from farouq umar

Internet Marketing Summary chapter 1-3
Internet Marketing Summary chapter 1-3Internet Marketing Summary chapter 1-3
Internet Marketing Summary chapter 1-3farouq umar
 
Aristotelian branches of philosophy
Aristotelian branches of philosophyAristotelian branches of philosophy
Aristotelian branches of philosophyfarouq umar
 
Erp implementation
Erp implementationErp implementation
Erp implementationfarouq umar
 
Configuration testing
Configuration testingConfiguration testing
Configuration testingfarouq umar
 
Library management
Library managementLibrary management
Library managementfarouq umar
 
Online examination
Online examinationOnline examination
Online examinationfarouq umar
 
Metro station documentation
Metro station documentationMetro station documentation
Metro station documentationfarouq umar
 
Business plan USING POPULATION PYRAMID
Business plan USING POPULATION PYRAMIDBusiness plan USING POPULATION PYRAMID
Business plan USING POPULATION PYRAMIDfarouq umar
 
ARISTOTLE PHILOSOPHY
ARISTOTLE PHILOSOPHYARISTOTLE PHILOSOPHY
ARISTOTLE PHILOSOPHYfarouq umar
 
ERP IMPLEMENTATION
ERP IMPLEMENTATION ERP IMPLEMENTATION
ERP IMPLEMENTATION farouq umar
 
Specialisterne CASE STUDY
Specialisterne CASE STUDYSpecialisterne CASE STUDY
Specialisterne CASE STUDYfarouq umar
 
HARLEY DAVIDSON CASE STUDY SOLUTION
HARLEY DAVIDSON CASE STUDY SOLUTIONHARLEY DAVIDSON CASE STUDY SOLUTION
HARLEY DAVIDSON CASE STUDY SOLUTIONfarouq umar
 
Relational data models in enterprise-level information system.
Relational data models in enterprise-level information system. Relational data models in enterprise-level information system.
Relational data models in enterprise-level information system. farouq umar
 
Zhejiang corporation of china telecom case study
Zhejiang corporation of china telecom case studyZhejiang corporation of china telecom case study
Zhejiang corporation of china telecom case studyfarouq umar
 
business communication
business communicationbusiness communication
business communicationfarouq umar
 
Construction company business plan
Construction company business planConstruction company business plan
Construction company business planfarouq umar
 
library management system in SQL
library management system in SQLlibrary management system in SQL
library management system in SQLfarouq umar
 

More from farouq umar (19)

Internet Marketing Summary chapter 1-3
Internet Marketing Summary chapter 1-3Internet Marketing Summary chapter 1-3
Internet Marketing Summary chapter 1-3
 
Aristotelian branches of philosophy
Aristotelian branches of philosophyAristotelian branches of philosophy
Aristotelian branches of philosophy
 
Honor killing
Honor killingHonor killing
Honor killing
 
Erp implementation
Erp implementationErp implementation
Erp implementation
 
Configuration testing
Configuration testingConfiguration testing
Configuration testing
 
Srs for library
Srs for librarySrs for library
Srs for library
 
Library management
Library managementLibrary management
Library management
 
Online examination
Online examinationOnline examination
Online examination
 
Metro station documentation
Metro station documentationMetro station documentation
Metro station documentation
 
Business plan USING POPULATION PYRAMID
Business plan USING POPULATION PYRAMIDBusiness plan USING POPULATION PYRAMID
Business plan USING POPULATION PYRAMID
 
ARISTOTLE PHILOSOPHY
ARISTOTLE PHILOSOPHYARISTOTLE PHILOSOPHY
ARISTOTLE PHILOSOPHY
 
ERP IMPLEMENTATION
ERP IMPLEMENTATION ERP IMPLEMENTATION
ERP IMPLEMENTATION
 
Specialisterne CASE STUDY
Specialisterne CASE STUDYSpecialisterne CASE STUDY
Specialisterne CASE STUDY
 
HARLEY DAVIDSON CASE STUDY SOLUTION
HARLEY DAVIDSON CASE STUDY SOLUTIONHARLEY DAVIDSON CASE STUDY SOLUTION
HARLEY DAVIDSON CASE STUDY SOLUTION
 
Relational data models in enterprise-level information system.
Relational data models in enterprise-level information system. Relational data models in enterprise-level information system.
Relational data models in enterprise-level information system.
 
Zhejiang corporation of china telecom case study
Zhejiang corporation of china telecom case studyZhejiang corporation of china telecom case study
Zhejiang corporation of china telecom case study
 
business communication
business communicationbusiness communication
business communication
 
Construction company business plan
Construction company business planConstruction company business plan
Construction company business plan
 
library management system in SQL
library management system in SQLlibrary management system in SQL
library management system in SQL
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 

Recently uploaded (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 

Oops concepts in c++ documentation

  • 1. OOPS Concept in C++ programming Language 1 OOPS Concept in C++ Programming Language Farouq Umar Idris Introduction to Programming Logic (CIS142) 30/09/2013 Prof. R.K Sharma
  • 2. OOPS Concept in C++ programming Language 2 ABSTRACT OOPS concepts (object, class, encapsulation, abstraction, polymorphism and inheritance) have tremendous programming consequences for programmers using structure languages. This project shows how important oops concepts are in C++ and what the major difference between C programming and C++ is. More importantly, it explains where and how to use the concepts (OOPS concepts) by giving few self-explanatory examples. The entire project is solely based on the use of OOPS concept in C++ and the difference between C++ and C programming.
  • 3. OOPS Concept in C++ programming Language 3 Table of Contents Acknowledgments......................................................................................................................4 Scope of project .........................................................................................................................4 Chapter 1: Introduction..............................................................................................................5 Objectives.............................................................................Error! Bookmark not defined. Definition ...............................................................................................................................5 Difference between C Programming and C++ Based On Oops Concepts.............................6 CHAPTER 2: OPPS COMPONENTS.............................................Error! Bookmark not defined. Object .....................................................................................................................................7 Class .....................................................................................................................................10 Example of class and object.................................................................................................11 Encapsulation .......................................................................................................................12 Data abstraction....................................................................................................................15 Difference between Encapsulation and Abstraction in Oops...............................................16 Conclusion ...............................................................................................................................17
  • 4. OOPS Concept in C++ programming Language 4 ACKNOWLEDGMENTS As a work group that we use to do in the end of a quarter, we can’t finish our work or write our final project without expressing our great gratitude to MAII Stratford-university, that throughout its managerial staff, by the work they are doing for education. Especially we give also thanks to Professor R.K Sharma who led us during the course of introduction to Programming and we come to end by giving also thanks to the entire group Member Muhunga David Eleca, Farouq Umar Idris and Faso Mushigo Heritier.
  • 5. OOPS Concept in C++ programming Language 5 1.0 INTRODUCTION Definition C programming is a general-purpose programming language developed between 1969 and 1973. Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. Its design provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system. C++ is a programming language that is general purpose, statically typed, free-form, multi- paradigm and compiled. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features. It was developed in 1979s and was originally named C with Classes, adding object oriented features, such as classes, and other enhancements to the C programming language.
  • 6. OOPS Concept in C++ programming Language 6 DIFFERENCE BETWEEN C PROGRAMMING AND C++ BASED ON OOPS CONCEPTS First off, C++ is a non-procedural language but C programming is a totally procedural language that doesn’t use the concepts of virtual functions in its programs. Polymorphism and overloading concepts are also not applicable in C programming language but in C++ programming, virtual functions, polymorphism as well as operator overload are used. The main difference between C programming and C++ is the concepts of OOPs that are used in C++ and not in C programming.
  • 7. OOPS Concept in C++ programming Language 7 2.0 OPPS CONCEPTS 2.1 Object In fact, we are surrounded by objects. In fact, everything we know (almost) can be considered as an object. The idea of object-oriented programming is handled in its source code elements that are called "objects." Imagine you want to create a complex application with many variables and functions that can be called between them. At first view, it'll look like an experience of a scientist in which we can’t understand anything as showed in the image below. Sure you have created a set of code that is working but imagine that you want to publish it on internet for everyone who wants to use it without to code again, they must be expert for understanding directly what you have done, what function to call first, what value to send to each function and so one. To discover all these things will take surly time, so that object
  • 8. OOPS Concept in C++ programming Language 8 oriented programming became important, that is to say, all the staff represented by functions and variables in our case will be made in a kind of cube; and this cube represent an object for us. Let us illustrate by the image bellow. Here, part of the cube (that represents an object) was deliberately set transparency to show you that our chemical flasks (That represent functions and variables of our complex application) are located inside the cube. But in reality, the cube is completely opaque; you can’t see anything inside like represented in the next image.
  • 9. OOPS Concept in C++ programming Language 9 Clearly: object-oriented programming so is to create the source code (possibly complex), but that is masked by placing it inside a cube (representing an object) through which we see nothing. For the programmer who will use it, he or she will work with a much simpler object than before: he or she will just have to press buttons and to use it do not need a degree in chemistry. Briefly, we can define an object as a collection of functions and variables that has a name.
  • 10. OOPS Concept in C++ programming Language 10 2.2 CLASS Class is like a plan that describe object. We can compare it for example to a plan to build a house. The object is an instance of the class, that is to say, a concrete implementation of the plan. In the above example, the object is the house. You can create several houses based on a construction plan. We can therefore create multiple objects from a class.
  • 11. OOPS Concept in C++ programming Language 11 Example of class and object #include <iostream.h> #include <conio.h> Class Personage // creation of a class { int main() { Personnage david, goliath; //Creation of 2 objets : david et goliath goliath.attack(david); //goliath attack david david.takePotionoflife(20); //david will take 20 of life in drinking a potion goliath.attack(david); //goliath attack again david david.attack(goliath); //david will do same return 0; } }
  • 12. OOPS Concept in C++ programming Language 12 2.3 ENCAPSULATION Encapsulation can be defined as a method in which data and function are combined inside a class. This process hides data and also protects it from being accessed from outside world or unauthorised user. To access it, the user has to go through the functions within the class. Encapsulation is a concept of object oriented programming which binds data and functions together by manipulating the data and ends up keeping both the data and functions safe from the outside world. With data encapsulation, data hiding came into existence. C++ generally supports all properties of encapsulation and hiding data by the creation of a user defined types which are referred to as classes. All items in C++ by default are private. class Box { public: doublegetVolume(void) { return length * breadth * height; } private: double length; // this is the Length double breadth; // this is the Breadth double height; //and this, the Height };
  • 13. OOPS Concept in C++ programming Language 13 This means that access is restricted to only members of the class Box not to any other part of a programme but just the class Box. By doing this, encapsulation is achieved. In order to make them accessible by other members, we need to declare them public. Example: In C++ program where a class with public and private members are implemented are example of example of data encapsulation and data abstraction. #include <iostream.h> class Adder{ public: //this side of the programme is accessed by all Adder(int x = 0) { total = x; } // this interface is all accessible by outside world voidaddNum(int no) { total += no; } intgetTotal() { return total; }; private: // from here, data are hidden from outside world
  • 14. OOPS Concept in C++ programming Language 14 int total; }; int main( ) { Adder y; y.addNum(10); y.addNum(20); y.addNum(30); cout<< "Total " <<y.getTotal() <<endl; return 0; }
  • 15. OOPS Concept in C++ programming Language 15 2.4 DATA ABSTRACTION Data abstraction can be considered as the process of showing only the essential part of a program to the outside world and hiding the details. It is a process of representing only the needed information within a program and leaving the details out. Data abstraction can be considered also as the process or a technique used in separation of interface and implementation. For instance, in our television set that we use almost every day. We know how we can turn it on and off, adjust the volume of the speaker and other external components of the television set. But we have no idea how things inside the TV set work. How signals are sent and received from where they are sent and how it modulates the signals. All this are not known by us. By this, it is seen that a television set is meant to separate its external interface from internal implementation and we can do what we want with only the external part of it like change channel and increase or decrease volume etc. This is a typical example of abstraction. In terms of C++, classes are used to provide desired level of data abstraction. They provide great level of public methods for the outside world or user to play with as well as manipulating the object data and functionality of the object that is stating without knowing how the class was implemented.
  • 16. OOPS Concept in C++ programming Language 16 DIFFERENCE BETWEEN ENCAPSULATION AND ABSTRACTION IN OOPS The two are a great deal in object oriented programming concepts and at some point are interrelated. 1. Encapsulation simply means to hide something like in a capsule or something of that nature. Therefore it is more like wrapping or simply hiding methods and properties. Programmers use encapsulation in hiding data and codes within a single unit for the purpose of protecting the data from outside world. Example of encapsulation is classes while abstraction is the process of showing only what needs to be shown and hiding details to the user. Abstraction as the name implies means abstract form of a thing. The uses of abstraction arise in programming when we need to create an abstract class where the abstract class represents properties of a class and methods. 2. Encapsulation is done by the use of protected and private access modifiers while abstraction is done using abstract class and interface. 3. Integrity are enforced in OOPs by the use of encapsulation (i.e. making sure appropriate use of data is done and in an appropriate manner), it is done by preventing programmers access to data in an unintended manner. 4. Differentiation by example Encapsulation Class Encapsulation { Private float division; Public float division { get { return division; }
  • 17. OOPS Concept in C++ programming Language 17 set {division = value;} } } Abstraction abstract class Abstraction { public abstract void do Abstraction(); } public class AbstractionImpl: Abstraction { public void doAbstraction() { // its Implemented it } }
  • 18. OOPS Concept in C++ programming Language 18 2.5 INHERITANCE Inheritance is one of main techniques used in OOOPS concept, that an Object gain the proprieties of another without resetting to create a well-defined categories or class. This technique also supports the hierarchical classification in which each object would not need to be redefined by all its characteristics explicitly. It prevents the programmer's unnecessary work and this is the concept of inheritance that does this job. Heritage gives us the opportunity to object to inherit only the qualities that make it unique in its class. Generally it can inherit all the attributes of its parent. As we know there is: 1. Public Inheritance: Is when a class is deriving from a public base class, the public members of the base class will become the public members of the derived class and protected members of the base class become protected members of the derived class. A base class's private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class. 2. Protected Inheritance: Is when a deriving from a protected base class, public and protected members of the base class become protected members of the derived class. 3. Private Inheritance: Is when we deriving from a private base class, the public and the protected members of the base class become private members of the derived class.
  • 19. OOPS Concept in C++ programming Language 19 An example for better understanding. Let specify that a class derives from another one, the class you create gain all the features of the base class. If the derived class has some extra features but is otherwise the same as the base class, this is a good oncoming. access public protected private Same class yes yes yes Derived classes yes yes no Outside classes yes no no • • • •
  • 20. OOPS Concept in C++ programming Language 20 #include <iostream> // Base class class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; } protected: int width; int height; }; // Derived class class Rectangle: public Shape {
  • 21. OOPS Concept in C++ programming Language 21 public: int getArea() { return (width * height); } }; int main(void) { Rectangle Rect; Rect. setWidth(5); Rect. setHeight(7); // Print the area of the object. cout << "Total area: " << Rect.getArea() << endl; return 0; }
  • 22. OOPS Concept in C++ programming Language 22 2.6 POLYMORPHISM In 1967 Polymorphism was identified by Christopher Strachey then developed by Hindley and Milner. The important thing is not the understanding of it implementation but how this concept works. C++ programming language provide us two manners of retrieving the objects and expression when the program is in the running process. Those two ways are Run time and Compile time. The interesting fundamental idea in polymorphism is at the compile time, the compiler doesn’t know which function to call before. But it’s done at time of running (Run time).by other way the run time is called as late binding. Example where a base class has been derived by other two classes: #include <iostream> class Shape { protected: int width, height; public: Shape( int a=0, int b=0) { width = a; height = b; } int area() {
  • 23. OOPS Concept in C++ programming Language 23 cout << "Parent class area :" <<endl; return 0; } }; class Rectangle: public Shape{ public: Rectangle( int a=0, int b=0) { Shape(a, b); } int area () { cout << "Rectangle class area :" <<endl; return (width * height); } }; class Triangle: public Shape{ public: Triangle( int a=0, int b=0) {
  • 24. OOPS Concept in C++ programming Language 24 Shape(a, b); } int area () { cout << "Rectangle class area :" <<endl; return (width * height / 2); } }; // Main function for the program int main( ) { Shape *shape; Rectangle rec(10,7); Triangle tri(10,5); // store the address of Rectangle shape = &rec; // call rectangle area. shape->area(); // store the address of Triangle
  • 25. OOPS Concept in C++ programming Language 25 shape = &tri; // call triangle area. shape->area(); return 0; }
  • 26. OOPS Concept in C++ programming Language 26 3.0 CONCLUSION OOPS is undoubtedly one of the most complicated programming techniques to explain. In fact, it's a whole new way to see the programming rather than ‘technical’. Before understanding OOPS, you must first understand what programming is. At this time, the basic definition of the programming was as follows: a sequence of logical instructions followed by the computer. In languages Object Oriented programming, the emphasis is on data, or 'objects' used and how the programmer manipulates it. Actually with OPPS concept, the program is now a solution to any problem that may be encountered, but whatever it is developed in relation to the objects that define your problem and using the functions associated with these objects.
  • 27. OOPS Concept in C++ programming Language 27 Reference 1. Mark Allen Weiss, 2006, Data structures and algorithm analysis in C++ 3rd edition 2. Henry C. Lucas jr. Information Technology for Management 7th Edition 3. www.tutorialspot.edu 4. www.cplusplus.com