# 一、题目描述

class Complex
{
private:
double real; // 实部
double imag; // 虚部
public:
Complex();
Complex(double r, double i);
// 友元函数，复数c1 + c2(二参数对象相加)
friend Complex addCom(const Complex& c1, const Complex& c2);
// 友元函数，输出类对象c的有关数据(c为参数对象)
friend void outCom(const Complex& c);
};

1. ``````实现复数类和友元函数addCom和outCom。
``````

3. ``````在main函数中，通过友元函数，实现复数的加减法和复数的输出。
``````

# 二、输入与输出

## 1.输入

``````10 10
3
+ 20 10
- 15 5
+ 5 25
``````

## 2.输出

``````(30,20)
(15,15)
(20,40)
``````

# 三、参考代码

``````#include<iostream>
#include<cmath>
#include<string>
#include <iomanip>
using namespace std;
class com
{
private:
double real;
double imag;
public:
com();
com(double r,double i);
friend com sub(const com&n1,const com&n2);
friend void pri(const com &c);
};
com::com(double r,double i)
{
real=r;
imag=i;
}
{
com a(n1.real+n2.real,n1.imag+n2.imag);
return a;
}
com sub(const com&n1,const com&n2)
{

com b(n1.real-n2.real,n1.imag-n2.imag);
return b;

}
void pri(const com &c)
{
cout<<"("<<c.real<<","<<c.imag<<")"<<endl;
}
int main()
{
int r,i;
int num;
cin>>r>>i;
com z1(r,i);
cin>>num;
char ch;

while(num--)
{
cin>>ch;
cin>>r>>i;
com z2(r,i);
if(ch=='+')
{

}
else if(ch=='-')
{
z1=sub(z1,z2);

}
pri(z1);

}
return 0;
}
``````

THE END

)">