|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<iostream>
- class Complex //complex表示“复数”
- {
- public:
- Complex();
- Complex(double r,double i);
- Complex complex_add(Complex &d);
- void print();
- private:
- double real;
- double imag;
- };
- Complex::Complex()
- {
- real = 0;
- imag = 0;
- }
- Complex::Complex(double r,double i)
- {
- real = r;
- imag = i;
- }
- Complex Complex::complex_add(Complex &d)
- {
- Complex c;
- c.real = real + d.real;
- c.imag = imag + d.imag;
- return c;
- }
- void Complex::print()
- {
- std::cout<<”(”<<real<<”,”<<imag<<”i)\n”;
- }
- int main()
- {
- Complex c1(3,4),c2(5,-10),c3;
- c3 = c1.complex_add(c2);
- std::cout<<”c1=”;
- c1.print();
- std::cout<<”c2=”;
- c1.print();
- std::cout<<”c1+c2=”;
- c3.print();
- return 0;
- }
复制代码
有没有大神能给讲一下
Complex Complex::complex_add(Complex &d)函数部分是什么意思...
为什么参数要是d的地址
还有c.real中的“.”是什么意思?
这个函数体是真的看不明白...麻烦大神给详细讲解下,谢谢啦! |
|