class complex
{
double i,j;
public:
complex(void);
complex(double ,double );
complex add(complex &a);
void norm();
complex aqq(complex &b);
void print();
void set(double,double);
complex (complex &c);
};

#include "complex.h"
#include<math.h>
#include<iostream>
using namespace std;
complex::complex(void)
{
i=0;
j=0;
}

complex::complex(double i2,double j2 ){
i=i2;
j=j2;
}

complex::complex(complex &b){
i=b.i;
j=b.j;
}
complex complex::add(complex &a){
complex y(a.i+i,a.j+j);
return y;
}
complex complex::aqq(complex &c){
complex y(c.i-i,c.j-j);
return y;
}
void complex::norm(){
double sum;
sum=sqrt(i*i+j*j);
cout<<"模为:"<<sum<<endl;
}
void complex::print(){
cout<<i<<"i"<<j<<"j"<<endl;
}
void complex::set(double a,double b){
i=a;
j=b;
}
#include<iostream>
using namespace std;
#include"complex.h"
int main(){
complex a(3,4),b(6,10);
complex c(a);
a.print();
c=b.add(a);
c.print();
a.norm();
c=b.aqq(a);
c.print();
system("pause");
return 0;

}
Last modification:May 11th, 2021 at 03:58 pm