#include<iostream.h>
class cshape
{
public:
cshape();
virtual int area()=0;
virtual void setshape(int number)=0;
~cshape();
private:
int number;
};
void cshape::setshape(int number)
{
switch(number)
{
case 1:cout<<"It is a triangle"<<endl;break;
case 2:cout<<"It is a crect"<<endl;break;
case 3:cout<<"It is a circle"<<endl;break;
};
}
class ctriangle:public cshape
{
public:
ctriangle();
float triangle(float het,float bot){
return ((float)(0.5*het*bot));
};
~ctriangle();
};
class ccrect:public cshape
{
public:
ccrect();
float crect(float size1,float size2){
return (size1*size2);
};
~ccrect();
};
class ccircle:public cshape
{
public:
ccircle();
double circle(float line){
return (3.14159*line);
};
~ccircle();
};
int main()
{
cshape *pshape;
ctriangle *a;
cout<<a->triangle(3,3)<<endl;
pshape->setshape(1);
ccrect *b;
cout<<b->crect(2,3)<<endl;
ccircle *c;
cout<<c->circle(3.5)<<endl;
cout<<a->triangle(3,3)+b->crect(2,3)+c->circle(3.5)<<endl;
return 0;
}
在这有一个运行错误问题,应该怎样改正呢.