参考答案:

需要在Point类和Circle类中重载运算符<<和>>,实现文件读写操作。

Point类重载运算符<<和>>:

ostream & operator << (ostream &out, const Point &p) //运算符<<重载 { out << p.x << " " << p.y << endl; return out; }

istream & operator >> (istream &in, Point &p) //运算符>>重载 { in >> p.x >> p.y; return in; }

Circle类重载运算符<<和>>:

ostream & operator << (ostream &out, const Circle &c) //运算符<<重载 { out << c.getX() << " " << c.getY() << " " << c.getR() << endl; return out; }

istream & operator >> (istream &in, Circle &c) //运算符>>重载 { double x, y, r; in >> x >> y >> r; c.setX(x); c.setY(y); c.setR(r); return in; }

完整代码如下

基于Point类及平面基类Plane类设计圆类Circle并为Point类和Circle重载实现和运算符mainvoid函数实现Point对象和Circle对象的文件读写操作。###裁判测试程序样例:#include iostream#include fstreamusing namespace std;点类Pointclass Pointprivate double x; doubl

原文地址: https://www.cveoy.top/t/topic/fEFB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录