PROGRAM TO IMPLEMENT THE CONCEPT OF PURE VIRTUAL FUNCTIONS

/*PROGRAM TO IMPLEMENT THE CONCEPT OF PURE VIRTUAL FUNCTIONS*/

#include<conio.h>

#include<iostream.h>

#include<stdio.h>

class base

{

public:

virtual void input()=0;

virtual void output()=0;

};

class derived:public base

{

char name[15];

int roll_no,age;

public:

void input()

{

cout<<“Enter name of the student: “;

gets(name);

cout<<“Enter roll no of the student: “;

cin>>roll_no;

cout<<“Enter age of the student: “;

cin>>age;

}

void output()

{

cout<<“Name: “<<name<<endl;

cout<<“Roll no: “<<roll_no<<endl;

cout<<“Age: “<<age<<endl;

}

};

void main()

{

base *ptr;

derived d1;

clrscr();

ptr=&d1;

ptr->input();

cout<<“Data of student is: “<<endl;

ptr->output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *