程序没错误 ,但是运行不正确!请大家帮看一下!谢谢啦!
#include <iostream>
#include<cmath>
using namespace std;
#define size 20
class Base
{public: virtual void area()=0;
};
class triangle:public Base
{private: int la,lb,lc;
float s;
public:triangle(int a,int b,int c){la=a;lb=b;lb=c;}
void area(){int n=(la+lb+lc)/2;
cout<<"Èý½ÇÐεÄÃæ»ýÊÇ:"<<endl;
s=sqrt(n*(n-la)*(n-lb)*(n-lc));}
};
class rectangle:public Base
{private: int length,width;
float s;
public:
rectangle(int a,int b){length=a;width=b;}
void area(){;
cout <<"¾ØÐεÄÃæ»ýÊÇ:"<<endl;
s=length*width;
}
};
class circle :public Base
{private: int radius;
float s;
public :
circle(int n){radius=n;}
void area(){
cout <<"Ô²ÐεÄÃæ»ýÊÇ:"<<endl;
s=3.14*radius*radius;
}
};
void main()
{
int a1,a2,a3,a4,a5,a6;
Base *a[size];
for (int i=0;i<size;i++)
{
int c=int(rand()*2+1);
switch(c)
{case 1:
cout<<"ÇëÊäÈëÈý¸ö±ß:"<<endl;
cin>>a1;
cin>>a2;
cin>>a3;
a[i]=new triangle(a1,a2,a3);
break;
case 2:
cout<<"ÇëÊäÈëÁ½¸ö±ß:"<<endl;
cin>>a4;
cin>>a5;
a[i]=new rectangle (a4,a5);
break;
case 3:
cout<<"ÇëÊäÈë°ë¾¶:"<<endl;
cin>>a6;
a[i]=new circle(a6);
break;
}
}
for( i=0;i<size;i++)
a[i]->area();
for( i=0;i<size;i++)
delete a[i];
}