#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
0 comments:
Post a Comment