各位大哥大姐帮个忙啊!
这个程序在VC++上运行结果是正确的.但是在我们学校的交题系统却是编译错误:
Compile Error
54583\Main.cc: In function `int main()':
54583\Main.cc:68: error: no matching function for call to `Circle::Circle(int&, int&, Circle&)'
54583\Main.cc:32: note: candidates are: Circle::Circle(const Circle&)
54583\Main.cc:35: note: Circle::Circle(int, int, int)
Sample Input
R 10 20 10 20
C 20 10 10
R 3 3 4 5
E
Sample Output
Rectangle 1: Area=200 Perimeter=60 point=(10,20)
Circle 2: Area=314.159 Perimeter=62.8318 center point=(20,10)
Rectangle 3: Area=20 Perimeter=18 point=(3,3)
我的源代码如下:
#include<iostream.h>
#define PI 3.14159
class shape
{
int x,y;
public:
shape(int a,int b)
{x=a,y=b;}
virtual double GetArea()=0;
virtual double GetPerim()=0;
virtual void show()=0;
int getx()
{return x;}
int gety()
{return y;}
};
class Rectangle:public shape
{
protected:
int w,h;
public:
Rectangle(int a,int b,int c,int d);
double GetArea()
{return w*h;}
double GetPerim()
{return 2*(w+h);}
void show()
{cout<<": Area="<<GetArea()<<" Perimeter="<<GetPerim()<<" point=("<<shape::getx()<<","<<shape::gety()<<")"<<endl;}
};
Rectangle::Rectangle(int a,int b,int c,int d):shape(a,b),w(c),h(d)
{}
class Circle:public shape
{
protected:
int radius;
public:
Circle(int a,int b,int c):shape(a,b)
{radius=c;}
double GetArea()
{return PI*radius*radius;}
double GetPerim()
{return 2*PI*radius;}
void show()
{cout<<": Area="<<GetArea()<<" Perimeter="<<GetPerim()<<" center point=("<<shape::getx()<<","<<shape::gety()<<")"<<endl;}
};
int main()
{
int a,b,c,d,n=1;
//Rectangle r;
//Circle c;
char ch;
shape *p;
while(cin>>ch)
{
if(ch=='E') break;
if(ch=='R')
{
cin>>a>>b>>c>>d;
Rectangle r(a,b,c,d);
p=&r;
cout<<"Rectangle "<<n;
p->show();
//cout<<": Area="<<p->GetArea()<<" Perimeter="<<p->GetPerim()<<" point=("<<a<<","<<b<<")"<<endl;
n++;
// break;
}else if(ch=='C')
{
cin>>a>>b>>c;
Circle c(a,b,c);
p=&c;
cout<<"Circle "<<n;
p->show();
//cout<<": Area="<<p->GetArea()<<" Perimeter="<<p->GetPerim()<<" center point=("<<x<<","<<y<<")"<<endl;
n++;
// break;
}
}
return 0;
}