#include<iostream> using namespace std; class CPoint { private: double x,y; public : CPoint (double i,double j); double Getx(); double Gety(); double Setpoint(double i,double j); }; class CShape { public: CPoint point; virtual double Area() { return 0.0; } }; class CCircle:public CShape { public: float r; CCircle(CPoint p1,float r=2):r(r){} double Area() { return 3.14*r*r; } }; class CRect:public CShape { public: double x; double y; CRect(CPoint p1,double x=2,double y=1):x(x),y(y) {} double Area() { return x*y; } }; class CEll:public CShape { double x; double y; CEll(CPoint p1,double x=2,double y=1); double Area() { return 3.14*x*y; } }; int main() { return 0; }有什么问题?怎么改正?
时间: 2023-12-06 08:03:52 浏览: 124
这段代码存在一个问题,即CEll类的构造函数是私有的,无法在main函数中创建CEll对象。需要将CEll类的构造函数改为公有的。
修改后的代码如下:
```
#include<iostream>
using namespace std;
class CPoint {
private:
double x,y;
public :
CPoint (double i,double j);
double Getx();
double Gety();
double Setpoint(double i,double j);
};
class CShape {
public:
CPoint point;
virtual double Area()
{
return 0.0;
}
};
class CCircle:public CShape {
public:
float r;
CCircle(CPoint p1,float r=2):r(r){}
double Area()
{
return 3.14*r*r;
}
};
class CRect:public CShape {
public:
double x;
double y;
CRect(CPoint p1,double x=2,double y=1):x(x),y(y) {}
double Area()
{
return x*y;
}
};
class CEll:public CShape {
public:
double x;
double y;
CEll(CPoint p1,double x=2,double y=1):x(x),y(y){}
double Area()
{
return 3.14*x*y;
}
};
int main() {
return 0;
}
```
阅读全文