64,636
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class complex
{
public:
complex(){
real=0;
image=0;
}
complex(int r,int m){
real=r;
image=m;
}
friend complex operator*(const complex& A,const complex& B);
friend ostream& operator<<(ostream& os,complex& a);
void print();
private:
int real;
int image;
};
void complex::print() {
cout <<real <<"+" <<image <<endl;
}
complex operator*(const complex& A,const complex& B) {
return complex(A.real*B.image-A.image*B.real,A.real*B.image+A.image*B.real);
}
ostream& operator<<(ostream& os,complex& a){
os<<a.real <<"+" <<a.image <<endl;
return os;
}
void main() {
complex v1(2,3);
complex v2(4,5);
complex v3;
v3=v1*v2;
cout <<v3 <<endl;
}