您的位置:首页 > 其它

7.12

2015-07-09 16:03 253 查看
#include<iostream>
using namespace std;
class Container{
public:
Container(double r=0,double i=0);
friend Container operator+(const Container c1,const Container c2);
void print() ;
private:
double real,imag;
};
Container::Container(double r,double i)
{ real=r;
imag=i;
}
Container operator+(const Container c1,const Container c2)
{ Container temp;
temp.real=c1.real+c2.real;
temp.imag=c1.imag+c2.imag;
return temp;
}
void Container::print()
{ cout<<" ("<<real<<", "<<imag<<") "<<endl;
}
int main()
{ Container c1(2.4,3.6),c2(4.1,6.3);
Container c;
c=c1+c2;
c.print();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: