18_1.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- #include <iostream.h>
- class Complex{
- public:
- Complex(double r=0, double v=0):real(r),virt(v){}
- friend Complex operator+(Complex a, Complex b);
- friend ostream& operator<<(ostream& out, Complex& a);
- private:
- double real;
- double virt;
- };
- ostream& operator<<(ostream& out, Complex& a){ return out <<a.real <<"+" <<a.virt <<"in"; }
- Complex operator+(Complex a, Complex b)
- {
- return Complex(a.real+b.real, a.virt+b.virt);
- }
- void main()
- {
- Complex a(2,5), b(7,8), c(0,0);
- c = a + b;
- cout <<c;
- c = 4.1 + a;
- cout <<c;
- c = b + 5.6;
- cout <<c;
- }