c++圆类定义如下,重载输入、输出运算符为友元函数,重载算术减法运算符为成员函数,参考给出代码进行填空
时间: 2024-05-08 09:20:52 浏览: 120
```
#include <iostream>
using namespace std;
class Circle {
private:
double radius;
public:
Circle(double r = 0) : radius(r) {}
friend istream& operator>>(istream& in, Circle& c) {
// TODO: 完成输入运算符的重载
return in;
}
friend ostream& operator<<(ostream& out, const Circle& c) {
// TODO: 完成输出运算符的重载
return out;
}
Circle operator-(const Circle& c) {
// TODO: 完成算术减法运算符的重载
}
};
int main() {
Circle c1, c2;
cin >> c1 >> c2;
cout << "c1 = " << c1 << endl;
cout << "c2 = " << c2 << endl;
Circle c3 = c1 - c2;
cout << "c1 - c2 = " << c3 << endl;
return 0;
}
istream& operator>>(istream& in, Circle& c) {
double r;
in >> r;
c.radius = r;
return in;
}
ostream& operator<<(ostream& out, const Circle& c) {
out << c.radius;
return out;
}
Circle Circle::operator-(const Circle& c) {
Circle temp(radius - c.radius);
return temp;
}
```
阅读全文