//
// Created by 刘彪 on 2020/2/29.
//
#include <iostream>
#include <iomanip>
#include <cstdio>
//#include <math.h>
using namespace std;
class Complex{
private:
double real,image;
public:
Complex(){}
Complex(double a, double b){
real = a;
image = b;
}
void setdata(double a,double b){
real = a;
image = b;
}
double getReal(){
return real;
}
double getImage(){
return image;
}
void print(){
if(image>0) cout<<"complex:"<<real<<"+"<<image<<"i"<<endl;
if(image<0) cout<<"complex:"<<real<<"-"<<-image<<"i"<<endl;
}
friend Complex add(Complex,Complex);
};
Complex add(Complex c1,Complex c2){
Complex c3;
c3.real = c1.real + c2.real;
c3.image = c1.image + c2.image;
return c3;
}
int main(){
Complex c1(2,5),c2,c3;
c2.setdata(-6,-2);
c3 = add(c1,c2);
cout<<"complex1:";c1.print();
cout<<"complex2:";c2.print();
cout<<"complex3:";c3.print();
return 0;
}
/Users/liubiao/CLionProjects/untitled2/cmake-build-debug/untitled2
complex1:complex:2+5i
complex2:complex:-6-2i
complex3:complex:-4+3i
Process finished with exit code 0
P131