SlideShare a Scribd company logo
Programming fundamental
Submitted by : Sidra Tahir
Submitted to : Ma'am Shumaila
Subject : object oriented program
Roll no : 165
Class : BSCS
Date : 30- 03-2020
Session : 2019-2023
COVT. POST GRADUATE COLLEGE FOR WOMENS GULBERG LAHORE
CONTENTS
 Polymorphism
 Virtual function
 Pointer to all object
 Abstractconcrete class
 Pure virtual class
PowerPlugs Templates for PowerPoint Preview 3
Polymorphism
In object-oriented
programming, polymorphism ref
ers to a programming language's
ability to process objects
differently depending on their
data type or class. More
specifically, it is the ability to
redefine methods for derived
classes.
Real life Example
 A person at the same time can have different characteristic.
Like a man at the same time is a father, a husband, an
employee. So the same person posses different behavior in
different situations. This is called polymorphism.
you have a smartphone for communication. The
communication mode you choose could be anything. It can be
a call, a text message, a picture message, mail, etc. So, the goal
is common that is communication, but their approach is
different.
Example Of Polymorphism
#include<iostream.h>
#include<conio.h>
class test
{
clrscr();
private:
int n;
public:
void in()
{
cout<<"enter a number:";
cin>>n;
}
Continue……………………
void out()
{
cout<<"the value of n = "<<n;
}
};
void main()
{
clrscr();
test*ptr;
ptr=new test;
ptr->in();
ptr->out();
getch();
}
PowerPlugs Templates for PowerPoint Preview 7
Output and working of program
output
Working:
The above program declares a class test and a pointer ptr of type test. The pointer can
refer to object of the class. The new operator creates an object in the memory and stores
the address in ptr. The program then uses the pointer to call the member function of the
object being referenced by the pointer. The symbol -> is used to access the member of any
object through pointer. The use of dot operator with pointer to access any member is
invalid.
 Virtual means existing in effect but not really.
 A type of function in some part of a program but does not exist really is
called virtual function.
 A virtual function is defined in the present class and can be overridden in
child classes.
Virtual function
Class class-name
{
Public:
Virtual void member- function-name()
{
…………. …………... body of base class
}
};
Syntax of virtual function
keyword
#include<iostream.h>
#include<conio.h>
class cbaseclass
{
public:
virtual void sayhello()
{
cout<<"hello from the cbaseclassnn";
}
void sayhi()
{
cout<<" hi from cbaseclassnn";
}
Example
program
#include<iostream.h>
#include<conio.h>
class a
{
public:
void disp()
{
cout<<" n i am from base class a";
}
};
class b : public a
{
public:
void disp()
{
cout<<"n i am from base class b";
}
};
continue……….
PowerPlugs Templates for PowerPoint Preview 12
class c: public b
{
public:
void disp()
{
cout<<"n i am from base class c";
}
};
void main()
{
a *pa;
b objb;
c objc;
pa=&objb;
pa->disp();
pa=&objc;
pa->disp();
getch();
}
PowerPlugs Templates for PowerPoint Preview 13
Output of program
output
i am from base class a
i am from base class a
PowerPlugs Templates for PowerPoint Preview 14
Working of program
The program declares three class a are the parent class and b and c are the child
classes. Each class has a member function disp().The disp() function in parent class a is
declared as virtual function. The child classes b and c override that member function.
The program declares one object of each class. It also declares a pointer ptr of class a.
the address of each object is stored in pointer and disp(0 function is called . Each time
the disp() function is called, corresponding function execution is executed
PowerPlugs Templates for PowerPoint Preview 15
A type of virtual function that has no body is known as pure virtual
function. A function can be declared as pure virtual function by adding
two things:
 The keyword virtual at the start of the function declarator.
 The =0 at the end of function declaratory.
Note: the pure virtual function are used in the classes which are not
used directly. The user can inherit the class and then override the pure
virtual function in the child class.
Pure virtual function
Class class-name
{
Public:
Virtual return-type function-name()=0
};
syntax
keyword
=0 indicate
that function
is pure
virtual
function
#include<iostream.h>
#include<conio.h>
Class A
{
clrscr();
Public:
Virtual void disp()=0;
};
Class B : public A
{
void disp()
{
Cout <<“n I am form derived class B”;
}};
Program and Example
Class C :public B
{
Public:
Void disp()
{
Cout<<“n I am form derived class
C”;
}
};
Int main()
{
B obj b;
C obj c;
Obj b.disp)();
Obj c.disp();
getch();
}
};
Output and working of program
Output
Working:
The program declares three class A are the parent class and B and C are
the child classes. Each class has a member function disp().The disp()
function in parent class A is declared as pure virtual function. The child
classes b and c override that member function.
The program declares one object of each class and disp(0 function is called
. Each time the disp() function is called, corresponding function execution
is executed
PowerPlugs Templates for PowerPoint Preview 19
Abstract class
By definition, an abstract class in C++ is a class that has at
least one pure virtual function (i.e., a function that has no
definition).
Syntax
abstract Class < class-name>
{
Public:
Abstract void function-name()
{
……….
}
Abstract method
}
PowerPlugs Templates for PowerPoint Preview 21
keyword
Program and Example
#include<iostream.h>
#include<conio.h>
Class abstract interface
{
Public:
Virtual void numbers()=0;
Void input();
Int a,b;
};
Void abstract interface : : input
{
Cout<<“enter the two numbers”;
Cin>>a>>b;
}
Continue………………..
PowerPlugs Templates for PowerPoint Preview 22
Class add: public abstract interface
{
Public:
Void numbers()
{
Int sum,a,b;
Sum=a+b;
Cout<<“sum is << sum<<“n”;
}
};
Class sub: public abstract interface
{
Public:
Void numbers()
{
Cout<<“diff is << diff <<“n”;
}
};
PowerPlugs Templates for PowerPoint Preview 23
int main()
{
Output
Add obj1;
Obj1 input();
Obj1 numbers();
Sub obj2;
Obj2 input();
Obj2 numbers();
}
output
Working of program
The program declares parent as abstract class interface and the child classes
are add and subclass. The child class add override the pure virtual function
declared in parent class. It is important to declare a pure virtual function in
parent class and override it in all child classes to implement polymorphism.
Takin g input in both child classes and then in main function made objects of
both child classes as input and numbers.
PowerPlugs Templates for PowerPoint Preview 24
Abstract class  concrete class
• Concrete classes are not
interface.
• Concrete classes can be base or
derived.
• Pure virtual function are may
not present in concrete
class.these classes can
instantiate the objects.
PowerPlugs Templates for PowerPoint Preview 25
• Abstract classes are the
interface
• Abstract class is generally a base
class.
• Pure virtual function should be
present in the abstract class.
• This classes cannot instantiate
the facts.
Shape
2D shape 3D SHAPE
SQAURE
CIRCLE TRIANGLE
CUBE SPHERE
CYLINDER
ABSTACT
CLASSES
CONCRETE
CLASSES
Pointer to call objects
 When accessing members of a class given a pointer to an object, use the arrow (-
>) operator instead of dot (.) operator.
 Must initialize the pointer before using it.
 Pointer athematic is relative to the base type of the pointer.
syntax
ptr -> member
PowerPlugs Templates for PowerPoint Preview 27
It is the name of pointer that reference an object.
It is the member access operator that is used to access a member of
object.
It is the class member to be accessed.
Program
#include<iostream.h>
#incl;ude<conio.h>
Class laptop
{
Int ram;
Public:
Int usb;
Void getdata (int a)
{
Ram =a;
}
Void disp()
{
Cout<<“ram : ” << ram<< endl;
Cout<<“usb : ”<< usb < <endl;
} };
PowerPlugs Templates for PowerPoint Preview 28
ntI main()
{
Laptop dell
Laptop *pdell = &dell;
Pdell -> usb = 3;
Pdell->getdata(20);
Pdell-> disp()
Getch();
}
Output
Working of program
The program declares a class laptop and a pointer pdell of type laptop. The pointer
refer the object of the class. The new operator creates an object in the memory and
stores the address in pdell. The program then uses the pointer to call the member
function of the object being referenced by the pointer. The symbol -> is used to access
the member of any object through pointer.
PowerPlugs Templates for PowerPoint Preview 29
PowerPlugs Templates for PowerPoint Preview 30

More Related Content

What's hot

Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
rashmita_mishra
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Function overloading
Function overloadingFunction overloading
Function overloading
Prof. Dr. K. Adisesha
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
SherabGyatso
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Prof. Dr. K. Adisesha
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
shammi mehra
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuage
Nimai Chand Das
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
NicheTech Com. Solutions Pvt. Ltd.
 
Interface in java
Interface in javaInterface in java
Interface in java
Kavitha713564
 
C# Summer course - Lecture 2
C# Summer course - Lecture 2C# Summer course - Lecture 2
C# Summer course - Lecture 2
mohamedsamyali
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Abstract class
Abstract classAbstract class
Abstract class
Hoang Nguyen
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
Ajit Nayak
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
mohamedsamyali
 

What's hot (20)

Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
class and objects
class and objectsclass and objects
class and objects
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Class and object
Class and objectClass and object
Class and object
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuage
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Interface in java
Interface in javaInterface in java
Interface in java
 
C# Summer course - Lecture 2
C# Summer course - Lecture 2C# Summer course - Lecture 2
C# Summer course - Lecture 2
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Abstract class
Abstract classAbstract class
Abstract class
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 

Similar to Virtual function

Seminar
SeminarSeminar
SEMINAR
SEMINARSEMINAR
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
C questions
C questionsC questions
C questions
parm112
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Pranali Chaudhari
 
2nd puc computer science chapter 8 function overloading
 2nd puc computer science chapter 8   function overloading 2nd puc computer science chapter 8   function overloading
2nd puc computer science chapter 8 function overloading
Aahwini Esware gowda
 
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
 
Compose Camp - Intro.pdf
Compose Camp - Intro.pdfCompose Camp - Intro.pdf
Compose Camp - Intro.pdf
ajaykumarpurohit
 
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
Muhammed Thanveer M
 
OOP in java
OOP in javaOOP in java
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
Sangharsh agarwal
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
Object Oriented Programming using C++: Ch11 Virtual Functions.pptxObject Oriented Programming using C++: Ch11 Virtual Functions.pptx
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
RashidFaridChishti
 
DS Unit 6.ppt
DS Unit 6.pptDS Unit 6.ppt
DS Unit 6.ppt
JITTAYASHWANTHREDDY
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
study material
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
ITNet
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 

Similar to Virtual function (20)

Seminar
SeminarSeminar
Seminar
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C questions
C questionsC questions
C questions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
2nd puc computer science chapter 8 function overloading
 2nd puc computer science chapter 8   function overloading 2nd puc computer science chapter 8   function overloading
2nd puc computer science chapter 8 function overloading
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Compose Camp - Intro.pdf
Compose Camp - Intro.pdfCompose Camp - Intro.pdf
Compose Camp - Intro.pdf
 
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
 
OOP in java
OOP in javaOOP in java
OOP in java
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
Object Oriented Programming using C++: Ch11 Virtual Functions.pptxObject Oriented Programming using C++: Ch11 Virtual Functions.pptx
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
 
DS Unit 6.ppt
DS Unit 6.pptDS Unit 6.ppt
DS Unit 6.ppt
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 

More from sdrhr

VIRUSES.pptx
VIRUSES.pptxVIRUSES.pptx
VIRUSES.pptx
sdrhr
 
probability reasoning
probability reasoningprobability reasoning
probability reasoning
sdrhr
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
sdrhr
 
GSM channels wireless
GSM channels  wirelessGSM channels  wireless
GSM channels wireless
sdrhr
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
sdrhr
 
Social
SocialSocial
Social
sdrhr
 
social service
 social service social service
social service
sdrhr
 
Group8 ppt
Group8 pptGroup8 ppt
Group8 ppt
sdrhr
 
Agrobactrium mediated transformation
Agrobactrium mediated transformationAgrobactrium mediated transformation
Agrobactrium mediated transformation
sdrhr
 
GENE MUTATION
       GENE  MUTATION       GENE  MUTATION
GENE MUTATION
sdrhr
 
Defects
DefectsDefects
Defects
sdrhr
 
computer ethics
computer ethicscomputer ethics
computer ethics
sdrhr
 

More from sdrhr (12)

VIRUSES.pptx
VIRUSES.pptxVIRUSES.pptx
VIRUSES.pptx
 
probability reasoning
probability reasoningprobability reasoning
probability reasoning
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
 
GSM channels wireless
GSM channels  wirelessGSM channels  wireless
GSM channels wireless
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
Social
SocialSocial
Social
 
social service
 social service social service
social service
 
Group8 ppt
Group8 pptGroup8 ppt
Group8 ppt
 
Agrobactrium mediated transformation
Agrobactrium mediated transformationAgrobactrium mediated transformation
Agrobactrium mediated transformation
 
GENE MUTATION
       GENE  MUTATION       GENE  MUTATION
GENE MUTATION
 
Defects
DefectsDefects
Defects
 
computer ethics
computer ethicscomputer ethics
computer ethics
 

Recently uploaded

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 

Recently uploaded (20)

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 

Virtual function

  • 1.
  • 2. Programming fundamental Submitted by : Sidra Tahir Submitted to : Ma'am Shumaila Subject : object oriented program Roll no : 165 Class : BSCS Date : 30- 03-2020 Session : 2019-2023 COVT. POST GRADUATE COLLEGE FOR WOMENS GULBERG LAHORE
  • 3. CONTENTS  Polymorphism  Virtual function  Pointer to all object  Abstractconcrete class  Pure virtual class PowerPlugs Templates for PowerPoint Preview 3
  • 4. Polymorphism In object-oriented programming, polymorphism ref ers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
  • 5. Real life Example  A person at the same time can have different characteristic. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism. you have a smartphone for communication. The communication mode you choose could be anything. It can be a call, a text message, a picture message, mail, etc. So, the goal is common that is communication, but their approach is different.
  • 6. Example Of Polymorphism #include<iostream.h> #include<conio.h> class test { clrscr(); private: int n; public: void in() { cout<<"enter a number:"; cin>>n; } Continue……………………
  • 7. void out() { cout<<"the value of n = "<<n; } }; void main() { clrscr(); test*ptr; ptr=new test; ptr->in(); ptr->out(); getch(); } PowerPlugs Templates for PowerPoint Preview 7
  • 8. Output and working of program output Working: The above program declares a class test and a pointer ptr of type test. The pointer can refer to object of the class. The new operator creates an object in the memory and stores the address in ptr. The program then uses the pointer to call the member function of the object being referenced by the pointer. The symbol -> is used to access the member of any object through pointer. The use of dot operator with pointer to access any member is invalid.
  • 9.  Virtual means existing in effect but not really.  A type of function in some part of a program but does not exist really is called virtual function.  A virtual function is defined in the present class and can be overridden in child classes. Virtual function
  • 10. Class class-name { Public: Virtual void member- function-name() { …………. …………... body of base class } }; Syntax of virtual function keyword
  • 11. #include<iostream.h> #include<conio.h> class cbaseclass { public: virtual void sayhello() { cout<<"hello from the cbaseclassnn"; } void sayhi() { cout<<" hi from cbaseclassnn"; } Example
  • 12. program #include<iostream.h> #include<conio.h> class a { public: void disp() { cout<<" n i am from base class a"; } }; class b : public a { public: void disp() { cout<<"n i am from base class b"; } }; continue………. PowerPlugs Templates for PowerPoint Preview 12
  • 13. class c: public b { public: void disp() { cout<<"n i am from base class c"; } }; void main() { a *pa; b objb; c objc; pa=&objb; pa->disp(); pa=&objc; pa->disp(); getch(); } PowerPlugs Templates for PowerPoint Preview 13
  • 14. Output of program output i am from base class a i am from base class a PowerPlugs Templates for PowerPoint Preview 14
  • 15. Working of program The program declares three class a are the parent class and b and c are the child classes. Each class has a member function disp().The disp() function in parent class a is declared as virtual function. The child classes b and c override that member function. The program declares one object of each class. It also declares a pointer ptr of class a. the address of each object is stored in pointer and disp(0 function is called . Each time the disp() function is called, corresponding function execution is executed PowerPlugs Templates for PowerPoint Preview 15
  • 16. A type of virtual function that has no body is known as pure virtual function. A function can be declared as pure virtual function by adding two things:  The keyword virtual at the start of the function declarator.  The =0 at the end of function declaratory. Note: the pure virtual function are used in the classes which are not used directly. The user can inherit the class and then override the pure virtual function in the child class. Pure virtual function
  • 17. Class class-name { Public: Virtual return-type function-name()=0 }; syntax keyword =0 indicate that function is pure virtual function
  • 18. #include<iostream.h> #include<conio.h> Class A { clrscr(); Public: Virtual void disp()=0; }; Class B : public A { void disp() { Cout <<“n I am form derived class B”; }}; Program and Example Class C :public B { Public: Void disp() { Cout<<“n I am form derived class C”; } }; Int main() { B obj b; C obj c; Obj b.disp)(); Obj c.disp(); getch(); } };
  • 19. Output and working of program Output Working: The program declares three class A are the parent class and B and C are the child classes. Each class has a member function disp().The disp() function in parent class A is declared as pure virtual function. The child classes b and c override that member function. The program declares one object of each class and disp(0 function is called . Each time the disp() function is called, corresponding function execution is executed PowerPlugs Templates for PowerPoint Preview 19
  • 20. Abstract class By definition, an abstract class in C++ is a class that has at least one pure virtual function (i.e., a function that has no definition).
  • 21. Syntax abstract Class < class-name> { Public: Abstract void function-name() { ………. } Abstract method } PowerPlugs Templates for PowerPoint Preview 21 keyword
  • 22. Program and Example #include<iostream.h> #include<conio.h> Class abstract interface { Public: Virtual void numbers()=0; Void input(); Int a,b; }; Void abstract interface : : input { Cout<<“enter the two numbers”; Cin>>a>>b; } Continue……………….. PowerPlugs Templates for PowerPoint Preview 22
  • 23. Class add: public abstract interface { Public: Void numbers() { Int sum,a,b; Sum=a+b; Cout<<“sum is << sum<<“n”; } }; Class sub: public abstract interface { Public: Void numbers() { Cout<<“diff is << diff <<“n”; } }; PowerPlugs Templates for PowerPoint Preview 23 int main() { Output Add obj1; Obj1 input(); Obj1 numbers(); Sub obj2; Obj2 input(); Obj2 numbers(); } output
  • 24. Working of program The program declares parent as abstract class interface and the child classes are add and subclass. The child class add override the pure virtual function declared in parent class. It is important to declare a pure virtual function in parent class and override it in all child classes to implement polymorphism. Takin g input in both child classes and then in main function made objects of both child classes as input and numbers. PowerPlugs Templates for PowerPoint Preview 24
  • 25. Abstract class concrete class • Concrete classes are not interface. • Concrete classes can be base or derived. • Pure virtual function are may not present in concrete class.these classes can instantiate the objects. PowerPlugs Templates for PowerPoint Preview 25 • Abstract classes are the interface • Abstract class is generally a base class. • Pure virtual function should be present in the abstract class. • This classes cannot instantiate the facts. Shape 2D shape 3D SHAPE SQAURE CIRCLE TRIANGLE CUBE SPHERE CYLINDER ABSTACT CLASSES CONCRETE CLASSES
  • 26. Pointer to call objects  When accessing members of a class given a pointer to an object, use the arrow (- >) operator instead of dot (.) operator.  Must initialize the pointer before using it.  Pointer athematic is relative to the base type of the pointer.
  • 27. syntax ptr -> member PowerPlugs Templates for PowerPoint Preview 27 It is the name of pointer that reference an object. It is the member access operator that is used to access a member of object. It is the class member to be accessed.
  • 28. Program #include<iostream.h> #incl;ude<conio.h> Class laptop { Int ram; Public: Int usb; Void getdata (int a) { Ram =a; } Void disp() { Cout<<“ram : ” << ram<< endl; Cout<<“usb : ”<< usb < <endl; } }; PowerPlugs Templates for PowerPoint Preview 28 ntI main() { Laptop dell Laptop *pdell = &dell; Pdell -> usb = 3; Pdell->getdata(20); Pdell-> disp() Getch(); } Output
  • 29. Working of program The program declares a class laptop and a pointer pdell of type laptop. The pointer refer the object of the class. The new operator creates an object in the memory and stores the address in pdell. The program then uses the pointer to call the member function of the object being referenced by the pointer. The symbol -> is used to access the member of any object through pointer. PowerPlugs Templates for PowerPoint Preview 29
  • 30. PowerPlugs Templates for PowerPoint Preview 30