函数题:复数排序 - C/C++ 操作符重载
设计符合下述要求的Complex复数类,使得下述程序可以正常运行:自定义>操作符函数,使得两个复数对象可以通过>操作符以“模”为基础进行大小比较。
要求:Complex的实部和虚部成员均使用double类型。
### 裁判测试程序样例:
c++
#include <iostream>
#include <cmath>
using namespace std;
//此处定义Complex类其及operator>()自定义操作符函数
int main()
{
const int N = 10;
Complex a[N];
for (int i=0;i<N;i++)
cin >> a[i].dReal >> a[i].dImage;
//使用冒泡排序算法进行排序
for (int i=N-1;i>0;i--)
for (int j=0;j<i;j++){
if (a[j]>a[j+1]){
auto t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
printf("Sorted array of complexes:\n");
for (int i=0;i<N;i++)
printf("(%.1f,%.1f),",a[i].dReal,a[i].dImage);
return 0;
}
### 输入样例:
in
1.1 3.3
2.3 2.1
7.4 7.6
6.1 0.1
4.4 4.4
5.6 7.8
10.1 23.2
0.1 0.2
56.12 78.2
4.2 2.1
说明:依次输入10个复数的实部和虚部
### 输出样例:
out
Sorted array of complexes:
(0.1,0.2),(2.3,2.1),(1.1,3.3),(4.2,2.1),(6.1,0.1),(4.4,4.4),(5.6,7.8),(7.4,7.6),(10.1,23.2),(56.1,78.2),
请注意:函数题只需要提交相关代码片段,不要提交完整程序。
### 感觉不会? 那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)

答案:若无答案欢迎评论