OJ 1.R
来源:互联网 发布:巴尔坦星人 知乎 编辑:程序博客网 时间:2024/05/22 00:55
/*定义一个复数类Complex,重载运算符“+”,使之能用于复数的加法运算。将运算符函数重载为非成员、非友元的普通函数。编写程序,求两个复数之和。Input两个复数Output复数之和*/#include <iostream>#include <iomanip>using namespace std;class Complex{public: Complex(); Complex(double r,double i); double get_real(); double get_imag(); void display();private: double real; double imag;};Complex operator+(Complex &c1,Complex &c2){ /*Complex c; c.get_real()=c1.get_real()+c2.get_real(); c.get_imag()=c1.get_imag()+c2.get_imag();*/ return Complex(c1.get_real()+c2.get_real(),c1.get_imag()+c2.get_imag());}Complex::Complex(){} Complex::Complex(double r,double i) { real=r; imag=i; } double Complex::get_real() { return real; } double Complex::get_imag() { return imag; } void Complex::display() { cout<<"("<<real<<","<<imag<<"i)"<<endl; }int main(){ double real,imag; cin>>real>>imag; Complex c1(real,imag); cin>>real>>imag; Complex c2(real,imag); Complex c3=c1+c2; cout<<setiosflags(ios::fixed); cout<<setprecision(2); c3.display(); return 0;}
0 0
- OJ 1.R
- oj(一)r
- 【OJ】---R---复数类--重载运算符+
- LINUX 下gets的 /r问题 北师大OJ Number theory
- sdutacm-oj--离散题目15--给出集合X、X上的关系R,判断关系R是不是传递的。
- r
- r
- R
- r
- r
- r
- R
- R
- r
- R
- r
- R
- r
- 旅行,写作,编程
- Activity详解
- UITableView(二编辑插入)
- [转载]《AngularJS》5个实例详解Directive(指令)机制
- 用PLSQL创建oracle用户
- OJ 1.R
- POJ 2243 Knight Moves
- 中秘传媒:网络品牌营销行业领跑者
- PCIE 设备扫描的过程
- ssh框架报错和真实错误不相关
- 使用openstack架构私有云
- JDK 《linux下安装jdk》
- TextKit学习(四)通过boundingRectWithSize:options:attributes:context:计算文本尺寸
- 网络协议学习方法