一个简单的C++程序
#include<iostream>usingnamespacestd;classcomplex{private:doublereal,image;publi...
#include<iostream>using namespace std;class complex{private:double real, image;public: complex(){real=0.0;image=0.0;cout<<"Initializing 0 0"<<endl; } complex(double r,double i=0.0){real=r;image=i; cout<<"initailzing"<<r<<'\t'<<i<<endl; } complex(complex & com); ~complex(){ cout<<"destructor"<<endl; } void assign(complex com){ real=com.real; image=com.image; } void print(){ cout<<real<<'+'<<image<<'i'<<endl; }};inline complex::complex(complex & com){cout<<"copy"<<com.real<<'\t'<<com.image<<endl;real=com.real;image=com.image;}complex fun(complex);|||||||||||||||帮忙注释一下这里complex globle;int main(){cout<<"entering main"<<endl;complex com1,com2(5.6,7.5);complex com3=com1;com3.print();globle.print();com1=fun(com2);com1.print();cout<<"exiting main"<<endl;return 0;}complex fun(complex com){cout<<"entering function"<<endl;globle.assign(com);帮忙注释一下这里cout<<"exiting function"<<endl;return globle;帮忙注释一下这里}
展开
展开全部
#include<iostream>
using namespace std;
class complex
{
private:
double real, image;
public:
complex(){real=0.0;image=0.0;cout<<"Initializing 0 0"<<endl; }
complex(double r,double i=0.0){real=r;image=i; cout<<"initailzing"<<r<<'\t'<<i<<endl; }
complex(complex & com);
~complex(){ cout<<"destructor"<<endl; }
void assign(complex com){ real=com.real; image=com.image; }
void print(){ cout<<real<<'+'<<image<<'i'<<endl; }
};
inline complex::complex(complex & com){cout<<"copy"<<com.real<<'\t'<<com.image<<endl;real=com.real;image=com.image;}
complex fun(complex);|||||||||||||||帮忙注释一下这里 //声明一个函数,告诉编译器这个函数的定义在其他地方。
complex globle;
int main()
{cout<<"entering main"<<endl;
complex com1,com2(5.6,7.5);
complex com3=com1;
com3.print();
globle.print();
com1=fun(com2);com1.print();
cout<<"exiting main"<<endl;
return 0;
}
complex fun(complex com)
{
cout<<"entering function"<<endl;
globle.assign(com);帮忙注释一下这里 //调用complex类变量globle中得assign方法,这个方法相当于把com中的数据拷贝到globle中(看complex类的定义就知道)
cout<<"exiting function"<<endl;
return globle; 帮忙注释一下这里 //将重新设置好的globle返回
}
以后提问记得排版。
using namespace std;
class complex
{
private:
double real, image;
public:
complex(){real=0.0;image=0.0;cout<<"Initializing 0 0"<<endl; }
complex(double r,double i=0.0){real=r;image=i; cout<<"initailzing"<<r<<'\t'<<i<<endl; }
complex(complex & com);
~complex(){ cout<<"destructor"<<endl; }
void assign(complex com){ real=com.real; image=com.image; }
void print(){ cout<<real<<'+'<<image<<'i'<<endl; }
};
inline complex::complex(complex & com){cout<<"copy"<<com.real<<'\t'<<com.image<<endl;real=com.real;image=com.image;}
complex fun(complex);|||||||||||||||帮忙注释一下这里 //声明一个函数,告诉编译器这个函数的定义在其他地方。
complex globle;
int main()
{cout<<"entering main"<<endl;
complex com1,com2(5.6,7.5);
complex com3=com1;
com3.print();
globle.print();
com1=fun(com2);com1.print();
cout<<"exiting main"<<endl;
return 0;
}
complex fun(complex com)
{
cout<<"entering function"<<endl;
globle.assign(com);帮忙注释一下这里 //调用complex类变量globle中得assign方法,这个方法相当于把com中的数据拷贝到globle中(看complex类的定义就知道)
cout<<"exiting function"<<endl;
return globle; 帮忙注释一下这里 //将重新设置好的globle返回
}
以后提问记得排版。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询