在C++中定义一个复数类的题
#include#includeclasscomplex{doublereal,imag;public:complex(doublereal=0.0,doubleimag...
#include#includeclasscomplex
{
double real,imag;
public:
complex(double real=0.0, doubleimag=0.0); //声明构造函数
( ) //声明析构函数
double abscomplex();
};
( ) //定义构造函数
{
cout<<"constructing……"<<endl;
real=r;
imag=i;
}
complex::~complex() //定义析构函数
{
cout<<"destructing……"<<endl;
}
doublecomplex::abscomplex()
{
double n;
n=real*real+imag*imag;
return sqrt(n);
}
voidmain()
{
( ) //定义复数类对象ob(1.1,2.2)
cout<<"absof complex ob="<< ( )<<endl; //调用abscomplex()函数
}
括号内的应该填什么呢 展开
{
double real,imag;
public:
complex(double real=0.0, doubleimag=0.0); //声明构造函数
( ) //声明析构函数
double abscomplex();
};
( ) //定义构造函数
{
cout<<"constructing……"<<endl;
real=r;
imag=i;
}
complex::~complex() //定义析构函数
{
cout<<"destructing……"<<endl;
}
doublecomplex::abscomplex()
{
double n;
n=real*real+imag*imag;
return sqrt(n);
}
voidmain()
{
( ) //定义复数类对象ob(1.1,2.2)
cout<<"absof complex ob="<< ( )<<endl; //调用abscomplex()函数
}
括号内的应该填什么呢 展开
展开全部
class complex
{
double real,imag;
public:
complex(double real=0.0, doubleimag=0.0); //声明构造函数
~complex( void ); //声明析构函数
double abscomplex();
};
complex::complex(double real=0.0, doubleimag=0.0) //定义构造函数
{
cout<<"constructing……"<<endl;
real=r;
imag=i;
}
complex::~complex() //定义析构函数
{
cout<<"destructing……"<<endl;
}
double complex::abscomplex()
{
double n;
n=real*real+imag*imag;
return sqrt(n);
}
{
double real,imag;
public:
complex(double real=0.0, doubleimag=0.0); //声明构造函数
~complex( void ); //声明析构函数
double abscomplex();
};
complex::complex(double real=0.0, doubleimag=0.0) //定义构造函数
{
cout<<"constructing……"<<endl;
real=r;
imag=i;
}
complex::~complex() //定义析构函数
{
cout<<"destructing……"<<endl;
}
double complex::abscomplex()
{
double n;
n=real*real+imag*imag;
return sqrt(n);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询