//主文件m.cpp
#include <iostream>
#include "complex.h" using namespace std; void main() { double f; complex c1(1,1); f=c1.abs(); cout<<f<<endl; } //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 <cmath> 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); } |
|