南宁尖锐湿疣会传染吗:complex类

来源:百度文库 编辑:我要文章网 时间:2019/12/11 08:12:39
//主文件m.cpp
#include
#include "complex.h"
using namespace std;
void main()
{
double f;
complex c1(1,1);
f=c1.abs();
cout<}
//complex.h
#if !defined complex_h
#define complex_h
class complex
{
double real;
double image;
public:
complex();
complex(double,double);
complex(const complex&);//拷贝构造函数
double abs();
};                                                                                                                                                                             #endif
//complex.cpp
#include "complex.h"
#include
complex::complex()
{
real=0;
image=0;
}
complex::complex(double r,double i)
{
real=r;
image=i;
}
complex::complex(const complex&c)
{
real=c.real;
image=c.image;
}
double complex::abs()
{
return sqrt(real*real+image*image);
}