本人由于水平有限,希望大家帮我解决一下,谢谢了!
#include <iostream>
#include<cmath>
using namespace std;
class point {
private:
int x;
int y;
public :point (int a,int b){x=a;y=b;}
int getx(){return x;}
int gety(){return y;}
point (point &m)
{x=m.x;
y=m.y;}
};
class Base
{public: virtual float area(){};
};
class triangle:public Base
{private: point A1,A2,A3;
float area;
public:triangle(point a,point b,point c):A1(a),A2(b)A3(c){}
float area(){int m1=sqrt((A1.x-A2.x)*(A1.x-A2.x)+(A1.y-A2.y)*(A1.y-A2.y));
int m2=sqrt((A1.x-A3.x)*(A1.x-A3.x)+(A1.y-A3.y)*(A1.y-A2.y));
int m3=sqrt((A2.x-A3.x)*(A2.x-A3.x)+(A2.y-A3.y)*(A2.y-A3.y));
int n=(m1+m2+m3)/2;
cout<<"Èý½ÇÐεÄÃæ»ýÊÇ:"<<endl;
return area=sqrt(n*(n-m1)*(n-m2)*(n-m3));
}
};
class rectangle:public Base
{private: point A1,A2;
float area;
public:
rectangle(point a,point b):A1(a),A2(b){}
float area(){int a=A1.x-A2.x;
int b=A1.y-A2.y;
cout <<"¾ØÐεÄÃæ»ýÊÇ:"<<endl;
return area=a*b;
}
};
class circle :public Base
{private: int radius;
float area;
public :
circle(int n){radius=n;}
float area(){
cout <<"Ô²ÐεÄÃæ»ýÊÇ:"<<endl;
return area=3.14*radius*radius;
}
};
void main()
{int *c;
int x1,x2,x3,y1,y2,y3;
for(int i=0;i<20;i++)
{
c=int(rand*2+1);
Base a[20];
switch(c)
{case '1':
{cout<<"ÇëÊäÈëÈý¸öµãµÄ×ø±ê:"<<endl;
cin>>x1;
cin>>x2;
cin>>x3;
cin>>y1;
cin>>y2;
cin>>y3;
point m1(x1,y1),m2(x2,y2),m3(x3,y3);
triangle tr(m1,m2,m3);
a[i]=tr;
break;}
case '2':
{cout<<"ÇëÊäÈëÁ½¸öµãµÄ×ø±ê:"<<endl;
cin>>x1;
cin>>x1;
cin>>y1;
cin>>y2;
point a1(x1,y1),a2(x2,y2);
rectangle rec(a1,a2);
a[i]=rec;
break;}
case '3':
{int m;
cout<<"ÇëÊäÈë°ë¾¶:"<<endl;
cin>>m;
circle cir(m);
a[i]=cir;
break;}
}
}
for( i=0;i<20;i++)
cout <<a[i].area()<<endl;
}
错误调试:
ompiling...
3333.cpp
d:\33333\3333.cpp(24) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(38) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(49) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(59) : error C2296: '*' : illegal, left operand has type 'int (__cdecl *)(void)'
d:\33333\3333.cpp(59) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Ö´ÐÐ cl.exe ʱ³ö´í.
3333.obj - 1 error(s), 0 warning(s)