Pure Virtual Function Assignment Help

Assignment Help: >> Polymorphism - Pure Virtual Function

Pure Virtual Function

A pure virtual function is a category of function that has only a function declaration. That does not have the function definition. The subsequent program describes how to declare a pure virtual function

// pure virtual function

# include<iostream.h>

class base

{

private:

int x;

float y;

public:

};

virtual void getdata( );

virtual void display( );

class derivedB : public base

{

private:

int rollno;

char name[20];

public:

};

void getdata ( );

void display ( );

void base :: getdata ( )

{

}

void base :: display( )

{

}

void derivedB :: getdata ( )

{

cout <<"enter roll number \n";

cin >> rollno;

cout<< "enter name \n";

cin>> name;

}

void derivedB :: display ( )

{

cout << "roll number  student's name \n";

cout << roll no << '\t' << name << endl;

}

void main ( )

{

base *ptr; derivedB obj; ptr = &obj;

ptr-> getdata ( );

ptr -> display ( );

}

Output of the program is

Enter roll number

89001

enter name ganapathy

rollnumber    student's name

89001  ganapathy

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd