SlideShare a Scribd company logo
1 of 24
OBJECT
ORIENTED
PROGRAMMING
FPL II Unit II
SPPU-2017/18
Prof. Ansari Aadil
Prof. Ansari Aadil S
Object
 OBJECT is an identifiable entity with some
characteristics and behavior.
 In OOP programming object represents a entity that
can store data and has its interface through functions.
 CLASS is a template/blue-print representing a group of
objects that share common properties and
relationships.
Prof. Ansari Aadil S
Structure of an
Object Oriented
Program
Prof. Ansari Aadil S
Features of OOP
• More emphasis on data rather than procedure.
• Programs are divided into object.
• Function and data are tied together in a data
structure.
• Objects communicate with each other through
Functions.
• Data is hidden or cannot be access by external
function.
Prof. Ansari Aadil S
Principle of OOPS
• Class:
It is type or a category of things.
It is similar to a structure with the difference that it
can also have function.
Ex. Class of Cars. There may be many cars with different
names and brand but all of them will share some
common properties like all of them will have 4
wheels, Speed Limit, Mileage range etc.
Prof. Ansari Aadil S
OBJECT : It is an instance of class. Ex. Class fruit can have apple as its object.
ABSTRACTION refers to the act of representing essential features without
including the background details or explanations.
ENCAPSULATION :The wrapping up of data and operations / functions (that
operate on the data ) into a single unit (called class) is known as
ENCAPSULATION.
INHERITANCE: Inheritance is the capability of one class of things to inherit
capabilities or properties from other class
POLYMORPHISM: Multiple form of the same thing. It is the ability for a
message or data to be processed in more than one form.
Prof. Ansari Aadil S
Structure of Object Oriented Program in
c++
#include<iostream.h>
class class-name
{
access-specifiers…
int i,j;
float f;
char ch;
double b;
access-specifiers…
void function-name()
{
statement 1;
statement 2;
}
}
main()
{
class-name.obj-name;
}
Header File
class
Data Variables or fields
Function or Method
Object of class
Class members
Prof. Ansari Aadil S
Define a Class Type
class class_name
{
permission_label:
member;
permission_label:
member;
...
};
class Rectangle
{
private:
int width;
int length;
public:
void set(int w, int
l);
int area();
};
Body
Header
Prof. Ansari Aadil S
class Rectangle
{
private:
int width;
int length;
public:
void set(int w, int
l);
int area();
};
Classes & Objects
Rectangle
r1;
Rectangle
r2;
Rectangle
r3;
……
int a;
Objects: Instance of a class
Prof. Ansari Aadil S
• Information hiding
• To prevent the internal representation from direct access
from outside the class
• Access Specifiers
• public
• may be accessible from anywhere within a program
• private
• may be accessed only by the member functions, and friends of
this class
• protected
• acts as public for derived classes
• behaves as private for the rest of the program
Class Definition - Access Control
Prof. Ansari Aadil S
Read and print details of a student using class
program in C++
/*C++ program to create class for a student.*/
#include <iostream>
using namespace std;
class student
{
private:
char name[30];
int rollNo;
int total;
float perc;
public:
//member function to get
student's details
void getDetails(void);
//member function to print
student's details
void putDetails(void);
};
//member function definition, outside of the class
void student::getDetails(void){
cout << "Enter name: " ;
cin >> name;
cout << "Enter roll number: ";
cin >> rollNo;
cout << "Enter total marks outof 500: ";
cin >> total;
perc=(float)total/500*100;
}
//member function definition, outside of the class
void student::putDetails(void){
cout << "Student details:n";
cout << "Name:"<< name << ",Roll
Number:" << rollNo << ",Total:" << total <<
",Percentage:" << perc;
}
int main()
{
student std; //object
creation
std.getDetails();
std.putDetails();
return 0;
}
Output: Enter name: mike
Enter roll number: 112
Enter total marks outof 500: 456
Student details:
Name:mike,Roll
Number:112,Total:456,Percentage:91.2
Prof. Ansari Aadil S
// Program to illustrate the working of objects and
class in C++ Programming
#include <iostream.h>
#include<conio.h>
class Test
{
private:
int data1;
float data2;
public:
void insertIntegerData(int d)
{
data1 = d;
cout << "Number: " << data1;
}
float insertFloatData()
{
cout << "nEnter data: ";
cin >> data2;
return data2;
}
};
int main()
{
Test o1, o2;
float secondDataOfObject2;
o1.insertIntegerData(12);
secondDataOfObject2 = o2.insertFloatData();
cout << "You entered " << secondDataOfObject2;
getch();
}
Output
Number: 12
Enter data: 23.3
You entered 23.3
Prof. Ansari Aadil S
Data Structure
Data : It is piece of Information
ex . String or any record
Types of Data:
1. Atomic– Single , Non decomposable
ex. 1234
2. Composite or structured – can be broken into sub fields
ex PRN has college code, branch code, student id.
Prof. Ansari Aadil S
A data structure is a particular way of organizing data in a
computer so that it can be used effectively.
Data structure is linear or non Linear in nature
1.Linear- every item is attach to previous and next item
ex. Array , Linked list, Stack ,Queue
2. Non linear – every item is attached to many other items.
Multidimensional array, Tree , Graph.
Prof. Ansari Aadil S
Stack
Queue
Linked List Graph Tree
Prof. Ansari Aadil S
Defining member function
1. Internally defined function- when member function of a
class are defined inside the class itself
#include<iostream.h>
#include<conio.h>
class circle
{
float r,a;
public:
void read()
{
cout<<“Enter radius:”;
cin>>r;
}
void compute()
{
a= 3.14 *r * r;
}
void display()
{
cout<<“Area”=<<a; }
};
void main()
{
clrscr();
circle c;
c.read();
c.compute();
c.display();
getch();
}
Output: Enter radius: 5
Area= 78.5
Prof. Ansari Aadil S
2. Externally defined function
When the member function of a class are defined outside the class.
:: () scope resolution operator is used.
#include<iostream.h>
#include<conio.h>
class circle
{
float r,a;
public:
void read();
void compute();
void display();
};
void circle :: read()
{
cout<<“Enter radius:”;
cin>>r;
}
void circle :: compute()
{
a= 3.14 *r * r;
}
void circle :: display()
{
cout<<“Area”=<<a; }
};
void main()
{
clrscr();
circle c;
c.read();
c.compute();
c.display();
getch();
}
Output: Enter radius: 5
Area= 78.5
Prof. Ansari Aadil S
3. Inline Member function
If a function is defined outside the class but still to be treated as internally
defined function then such function has to be made “inline” function
#include<iostream.h>
#include<conio.h>
class circle
{
float r,a;
public:
void read();
void compute();
void display();
};
inline void circle :: read()
{
cout<<“Enter radius:”;
cin>>r;
}
inline void circle :: compute()
{
a= 3.14 *r * r;
}
inline void circle :: display()
{
cout<<“Area”=<<a; }
};
void main()
{
clrscr();
circle c;
c.read();
c.compute();
c.display();
getch();
}
Output: Enter radius: 5
Area= 78.5
Prof. Ansari Aadil S
Constructor
A constructor is a member function of a class which initializes
objects of a class.
• Constructor has same name as the class itself
• Constructors don’t have return type
• A constructor is automatically called when an object is created.
• If we do not specify a constructor, C++ compiler generates a
default constructor for us (expects no parameters and has an
empty body).
Prof. Ansari Aadil S
Types of Constructors
1. Default Constructors
2. Parameterized Constructors:
3. Copy Constructor
Prof. Ansari Aadil S
Default Constructors:
Default constructor is the constructor which doesn’t take any
argument. It has no parameters.
#include <iostream.h>
#include<conio.h>
using namespace std;
class construct
{
public:
int a, b;
// Default Constructor
construct()
{
a = 10;
b = 20;
}
};
void main()
{
// Default constructor called automatically
// when the object is created
construct c;
cout << "a: "<< c.a << endl << "b: "<< c.b;
getch();
}
Output:
a: 10
b: 20
Prof. Ansari Aadil S
Parameterized Constructors
To create a parameterized constructor, simply add parameters to it the way you would to any other
function. When you define the constructor’s body, use the parameters to initialize the object.
#include<iostream.h>
#include<conio.h>
class Point
{
private:
int x, y;
public:
// Parameterized Constructor
Point(int x1, int y1)
{
x = x1;
y = y1;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
};
int main()
{
// Constructor called
Point p1(10, 15);
// Access values assigned by constructor
cout << "p1.x = " << p1.getX() << ", p1.y
= " << p1.getY();
return 0;
}
Output:
p1.x = 10, p1.y = 15
Prof. Ansari Aadil S
Copy Constructor
A copy constructor is a member function which initializes
an object using another object of the same class.
ClassName (const ClassName &old_obj);
Prof. Ansari Aadil S
Destructors
Destructor is a member function which destructs or deletes an object.
Destructors have same name as the class preceded by a tilde (~)
class test
{
int *p;
public:
test()
{
p=new int;
}
void read()
{
cout<< “ Enter a number: ”;
cin>> *p;
}
void display()
{
cout<< “ Value= “<<*p<< endl;
}
~ test()
{
delete p;
cout<<“Destroyed”;
}
};
void main()
{
clrscr();
test t;
t.read();
t.display();
getch();
}
Output: Enter a number: 5
Value=5;
Destroyed
Prof. Ansari Aadil S

More Related Content

What's hot

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OSSalah Amean
 
Basic concept of frame relay
Basic concept of frame relayBasic concept of frame relay
Basic concept of frame relayNetProtocol Xpert
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSESujata Regoti
 
x86 architecture
x86 architecturex86 architecture
x86 architecturei i
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5RLJIT
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
Pipeline hazards in computer Architecture ppt
Pipeline hazards in computer Architecture pptPipeline hazards in computer Architecture ppt
Pipeline hazards in computer Architecture pptmali yogesh kumar
 
Unit 3 Network Layer PPT
Unit 3 Network Layer PPTUnit 3 Network Layer PPT
Unit 3 Network Layer PPTKalpanaC14
 
Intel x86 Architecture
Intel x86 ArchitectureIntel x86 Architecture
Intel x86 ArchitectureChangWoo Min
 

What's hot (20)

Java Quiz
Java QuizJava Quiz
Java Quiz
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
A Step Towards Data Orientation
A Step Towards Data OrientationA Step Towards Data Orientation
A Step Towards Data Orientation
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Exception handling
Exception handlingException handling
Exception handling
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
 
Basic concept of frame relay
Basic concept of frame relayBasic concept of frame relay
Basic concept of frame relay
 
Asterisk: the future is at REST
Asterisk: the future is at RESTAsterisk: the future is at REST
Asterisk: the future is at REST
 
Operations on Processes
Operations on ProcessesOperations on Processes
Operations on Processes
 
Chapter 8: Switching
Chapter 8: SwitchingChapter 8: Switching
Chapter 8: Switching
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
x86 architecture
x86 architecturex86 architecture
x86 architecture
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
IPocalypse
IPocalypseIPocalypse
IPocalypse
 
Os讀書會20170616
Os讀書會20170616Os讀書會20170616
Os讀書會20170616
 
Pipeline hazards in computer Architecture ppt
Pipeline hazards in computer Architecture pptPipeline hazards in computer Architecture ppt
Pipeline hazards in computer Architecture ppt
 
Unit 3 Network Layer PPT
Unit 3 Network Layer PPTUnit 3 Network Layer PPT
Unit 3 Network Layer PPT
 
Intel x86 Architecture
Intel x86 ArchitectureIntel x86 Architecture
Intel x86 Architecture
 

Similar to OOP Concepts Explained

Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Abu Saleh
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectsecondakay
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objectsRai University
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.pptBArulmozhi
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3Atif Khan
 
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 Boro
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1Vineeta Garg
 

Similar to OOP Concepts Explained (20)

Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 

Recently uploaded

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

OOP Concepts Explained

  • 1. OBJECT ORIENTED PROGRAMMING FPL II Unit II SPPU-2017/18 Prof. Ansari Aadil Prof. Ansari Aadil S
  • 2. Object  OBJECT is an identifiable entity with some characteristics and behavior.  In OOP programming object represents a entity that can store data and has its interface through functions.  CLASS is a template/blue-print representing a group of objects that share common properties and relationships. Prof. Ansari Aadil S
  • 3. Structure of an Object Oriented Program Prof. Ansari Aadil S
  • 4. Features of OOP • More emphasis on data rather than procedure. • Programs are divided into object. • Function and data are tied together in a data structure. • Objects communicate with each other through Functions. • Data is hidden or cannot be access by external function. Prof. Ansari Aadil S
  • 5. Principle of OOPS • Class: It is type or a category of things. It is similar to a structure with the difference that it can also have function. Ex. Class of Cars. There may be many cars with different names and brand but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range etc. Prof. Ansari Aadil S
  • 6. OBJECT : It is an instance of class. Ex. Class fruit can have apple as its object. ABSTRACTION refers to the act of representing essential features without including the background details or explanations. ENCAPSULATION :The wrapping up of data and operations / functions (that operate on the data ) into a single unit (called class) is known as ENCAPSULATION. INHERITANCE: Inheritance is the capability of one class of things to inherit capabilities or properties from other class POLYMORPHISM: Multiple form of the same thing. It is the ability for a message or data to be processed in more than one form. Prof. Ansari Aadil S
  • 7. Structure of Object Oriented Program in c++ #include<iostream.h> class class-name { access-specifiers… int i,j; float f; char ch; double b; access-specifiers… void function-name() { statement 1; statement 2; } } main() { class-name.obj-name; } Header File class Data Variables or fields Function or Method Object of class Class members Prof. Ansari Aadil S
  • 8. Define a Class Type class class_name { permission_label: member; permission_label: member; ... }; class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); }; Body Header Prof. Ansari Aadil S
  • 9. class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); }; Classes & Objects Rectangle r1; Rectangle r2; Rectangle r3; …… int a; Objects: Instance of a class Prof. Ansari Aadil S
  • 10. • Information hiding • To prevent the internal representation from direct access from outside the class • Access Specifiers • public • may be accessible from anywhere within a program • private • may be accessed only by the member functions, and friends of this class • protected • acts as public for derived classes • behaves as private for the rest of the program Class Definition - Access Control Prof. Ansari Aadil S
  • 11. Read and print details of a student using class program in C++ /*C++ program to create class for a student.*/ #include <iostream> using namespace std; class student { private: char name[30]; int rollNo; int total; float perc; public: //member function to get student's details void getDetails(void); //member function to print student's details void putDetails(void); }; //member function definition, outside of the class void student::getDetails(void){ cout << "Enter name: " ; cin >> name; cout << "Enter roll number: "; cin >> rollNo; cout << "Enter total marks outof 500: "; cin >> total; perc=(float)total/500*100; } //member function definition, outside of the class void student::putDetails(void){ cout << "Student details:n"; cout << "Name:"<< name << ",Roll Number:" << rollNo << ",Total:" << total << ",Percentage:" << perc; } int main() { student std; //object creation std.getDetails(); std.putDetails(); return 0; } Output: Enter name: mike Enter roll number: 112 Enter total marks outof 500: 456 Student details: Name:mike,Roll Number:112,Total:456,Percentage:91.2 Prof. Ansari Aadil S
  • 12. // Program to illustrate the working of objects and class in C++ Programming #include <iostream.h> #include<conio.h> class Test { private: int data1; float data2; public: void insertIntegerData(int d) { data1 = d; cout << "Number: " << data1; } float insertFloatData() { cout << "nEnter data: "; cin >> data2; return data2; } }; int main() { Test o1, o2; float secondDataOfObject2; o1.insertIntegerData(12); secondDataOfObject2 = o2.insertFloatData(); cout << "You entered " << secondDataOfObject2; getch(); } Output Number: 12 Enter data: 23.3 You entered 23.3 Prof. Ansari Aadil S
  • 13. Data Structure Data : It is piece of Information ex . String or any record Types of Data: 1. Atomic– Single , Non decomposable ex. 1234 2. Composite or structured – can be broken into sub fields ex PRN has college code, branch code, student id. Prof. Ansari Aadil S
  • 14. A data structure is a particular way of organizing data in a computer so that it can be used effectively. Data structure is linear or non Linear in nature 1.Linear- every item is attach to previous and next item ex. Array , Linked list, Stack ,Queue 2. Non linear – every item is attached to many other items. Multidimensional array, Tree , Graph. Prof. Ansari Aadil S
  • 15. Stack Queue Linked List Graph Tree Prof. Ansari Aadil S
  • 16. Defining member function 1. Internally defined function- when member function of a class are defined inside the class itself #include<iostream.h> #include<conio.h> class circle { float r,a; public: void read() { cout<<“Enter radius:”; cin>>r; } void compute() { a= 3.14 *r * r; } void display() { cout<<“Area”=<<a; } }; void main() { clrscr(); circle c; c.read(); c.compute(); c.display(); getch(); } Output: Enter radius: 5 Area= 78.5 Prof. Ansari Aadil S
  • 17. 2. Externally defined function When the member function of a class are defined outside the class. :: () scope resolution operator is used. #include<iostream.h> #include<conio.h> class circle { float r,a; public: void read(); void compute(); void display(); }; void circle :: read() { cout<<“Enter radius:”; cin>>r; } void circle :: compute() { a= 3.14 *r * r; } void circle :: display() { cout<<“Area”=<<a; } }; void main() { clrscr(); circle c; c.read(); c.compute(); c.display(); getch(); } Output: Enter radius: 5 Area= 78.5 Prof. Ansari Aadil S
  • 18. 3. Inline Member function If a function is defined outside the class but still to be treated as internally defined function then such function has to be made “inline” function #include<iostream.h> #include<conio.h> class circle { float r,a; public: void read(); void compute(); void display(); }; inline void circle :: read() { cout<<“Enter radius:”; cin>>r; } inline void circle :: compute() { a= 3.14 *r * r; } inline void circle :: display() { cout<<“Area”=<<a; } }; void main() { clrscr(); circle c; c.read(); c.compute(); c.display(); getch(); } Output: Enter radius: 5 Area= 78.5 Prof. Ansari Aadil S
  • 19. Constructor A constructor is a member function of a class which initializes objects of a class. • Constructor has same name as the class itself • Constructors don’t have return type • A constructor is automatically called when an object is created. • If we do not specify a constructor, C++ compiler generates a default constructor for us (expects no parameters and has an empty body). Prof. Ansari Aadil S
  • 20. Types of Constructors 1. Default Constructors 2. Parameterized Constructors: 3. Copy Constructor Prof. Ansari Aadil S
  • 21. Default Constructors: Default constructor is the constructor which doesn’t take any argument. It has no parameters. #include <iostream.h> #include<conio.h> using namespace std; class construct { public: int a, b; // Default Constructor construct() { a = 10; b = 20; } }; void main() { // Default constructor called automatically // when the object is created construct c; cout << "a: "<< c.a << endl << "b: "<< c.b; getch(); } Output: a: 10 b: 20 Prof. Ansari Aadil S
  • 22. Parameterized Constructors To create a parameterized constructor, simply add parameters to it the way you would to any other function. When you define the constructor’s body, use the parameters to initialize the object. #include<iostream.h> #include<conio.h> class Point { private: int x, y; public: // Parameterized Constructor Point(int x1, int y1) { x = x1; y = y1; } int getX() { return x; } int getY() { return y; } }; int main() { // Constructor called Point p1(10, 15); // Access values assigned by constructor cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY(); return 0; } Output: p1.x = 10, p1.y = 15 Prof. Ansari Aadil S
  • 23. Copy Constructor A copy constructor is a member function which initializes an object using another object of the same class. ClassName (const ClassName &old_obj); Prof. Ansari Aadil S
  • 24. Destructors Destructor is a member function which destructs or deletes an object. Destructors have same name as the class preceded by a tilde (~) class test { int *p; public: test() { p=new int; } void read() { cout<< “ Enter a number: ”; cin>> *p; } void display() { cout<< “ Value= “<<*p<< endl; } ~ test() { delete p; cout<<“Destroyed”; } }; void main() { clrscr(); test t; t.read(); t.display(); getch(); } Output: Enter a number: 5 Value=5; Destroyed Prof. Ansari Aadil S