Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to illustrate an example of Polymorphism ( Pure Virtual functions ).

Posted By: Easy Tutor     Category: C++ Programming     Views: 5001

A C++ Program to illustrate an example of Polymorphism ( Pure Virtual functions ).

Code for Program to illustrate an example of Polymorphism ( Pure Virtual functions ). in C++ Programming

 #include<iostream.h>
 #include<graphics.h>
 #include<stdlib.h>
 #include<conio.h>


 /*************************************************************************///------------------------------  shape  --------------------------------///*************************************************************************/class shape
    {
       public:
        virtualvoid draw()=0;
    };

 /*************************************************************************///--------------------------  draw_rectangle  ---------------------------///*************************************************************************/class draw_rectangle:public shape
    {
       public:
        void draw()  { rectangle(225,225,180,180);  }
    };

 /*************************************************************************///---------------------------  draw_arc  --------------------------------///*************************************************************************/class draw_arc:public shape
    {
       public:
        void draw()  { arc(200,200,45,135,100);  }
    };

 /*************************************************************************///---------------------------  draw_circle  -----------------------------///*************************************************************************/class draw_circle:public shape
    {
       public:
        void draw()  { circle(200,200,60);  }
    };


 main()
    {
       int driver=VGA;
       int mode=VGAHI;
       int error_code;

       initgraph(&driver,&mode,"..\\Bgi");

       error_code=graphresult( );

       if(error_code!=grOk)
          {
             restorecrtmode( );
             textmode(BW80);
             clrscr( );

             cout<<" \n Fatal Error  : Graphic Driver not initialized"<<endl;
             cout<<" Error Reason : "<<grapherrormsg(error_code)<<endl;
             cout<<" \n Press any key to exit...";

             getch( );
             exit(1);
          }

       shape *ptr;
       draw_rectangle r;
       draw_arc a;
       draw_circle c;

       ptr=&r;
       ptr->draw();

       ptr=&a;
       ptr->draw();

       ptr=&c;
       ptr->draw();

       getch();
       closegraph();
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to illustrate an example of Polymorphism ( Pure Virtual functions ). is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!