c++复数计算器(四则运算+坐标模长、角度表示) |
您所在的位置:网站首页 › 计算器求复数的模 › c++复数计算器(四则运算+坐标模长、角度表示) |
用类实现的简单复数计算器 废话少说,直接上代码 #include #include #define PI acos(-1) using namespace std; class complex { friend complex operator +(complex c1, complex c2); friend complex operator -(complex c1, complex c2); friend complex operator *(complex c1, complex c2); friend complex operator /(complex c1, complex c2); friend ostream& operator return complex(c1.real - c2.real, c1.imag - c2.imag); } complex operator *(complex c1, complex c2) { return complex(c1.real * c2.real-c1.imag*c2.imag, c1.real * c2.imag + c1.imag * c2.real); } complex operator /(complex c1, complex c2) { return complex((c1.real * c2.real + c1.imag * c2.imag)/(c2.real*c2.real+c2.imag*c2.imag), (c2.real * c1.imag - c1.real * c2.imag) / (c2.real * c2.real + c2.imag + c2.imag)); } ostream& operator opt cout c.real = c.mould * cos(c.angle * PI /180); c.imag = c.mould * sin(c.angle * PI /180); } int main() { int a = 1, flagg=1; while (a != 0) { cout double a1, a2, a3, a4; case 0: cout a2; cout a3 >> a4; if (flagg == 1) { complex c1(a1, a2), c2(a3, a4); complex c3(c1 + c2); cout complex c1(a1, a2), c2(a3, a4); complex c3(c1 - c2); c3.conversion1(c3); cout complex c1(a1, a2), c2(a3, a4); complex c3(c1 * c2); c3.conversion1(c3); cout complex c1(a1, a2), c2(a3, a4); complex c3(c1 / c2); c3.conversion1(c3); cout |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |