ABSTRACT CLASS
SUBJECT:PROGRAMMING WITH C++
SUBJECT CODE:15BCI303
CLASS:II B.COM IT
ACADEMIC YEAR:2018-2019 ODD
DATE:28/7/2018
HOUR:1
28/7/2018 1
ABSTRACT CLASS
OVERVIEW OF ABSTRACT CLASS?
 What is abstract class?
 How to make abstract class ?
 How to use abstract class ?
 Importance of abstract class ?
28/7/2018 2
ABSTRACT CLASS
WHAT IS ABSTRACT CLASS?
Abstract class :
 An abstract class is a class that is designed to
be specific used as a base class .
 we can’t create objects of abstract classes.
 An abstract class contains at least one pure
base class.
28/7/2018 3
ABSTRACT CLASS
HOW TO MAKE ABSTRACT CLASS?
 An abstract class contains at least one pure virtual
function. Declare a pure virtual function by using a
pure specifier (= 0) in the declaration of a virtual
member function.
The following is an example of an abstractclass:
class abstract
{
public:
virtual void f() = 0; //pure virtual function that
};
28/7/2018 4
ABSTRACT CLASS
HOW TO USE ABSTRACT CLASS ?
//this is simple program of abstract class.
//pure virtual member
#include <iostream>
using namespace std;
class Abstract {
int x, y;
public:
virtual void setData(int x = 0, int y = 0) = 0;
virtual void printData() = 0;
};
class Derived : public Abstract {
int x, y;
public:
void setData(int a= 0, int b= 0)
{
x = a;
y = b;
}
28/7/2018 5
ABSTRACT CLASS
void printData()
{
cout << "Derived::x = " << x << endl
<< "Derived::y = " << y << endl;
}
};
int main()
{
Derived d;
//new data set.
d.setData(10, 20);
cout << “Set New data " << endl;
d.printData();
}
OUTPUT:
Set New data:
Derived::x =10
Derived::y=20
28/7/2018 6
ABSTRACT CLASS
IMPORTANCE OF ABSTRACT CLASS?
 An abstract class as a base class is needed
when there is functionality that is desired for
all objects that have a type deriving from
Abstract Class, but we cannot be
implemented on the Abstract Class itself.
28/7/2018 7
ABSTRACT CLASS
THANK YOU
28/7/2018 8
ABSTRACT CLASS

Abstract class used in C++-its importance

  • 1.
    ABSTRACT CLASS SUBJECT:PROGRAMMING WITHC++ SUBJECT CODE:15BCI303 CLASS:II B.COM IT ACADEMIC YEAR:2018-2019 ODD DATE:28/7/2018 HOUR:1 28/7/2018 1 ABSTRACT CLASS
  • 2.
    OVERVIEW OF ABSTRACTCLASS?  What is abstract class?  How to make abstract class ?  How to use abstract class ?  Importance of abstract class ? 28/7/2018 2 ABSTRACT CLASS
  • 3.
    WHAT IS ABSTRACTCLASS? Abstract class :  An abstract class is a class that is designed to be specific used as a base class .  we can’t create objects of abstract classes.  An abstract class contains at least one pure base class. 28/7/2018 3 ABSTRACT CLASS
  • 4.
    HOW TO MAKEABSTRACT CLASS?  An abstract class contains at least one pure virtual function. Declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function. The following is an example of an abstractclass: class abstract { public: virtual void f() = 0; //pure virtual function that }; 28/7/2018 4 ABSTRACT CLASS
  • 5.
    HOW TO USEABSTRACT CLASS ? //this is simple program of abstract class. //pure virtual member #include <iostream> using namespace std; class Abstract { int x, y; public: virtual void setData(int x = 0, int y = 0) = 0; virtual void printData() = 0; }; class Derived : public Abstract { int x, y; public: void setData(int a= 0, int b= 0) { x = a; y = b; } 28/7/2018 5 ABSTRACT CLASS
  • 6.
    void printData() { cout <<"Derived::x = " << x << endl << "Derived::y = " << y << endl; } }; int main() { Derived d; //new data set. d.setData(10, 20); cout << “Set New data " << endl; d.printData(); } OUTPUT: Set New data: Derived::x =10 Derived::y=20 28/7/2018 6 ABSTRACT CLASS
  • 7.
    IMPORTANCE OF ABSTRACTCLASS?  An abstract class as a base class is needed when there is functionality that is desired for all objects that have a type deriving from Abstract Class, but we cannot be implemented on the Abstract Class itself. 28/7/2018 7 ABSTRACT CLASS
  • 8.