↑ 收起筛选 ↑
用C/C++实现:输入一个复数,如A+Bi、A%Bi,要求将...
2020-09-15

先定义一个数组,然后通过c++中的运算符重载实现复数相加.具体怎么重载你还是看书吧更确切点,然后将得到的结果赋予给数组

提供两个方法,方法1:int a,b;scanf("%d+%di",&a,&b);方法2:int a,b;string str;cin>>str;for(int i=0;i<str.length();i++){ if(str[i]=='+' || str[i]=='i') str[i]=' ';}stringstream ss(str);ss>>a>>b;

#include#include main() { int i,x; int a[2]={0},b[2]={0},sum[2]; char c[30],d[30]; printf("the frist number:\n"); gets(c); printf("the second number:\n"); gets(d); a[0]=c[0]-'0'; for(i=1;c[i]!='+';i++) a[0]=a[0]*10+c[i]-'0'; i++; a[1]=c[i]-'0'; i++ ; for(;c[i]!='i';i++) a

提供两抄个方法袭,方法百1:int a,b;scanf(&度quot;%问d+%di",&a,&b);方法答2:int a,b;string str;cin>>str;for(int i=0;i<str.length();i++){ if(str[i]=='+' || str[i]=='i') str[i]=' ';}stringstream ss(str);ss>>a>>b;

#includeusing namespace std;class complex{private: double real,imag;public: complex(int r=0.0,int i=0.0) {real=r; imag=i; } ~complex(){} void input() {cin>>real>>imag; } void output() {cout>choose; complex c1,c2,c3; switch(choose) { case 1:cout 评论0 0 0

class Complex{ private: int a; int b; public: Complex(){ a = 0; b = 0; } Complex(int x, int y){ a = x; b = y; } Complex& operator+(Complex c){ a = a + c.a; b = b + c.b; return *this; } Complex& operator-(Complex c){ a = a - c.a; b = b - c.b; return *this; } };

设z=a+bi,则z平方=a平方-b平方+2abi=-3+4i,即a平方-b平方=-3,2ab=4,解得a=1,b=2,或a=-1,b=-2

//complex类#include#includeclass complex{ double real,imag;public: complex(){real=5;imag=5;}//缺省构造函数 complex(double r){real=r;imag=0;}//只给实部赋值的构造函数 complex(double r,double i){real=r;imag=i;}//同时给实、虚部赋值的函数

#include<iostream> using std::cout; using std::cin; class Complex { double m_r, m_v; public: Complex(double r=0, double v=0); friend Complex operator+(const Complex&, const Complex&); friend std::ostream& operator<<(std::ostream&, const

[图文] 将复数 表示为a+bi(a,b∈R,i为虚数单位)的形式为( ) 悬赏: 0 答案豆 提问人: 匿名网友 您可能感兴趣的试题 (1i) 10 (i为虚数单位)的二项展开式中的第七项为 [ ] A.210 B.210 C.120i D.120i 已知

延伸阅读: