c++ program to virtual function

#include <iostream> using namespace std; class shape { public:double x,y; void getdata() { cout<<"enter x and y\n"; cin>>x>>y; } virtual void display_area()=0; }; class triangle: public shape { public:double area; void display_area() { area=(x*y)/12; cout<<"triangle="<<area; } }; class rectangle:public shape { public:double area; void display_area() { area=x*y; cout<<"rectangle="<<area; } }; int main() { triangle t; rectangle r; shape * sptr; sptr->getdata(); sptr->display_area(); sptr=&r; sptr->getdata(); sptr->display_area(); return(0); }