一.问题描述:
建立一个复数类,实数和虚数是其私有数据成员。建立一个>(大于号)的运算符重载,比较两个复数间模的大小。
二.代码输入:
#include "iostream" using namespace std; class Fu { public: double shi; double xv; void set() { cin>>this->shi; cin>>this->xv; } double fun1() { return this->shi; } double fun2() { return this->xv; } friend void operator>(Fu x,Fu y) { if(x.xv*x.xv+x.shi*x.shi>y.xv*y.xv+y.shi*y.shi) cout<<"true"<<endl; else cout<<"false"<<endl; } }; int main() { Fu x[1000]; int i=0; while(1) { x[i].set(); x[i+1].set(); if(x[i].fun1() || x[i].fun2() || x[i+1].fun2() || x[i+1].fun1()) { x[i]>x[i+1]; } else return 0; i+=2; } }
标签:return,Fu,double,复数,shi,xv,比较 From: https://www.cnblogs.com/lzh0416/p/17396437.html