欢迎来到天天文库
浏览记录
ID:38270118
大小:28.00 KB
页数:3页
时间:2019-06-07
《对复数类重载运算符,使得能够取复数的模和共轭》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、对复数类重载运算符,使得能够取复数的模和共轭。//complex.hclasscomplex{private:doublereal,imag;public:complex(doubler=0,doublei=0):real(r),imag(i){}frienddoubleoperator+(complexc);friendcomplexoperator-(complexc);voiddisplay();};//complex.cpp#include#include"complex.h"#include"math.h"usingnames
2、pacestd;doubleoperator+(complexc){doubletemp;temp=c.real*c.real+c.imag*c.imag;temp=sqrt(temp);returntemp;}complexoperator-(complexc){complextemp;temp.real=c.real;temp.imag=0-c.imag;returntemp;}voidcomplex::display(){cout<=0)cout<<"+"<3、/main.cpp#include#include"complex.h"usingnamespacestd;voidmain(){doublec1;complexc(6,-8),c2;c1=+c;cout<<"复数的模为:"<
3、/main.cpp#include#include"complex.h"usingnamespacestd;voidmain(){doublec1;complexc(6,-8),c2;c1=+c;cout<<"复数的模为:"<
此文档下载收益归作者所有