Find us On Facebook

Showing posts with label Pure virtual function. Show all posts
Showing posts with label Pure virtual function. Show all posts

Wednesday, April 6, 2011

W.A.P to use of pure virtual function


#include<iostream.h>
#include<conio.h>
            class cpolygon {
                        protected:
                                    int l,h;
                        public:
                                    void setval(int a, int b){
                                                l=a;
                                                h=b;
                                    }
                                    virtual int area(void)=0;
            };
            class crectangle : public cpolygon {
                        public:
                                    int area(void) {
                                                return(l*h);
                                    }
            };
            class ctriangle : public cpolygon {
                        public:
                                    int area(void) {
                                     return((l*h)/2);
                                     }
            };

void main() {
            clrscr();
            crectangle crect;
            ctriangle tangle;
            cpolygon *cpoly;
            cpolygon *poly1 = &crect;
            cpolygon *poly2 = &tangle;

            poly1->setval(4,5);
            poly2->setval(4,5);

            cout<<"Area : = "<<poly1->area();
            cout<<"\nArea : = "<<poly2->area();

            getch();
}



OUTPUT:-



Area : = 20
Area : = 10

Programms

C,C++,VB, PL/SQL EBOOK SEARCH ENGINE