SlideShare a Scribd company logo
Object-Oriented Programming
• Objects can be used effectively to represent
real-world entities
• For instance, an object might represent a
particular employee in a company
• Each employee object handles the processing
and data management related to that
employee
04/27/15 MCA-114 2
Objects
• An object has:
– state - descriptive characteristics
– behaviors - what it can do (or what can be done to it)
• The state of a bank account includes its account number and
its current balance
• The behaviors associated with a bank account include the
ability to make deposits and withdrawals
• Note that the behavior of an object might change its state
04/27/15 MCA-114 3
Classes
• An object is defined by a class
• A class is the blueprint of an object
• Multiple objects can be created from the same class
04/27/15 MCA-114 4
Objects and Classes
04/27/15 MCA-114 5
Bank
Account
A class
(the concept)
John’s Bank Account
Balance: $5,257
An object
(the realization)
Bill’s Bank Account
Balance: $1,245,069
Mary’s Bank Account
Balance: $16,833
Multiple objects
from the same class
Attributes
Contain current state of an object.
• Attributes can be classified as simple or complex.
• Simple attribute can be a primitive type such as
integer, string, etc., which takes on literal values.
• Complex attribute can contain collections and/or
references.
• Reference attribute represents relationship.
• complex object: contains one or more complex
attributes
04/27/15 MCA-114 6
Methods and messages
Method: Defines behavior of an object, as a set of encapsulated functions.
Message: Request from one object to another asking second object to
execute one of its methods.
04/27/15 MCA-114 7
(a)
(b)
(a) Object showing attributes and methods
(b) Example of a method
Classes
Class: Blueprint for defining a set of similar objects.
Objects in a class are called instances.
04/27/15 MCA-114 8
Data Encapsulation and Abstraction
• The wrapping up of data and functions into a single unit is known as
encapsulation. Data encapsulation is the most striking feature of a class.
The data is not accessible to the outside world and only those functions
which are wrapped in the class can access it. These functions provide the
interface between the object’s data and the program. This insulation of the
data form direct access by the program is called data hiding or information
hiding.
• Abstraction refers to the act of representing essential features without
including the background details or explanations. Classes use the concept of
abstraction and are defined as a list of abstract attributes such as size, weight
and cost and functions to operate on these attributes. They encapsulate all
the essential properties of the objects that are to be created. The attributes
are sometimes called data members because they hold information. The
functions that operate on these data are sometimes called methods or
member function. Since the classes use the concept of data abstraction, they
are knows as Abstract Data Types (ADT).
04/27/15 MCA-114 9
Inheritance
• One class can be used to derive another via
inheritance
• Classes can be organized into hierarchies
04/27/15 MCA-114 10
Bank
Account
Account
Charge
Account
Savings
Account
Checking
Account
Inheritance (contd)
Inheritance allows one class of objects to be defined as a special case
of a more general class.
Special cases are subclasses and more general cases are superclasses.
04/27/15 MCA-114 11
Generalization: process of forming a superclass
Specialization: forming a subclass
•Subclass inherits all properties of its superclass and can define its own unique
properties.
•Subclass can redefine inherited methods.
•All instances of subclass are instances of superclass.
•Principle of substitutability: instance of subclass can be used whenever method/construct
expects instance of superclass.
•A KIND OF (AKO): Name for relationship between subclass and superclass
Types of inheritance
04/27/15 MCA-114 12
(a)
(b)
(c)
(a) Single
(b) Multiple
(c) Repeated
(b)
Inheritance (contd)
• Define humanBeing to be a class
– A humanBeing has attributes, such as age, height,
gender
– Assign values to attributes when describing object
• Define Parent to be a subclass of HumanBeing
– A Parent has all attributes of a HumanBeing, plus
attributes of his/her own (name of oldest child,
number of children)
– A Parent inherits all attributes of humanBeing
• The property of inheritance is an essential feature of
object-oriented languages such as Smalltalk, C++,
Ada 95, Java (but not C, FORTRAN)
04/27/15 MCA-114 13
Inheritance (contd)
• UML notation
– Inheritance is represented by a large open triangle
04/27/15 MCA-114 14
Overriding and Overloading
Overriding: Process of redefining a property within a subclass.
Overloading: Allows name of a method to be reused with a class or across
classes.
04/27/15 MCA-114 15
Overriding Example:
Might define method in Staff class to increment salary based on commission
method void giveCommission(float branchProfit) {
salary = salary + 0.02 * branchProfit; }
May wish to perform different calculation for commission in Manager subclass:
method void giveCommission(float branchProfit) {
salary = salary + 0.05 * branchProfit; }
Aggregation
• UML Notation
04/27/15 MCA-114 16
Association
• UML Notation
04/27/15 MCA-114 17
Polymorphism and Dynamic Binding
• Polymorphism is another important OOP concept. Polymorphism, a Greek
term, means the ability to take more than one form. An operation may exhibit
different behaviors in difference instances. The behaviors depends upon the
types of data used in the operation. For example, consider the operation of
addition. For two numbers, the operation will generate a sum. If the operands
are strings , the operation would produce a third string by concatenation. The
process of making an operator to exhibit different behaviors in different
instances is known as operator overloading.
04/27/15 MCA-114 18
Polymorphism and Dynamic Binding (contd)
04/27/15 MCA-114 19
Shape
Draw()
Triangle object
Draw()
Box
Draw()
Circle
Draw()
Dynamic Binding
• Binding refers to the linking of a procedure call to the code to be executed
in response to the call. Dynamic binding means that the code associated
with a given procedure call is now knows until the time of the call at run-
time. It is associated with polymorphism and inheritance. A function call
associated with a polymorphic reference depends on the dynamic type of
that reference.
• Consider the procedure “draw”, every object will have this procedure. Its
algorithm is, however, unique to each object and so the draw procedure
will be redefined in each class that defines the object. At run-time, the
code matching the object under current reference will be called.
04/27/15 MCA-114 20
Message Passing
• An object-oriented program consists of a set of objects that communicate
with each other. The process of programming in an object oriented
language, therefore involves the following basic steps:
1. Creating classes that define objects and their behavior,
2. Creating objects from class definitions and
3. Establishing communication among objects.
• Objects communicate with one another by sending and receiving
information much the same way as people pass messages to one another.
The concept of message passing makes it easier to talk about building
systems that directly model their real-world counterparts.
• Message passing involves specifying the name of the object, the name of
the function (message) and the information to be sent. Example:-
• employee.salary(name)
• Object message information
04/27/15 MCA-114 21
Default Parameter Value
• C++ allows us to call a function without specifying all its arguments. In such
cases, the function assigns a default value to the parameter which does not have a
matching argument in the function call. Default values are specified when the
function is declared. The compiler looks at the prototype to see how many
arguments a function uses and alerts the program for possible default values.
• A default argument is checking for type at the time of declaration and evaluated at
the time of call. Once important point to note is that only the trailing arguments
can have default values and therefore we must add defaults form right to left. We
cannot provide a default value to a particular argument in the middle of an
argument list.
• Default arguments are useful in situations where some arguments always have the
same value.
04/27/15 MCA-114 22
int main()
{
float amount;
float value(float p, int n, float r=0.15);
amount=value(5000.00,5);
cout<<amount;
return 0;
}
float value(float p, int n, float r)
{
}
04/27/15 MCA-114 23
Default Parameter ValueDefault Parameter Value
Using Reference variables with
Functions
• Provision of the reference variables in C++ permits us to pass parameters to the
functions by reference. When we pass arguments by reference, the “formal”
arguments in the called function become aliases to the “actual” arguments in the
calling function. This means that when the function is working with its own
arguments, it is actually working on the original data.
• In C , this is accomplished using pointers .
void swap(int &a, int &b)
{
int t=a;
a=b;
b=t;
}
swap(m,n);
04/27/15 MCA-114 24
04/27/15 MCA-114 25
Debugging Exercises
1. What will happen when you execute the following code?
#include<iostream>
int main()
{
int i=0;
i=400*400/400;
cout<<i;
return 0;
}
2. Identify the error in the following program
#incude<iostream>
int main()
{
int num[]={1,2,3,4,5,6};
num[1]==[1]num ?cout<<“Success”:cout<<“Error”;
return 0;
}
04/27/15 MCA-114 26
Debugging Exercises
3. Identify the errors in the following program.
#include<iostream>
int main()
{
int i=5;
while(1)
{
Switch(i )
{
default:
case 4:
case 5:
break;
case 1:
continue;
case 2:
case 3:
break;
}
i--;
} }
04/27/15 MCA-114 27
Debugging Exercises
4. Identify the error in the following program.
#include<iostream>
#define pi 3.14
int squareArea(int &);
int circleArea(int &);
int main()
{
int a=10;
cout<<squareArea(a)<<“ “;
cout<<CircleArea(a)<<“ “;
cout<<a<<endl;
}
int squareArea(int &a)
{
return a*==a;
}
int circleArea(int &r)
{
return r=pi*r*r;
}
04/27/15 MCA-114 28
Debugging Exercises
5. Identify the error in the following program.
#include<iostream>
#include<cmalloc>
char* allocateMemory();
int main()
{
char *str;
str=allocateMemory();
cout<<str;
delete str;
str= “ “;
cout<<str;
}
Char* allocateMemory()
{
Str=“memory allocation test, “;
retrun str;
}
04/27/15 MCA-114 29
Debugging Exercises
6. Identify the error in the following program
#include<iostream>
void display(const int const1=5)
{
const int const2=5;
int arrary1[const1];
int arrary2[const2];
for(int i=0;i<5;i++)
{
arrary1[i]=I;
array2[i]=i*10;
cout<<array1[i]<<‘ ‘ <<array2[i]<<‘ ‘;
}
}
int main()
{
display(5);
}
04/27/15 MCA-114 30
Debugging Exercises
7. Identify the error in the following program.
#include<iostream>
int gValue=10;
void extra()
{
cout<<gValue<<‘ ‘;
}
int main()
{
extra();
{
int gValue=20;
cout<<gValue<<‘ ‘;
cout<<:gValue<<‘ ‘;
}
}
04/27/15 MCA-114 31
Find out Output
8. #include<iostream>
class user
{
private:
int i;
float f;
char c;
public:
void displaydata()
{
cout<<endl<<i<<‘n’<<f<<“n”<<c;
}
};
int main()
{
cout<<sizeof(user);
user u1;
cout<<endl<<sizeof(u1);
u1.displaydata(); }
04/27/15 MCA-114 32
Find out Output
9. #include<iostream>
class date
{
private:
int dd,mm,yy;
public:
date()
{
cout<<endl<<“Reached here”;
}
};
int main()
{
date today;
date *p=&today;
cout<<endl<<p;
}
Ad

More Related Content

What's hot (20)

Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
Pranali Chaudhari
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Pranali Chaudhari
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
sumitbardhan
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine Learning
Patrick Nicolas
 
DataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language FundamentalsDataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language Fundamentals
Joshua Erney
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
maznabili
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
sumitbardhan
 
Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
Object Oriented Programming With C++
Object Oriented Programming With C++Object Oriented Programming With C++
Object Oriented Programming With C++
Vishnu Shaji
 
Semantic Analysis using Wikipedia Taxonomy
Semantic Analysis using Wikipedia TaxonomySemantic Analysis using Wikipedia Taxonomy
Semantic Analysis using Wikipedia Taxonomy
Patrick Nicolas
 
Introduction to database-ER Model
Introduction to database-ER ModelIntroduction to database-ER Model
Introduction to database-ER Model
Ajit Nayak
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
sumitbardhan
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine Learning
Patrick Nicolas
 
DataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language FundamentalsDataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language Fundamentals
Joshua Erney
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
maznabili
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
sumitbardhan
 
Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
Object Oriented Programming With C++
Object Oriented Programming With C++Object Oriented Programming With C++
Object Oriented Programming With C++
Vishnu Shaji
 
Semantic Analysis using Wikipedia Taxonomy
Semantic Analysis using Wikipedia TaxonomySemantic Analysis using Wikipedia Taxonomy
Semantic Analysis using Wikipedia Taxonomy
Patrick Nicolas
 
Introduction to database-ER Model
Introduction to database-ER ModelIntroduction to database-ER Model
Introduction to database-ER Model
Ajit Nayak
 

Viewers also liked (7)

OOPs difference faqs-3
OOPs difference faqs-3OOPs difference faqs-3
OOPs difference faqs-3
Umar Ali
 
Chapter1 Introduction to OOP (Java)
Chapter1 Introduction to OOP (Java)Chapter1 Introduction to OOP (Java)
Chapter1 Introduction to OOP (Java)
Dyah Fajar Nur Rohmah
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
Pritom Chaki
 
object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)
munibali55
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
D Nayanathara
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
OOPs difference faqs-3
OOPs difference faqs-3OOPs difference faqs-3
OOPs difference faqs-3
Umar Ali
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
Pritom Chaki
 
object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)
munibali55
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
D Nayanathara
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
Ad

Similar to implementing oop_concept (20)

3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx
RokaKaram
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.ppt
ChishaleFriday
 
Advanced Topics on Database - Unit-2 AU17
Advanced Topics on Database - Unit-2 AU17Advanced Topics on Database - Unit-2 AU17
Advanced Topics on Database - Unit-2 AU17
LOGANATHANK24
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxMIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptx
elsagalgao
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 
C++ training
C++ training C++ training
C++ training
PL Sharma
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
Kongunadu College of Engineering and Technology
 
C++ & Data Structure - Unit - first.pptx
C++ & Data Structure - Unit - first.pptxC++ & Data Structure - Unit - first.pptx
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
34. uml
34. uml34. uml
34. uml
karzansaid
 
Data structures
Data structuresData structures
Data structures
Saurabh Mishra
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
Rasi Manivannan
 
Ooad ch 2
Ooad ch 2Ooad ch 2
Ooad ch 2
anujabeatrice2
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
JITTAYASHWANTHREDDY
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
 
My c++
My c++My c++
My c++
snathick
 
3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx
RokaKaram
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.ppt
ChishaleFriday
 
Advanced Topics on Database - Unit-2 AU17
Advanced Topics on Database - Unit-2 AU17Advanced Topics on Database - Unit-2 AU17
Advanced Topics on Database - Unit-2 AU17
LOGANATHANK24
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxMIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptx
elsagalgao
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 
C++ training
C++ training C++ training
C++ training
PL Sharma
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
 
Ad

Recently uploaded (20)

Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 

implementing oop_concept

  • 1. Object-Oriented Programming • Objects can be used effectively to represent real-world entities • For instance, an object might represent a particular employee in a company • Each employee object handles the processing and data management related to that employee 04/27/15 MCA-114 2
  • 2. Objects • An object has: – state - descriptive characteristics – behaviors - what it can do (or what can be done to it) • The state of a bank account includes its account number and its current balance • The behaviors associated with a bank account include the ability to make deposits and withdrawals • Note that the behavior of an object might change its state 04/27/15 MCA-114 3
  • 3. Classes • An object is defined by a class • A class is the blueprint of an object • Multiple objects can be created from the same class 04/27/15 MCA-114 4
  • 4. Objects and Classes 04/27/15 MCA-114 5 Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class
  • 5. Attributes Contain current state of an object. • Attributes can be classified as simple or complex. • Simple attribute can be a primitive type such as integer, string, etc., which takes on literal values. • Complex attribute can contain collections and/or references. • Reference attribute represents relationship. • complex object: contains one or more complex attributes 04/27/15 MCA-114 6
  • 6. Methods and messages Method: Defines behavior of an object, as a set of encapsulated functions. Message: Request from one object to another asking second object to execute one of its methods. 04/27/15 MCA-114 7 (a) (b) (a) Object showing attributes and methods (b) Example of a method
  • 7. Classes Class: Blueprint for defining a set of similar objects. Objects in a class are called instances. 04/27/15 MCA-114 8
  • 8. Data Encapsulation and Abstraction • The wrapping up of data and functions into a single unit is known as encapsulation. Data encapsulation is the most striking feature of a class. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. These functions provide the interface between the object’s data and the program. This insulation of the data form direct access by the program is called data hiding or information hiding. • Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost and functions to operate on these attributes. They encapsulate all the essential properties of the objects that are to be created. The attributes are sometimes called data members because they hold information. The functions that operate on these data are sometimes called methods or member function. Since the classes use the concept of data abstraction, they are knows as Abstract Data Types (ADT). 04/27/15 MCA-114 9
  • 9. Inheritance • One class can be used to derive another via inheritance • Classes can be organized into hierarchies 04/27/15 MCA-114 10 Bank Account Account Charge Account Savings Account Checking Account
  • 10. Inheritance (contd) Inheritance allows one class of objects to be defined as a special case of a more general class. Special cases are subclasses and more general cases are superclasses. 04/27/15 MCA-114 11 Generalization: process of forming a superclass Specialization: forming a subclass •Subclass inherits all properties of its superclass and can define its own unique properties. •Subclass can redefine inherited methods. •All instances of subclass are instances of superclass. •Principle of substitutability: instance of subclass can be used whenever method/construct expects instance of superclass. •A KIND OF (AKO): Name for relationship between subclass and superclass
  • 11. Types of inheritance 04/27/15 MCA-114 12 (a) (b) (c) (a) Single (b) Multiple (c) Repeated (b)
  • 12. Inheritance (contd) • Define humanBeing to be a class – A humanBeing has attributes, such as age, height, gender – Assign values to attributes when describing object • Define Parent to be a subclass of HumanBeing – A Parent has all attributes of a HumanBeing, plus attributes of his/her own (name of oldest child, number of children) – A Parent inherits all attributes of humanBeing • The property of inheritance is an essential feature of object-oriented languages such as Smalltalk, C++, Ada 95, Java (but not C, FORTRAN) 04/27/15 MCA-114 13
  • 13. Inheritance (contd) • UML notation – Inheritance is represented by a large open triangle 04/27/15 MCA-114 14
  • 14. Overriding and Overloading Overriding: Process of redefining a property within a subclass. Overloading: Allows name of a method to be reused with a class or across classes. 04/27/15 MCA-114 15 Overriding Example: Might define method in Staff class to increment salary based on commission method void giveCommission(float branchProfit) { salary = salary + 0.02 * branchProfit; } May wish to perform different calculation for commission in Manager subclass: method void giveCommission(float branchProfit) { salary = salary + 0.05 * branchProfit; }
  • 17. Polymorphism and Dynamic Binding • Polymorphism is another important OOP concept. Polymorphism, a Greek term, means the ability to take more than one form. An operation may exhibit different behaviors in difference instances. The behaviors depends upon the types of data used in the operation. For example, consider the operation of addition. For two numbers, the operation will generate a sum. If the operands are strings , the operation would produce a third string by concatenation. The process of making an operator to exhibit different behaviors in different instances is known as operator overloading. 04/27/15 MCA-114 18
  • 18. Polymorphism and Dynamic Binding (contd) 04/27/15 MCA-114 19 Shape Draw() Triangle object Draw() Box Draw() Circle Draw()
  • 19. Dynamic Binding • Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is now knows until the time of the call at run- time. It is associated with polymorphism and inheritance. A function call associated with a polymorphic reference depends on the dynamic type of that reference. • Consider the procedure “draw”, every object will have this procedure. Its algorithm is, however, unique to each object and so the draw procedure will be redefined in each class that defines the object. At run-time, the code matching the object under current reference will be called. 04/27/15 MCA-114 20
  • 20. Message Passing • An object-oriented program consists of a set of objects that communicate with each other. The process of programming in an object oriented language, therefore involves the following basic steps: 1. Creating classes that define objects and their behavior, 2. Creating objects from class definitions and 3. Establishing communication among objects. • Objects communicate with one another by sending and receiving information much the same way as people pass messages to one another. The concept of message passing makes it easier to talk about building systems that directly model their real-world counterparts. • Message passing involves specifying the name of the object, the name of the function (message) and the information to be sent. Example:- • employee.salary(name) • Object message information 04/27/15 MCA-114 21
  • 21. Default Parameter Value • C++ allows us to call a function without specifying all its arguments. In such cases, the function assigns a default value to the parameter which does not have a matching argument in the function call. Default values are specified when the function is declared. The compiler looks at the prototype to see how many arguments a function uses and alerts the program for possible default values. • A default argument is checking for type at the time of declaration and evaluated at the time of call. Once important point to note is that only the trailing arguments can have default values and therefore we must add defaults form right to left. We cannot provide a default value to a particular argument in the middle of an argument list. • Default arguments are useful in situations where some arguments always have the same value. 04/27/15 MCA-114 22
  • 22. int main() { float amount; float value(float p, int n, float r=0.15); amount=value(5000.00,5); cout<<amount; return 0; } float value(float p, int n, float r) { } 04/27/15 MCA-114 23 Default Parameter ValueDefault Parameter Value
  • 23. Using Reference variables with Functions • Provision of the reference variables in C++ permits us to pass parameters to the functions by reference. When we pass arguments by reference, the “formal” arguments in the called function become aliases to the “actual” arguments in the calling function. This means that when the function is working with its own arguments, it is actually working on the original data. • In C , this is accomplished using pointers . void swap(int &a, int &b) { int t=a; a=b; b=t; } swap(m,n); 04/27/15 MCA-114 24
  • 24. 04/27/15 MCA-114 25 Debugging Exercises 1. What will happen when you execute the following code? #include<iostream> int main() { int i=0; i=400*400/400; cout<<i; return 0; } 2. Identify the error in the following program #incude<iostream> int main() { int num[]={1,2,3,4,5,6}; num[1]==[1]num ?cout<<“Success”:cout<<“Error”; return 0; }
  • 25. 04/27/15 MCA-114 26 Debugging Exercises 3. Identify the errors in the following program. #include<iostream> int main() { int i=5; while(1) { Switch(i ) { default: case 4: case 5: break; case 1: continue; case 2: case 3: break; } i--; } }
  • 26. 04/27/15 MCA-114 27 Debugging Exercises 4. Identify the error in the following program. #include<iostream> #define pi 3.14 int squareArea(int &); int circleArea(int &); int main() { int a=10; cout<<squareArea(a)<<“ “; cout<<CircleArea(a)<<“ “; cout<<a<<endl; } int squareArea(int &a) { return a*==a; } int circleArea(int &r) { return r=pi*r*r; }
  • 27. 04/27/15 MCA-114 28 Debugging Exercises 5. Identify the error in the following program. #include<iostream> #include<cmalloc> char* allocateMemory(); int main() { char *str; str=allocateMemory(); cout<<str; delete str; str= “ “; cout<<str; } Char* allocateMemory() { Str=“memory allocation test, “; retrun str; }
  • 28. 04/27/15 MCA-114 29 Debugging Exercises 6. Identify the error in the following program #include<iostream> void display(const int const1=5) { const int const2=5; int arrary1[const1]; int arrary2[const2]; for(int i=0;i<5;i++) { arrary1[i]=I; array2[i]=i*10; cout<<array1[i]<<‘ ‘ <<array2[i]<<‘ ‘; } } int main() { display(5); }
  • 29. 04/27/15 MCA-114 30 Debugging Exercises 7. Identify the error in the following program. #include<iostream> int gValue=10; void extra() { cout<<gValue<<‘ ‘; } int main() { extra(); { int gValue=20; cout<<gValue<<‘ ‘; cout<<:gValue<<‘ ‘; } }
  • 30. 04/27/15 MCA-114 31 Find out Output 8. #include<iostream> class user { private: int i; float f; char c; public: void displaydata() { cout<<endl<<i<<‘n’<<f<<“n”<<c; } }; int main() { cout<<sizeof(user); user u1; cout<<endl<<sizeof(u1); u1.displaydata(); }
  • 31. 04/27/15 MCA-114 32 Find out Output 9. #include<iostream> class date { private: int dd,mm,yy; public: date() { cout<<endl<<“Reached here”; } }; int main() { date today; date *p=&today; cout<<endl<<p; }