中易网

复数能进行模加运算么

答案:2  悬赏:20  
解决时间 2021-02-15 05:45
复数能进行模加运算么
最佳答案
mod(x,y)运算只能对实数进行。因为复数的取模运算,没有定义,实在要做只有自己根据所定义的mod来编写函数。
全部回答

//设计一个复数类,可以进行复数的加、减、乘、法、除、取模、乘方、求2个复数向量之间的夹角等运算。 #include <iostream> #include <cmath> #include <cstdlib> using namespace std; class complex { private:  float real;  float imag; public: //构造函数  complex()  {   real=0;   imag=0;  }  complex(float a,float b):real(a),imag(b){}  //复数输出  void display(); //取模运算  float mode(); //复数的四则运算  complex operator+(complex &a);  complex operator-(complex &a);  complex operator*(complex &a);  complex operator/(complex &a); //复数乘方  complex power(int n); //计算夹角  float  includedangle(complex &a); }; void complex::display () {  cout<<"this complex is:";  if(imag>=0)   cout<<real<<'+'<<imag<<'i'<<endl;  else   cout<<real<<imag<<'i'<<endl;  cout<<"mode is:"<<mode()<<endl; } float complex::mode() {  return (sqrt(real*real+imag*imag)); }

complex complex::operator+(complex &a) {  complex temp;  temp.real = real + a.real ;  temp.imag = imag + a.imag ;  return temp; } complex complex::operator-(complex &a) {  complex temp;  temp.real =real - a.real ;  temp.imag =imag - a.imag ;  return temp ; } complex complex::operator*(complex &a) {  complex temp;  temp.real = real*a.real - imag*a.imag;  temp.imag = real*a.imag + a.real*imag;  return temp; } complex complex::operator/(complex &a) {  complex temp;  if(a.real!=0 && a.imag!=0)  {   cout<<"error!"<<endl;  }  else  {   temp.real = (real*a.real - imag*(-a.imag))/(a.real*a.real + a.imag*imag);   temp.imag = (real*(-a.imag) + a.real*imag)/(a.real*a.real + a.imag*imag);  }  return temp; } complex complex::power (int n) {  complex temp;  temp=*this;  for(int i=1;i<n;i++)  {   temp=(*this)*temp;  }  return temp; } float complex::includedangle(complex &a) { //tanθ=|(k2- k1)/(1+ k1*k2)|  float b,k1,k2;  if(real!=0 && a.real!=0)  {   k1=imag/real;   k2=a.imag/a.real;   b=atan(fabs((k2-k1)/(1+k1*k2)));  }  else   if(real==0 && a.real!=0)   {    k2=a.imag/a.real;    b=atan(fabs(k2));   }   else if(real!=0 && a.real==0)   {    k1=imag/real;    b=atan(fabs(k1));   }   else    b=0;  return b; }

我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
家里的老鼠太烦了!又是咬东西有事乱拉屎!为
一排火柴棍摆成扇形的图片是什么
在家中给长2.2M,宽4dM,高80cm的柜子装铝合金,
亲戚介绍认识一个女孩,微信上跟她聊天,从不
没有邮箱怎么注册淘宝号
tgt火线助手为什么安装不上
谁知道苹果直营店里iphone样机上的图片(那种
合资车中的SUV,是买标致3008还是福特翼虎?
吃嘎啦肉与西瓜相克吗
学信网上面的学籍档案如何取消?
8年纪中学生学习报第13期答案
办理一卡双号业务怎么收费?
玉旗大酒店地址有知道的么?有点事想过去
王者荣耀,露娜连招1323a三下再3,13a2a3a3,
谈谈CSS Sprite是什么?及这个技术的优缺点。
推荐资讯
杭州九堡到屯溪的班车是几点
韩国首尔韩国语第二册的单词
商丘有哪些比较便宜的宾馆?
我想换系统,但电脑上已经装有很多重要文件,
现在手机CPU哪些不错?排名先后说一下,另外
fc游戏、主角武器是回力镖、每过一关都可以有
迎凤楼地址在哪,我要去那里办事
[第394个问答]左宗棠一对联。您能给出对应
村支书以建校为名,无赏征收村民土地,是否违
贝智高多少钱一盒?
我贷款买车,合同汽车金融公司打错了,当时打
如果残疾人进德邦上班,待遇是怎么样的
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?