C++:运算符重载2(双目:复数的减法)
来源:互联网 发布:linux nmon 编辑:程序博客网 时间:2024/03/29 21:41
运算符重载2(双目:复数的减法)
Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByte
Total Submit:460 Accepted:298
Description
定义复数类,用友元函数重载复数的减法。
Input
输入数据有若干行。每行上有四个整数,前两个表示一个复数的实部和虚部,后两个表示另一个复数的实部和虚部。
Output
对于每一组数据,输出两复数的差,格式参照样例输出。
Sample Input
1 2 3 4
4 3 2 1
1 2 3 2
3 2 3 1
Sample Output
-2-2i
2+2i
-2+0i
0+1i
代码块:
#include<iostream>using namespace std;class complex{ double real,image;public: complex(double r=0,double i=0) { real=r; image=i; } friend complex operator-(complex &a); //friend complex operator+(double n,complex &a); //friend complex operator+(complex &a,double n); void disp() { if(image<0) cout<<real<<image<<"i"<<endl; else cout<<real<<"+"<<image<<"i"<<endl; }complex operator-(complex&a){ real=real-a.real; image=image-a.image; return complex(real,image);}};int main(){ int a,b,c,d; double t,tt; while (cin>>a>>b>>c>>d) { complex a1(a,b),a2(c,d),a3; a3=a1-a2; a3.disp(); } return 0;}
1 0
- C++:运算符重载2(双目:复数的减法)
- [c++]复数的运算符重载
- 【C++】复数的运算符重载
- 双目运算符的重载
- 双目运算符的重载
- 双目运算符重载
- 重载双目运算符
- 双目运算符重载
- 双目运算符重载
- 复数运算符的重载
- 双目运算符+=的重载
- C++复数运算的运算符重载
- C++运算符重载----复数的运算
- 复数运算符重载
- 复数运算符重载
- C++双目运算符重载
- 10.3 重载双目运算符
- C ++ 面向对象编程 运算符重载 双目
- UI基础学习之(十三):Transform的使用
- Objective-C 代码块学习
- java基础篇--03<匿名内部类&枚举类>
- 智慧北京笔记4
- MFC 技巧之五
- C++:运算符重载2(双目:复数的减法)
- 反射
- 230,队列组——同时下载两张图片,然后,合并显示
- python学习中遇到问题
- MFC 技巧之六
- opentsdb采集的数据存放在哪里
- Android开发拍照后相册不显示的问题
- 智慧北京笔记5
- 串口输入十六进制字符串数据,接收后转换为十进制数据