好文档 - 专业文书写作范文服务资料分享网站

c++面向对象程序设计课后习题答案(谭浩强版)

天下 分享 时间: 加入收藏 我要投稿 点赞

double imag; };

double Complex::get_real() {return real;}

double Complex::get_imag() {return imag;}

void Complex::display()

{cout<<\

Complex operator + (Complex &c1,Complex &c2) {

return Complex()+(),()+()); }

int main()

{Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; cout<<\ (); return 0; } 2:

#include using namespace std; class Complex {public:

Complex(){real=0;imag=0;}

Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c2); Complex operator-(Complex &c2); Complex operator*(Complex &c2); Complex operator/(Complex &c2); void display(); private: double real; double imag; };

Complex Complex::operator+(Complex &c2) {Complex c; =real+; =imag+; return c;}

Complex Complex::operator-(Complex &c2) {Complex c; =; =; return c;}

Complex Complex::operator*(Complex &c2) {Complex c; =real**; =imag*+real*;

return c;}

Complex Complex::operator/(Complex &c2) {Complex c; =(real*+imag*/*+*; =(imag**/*+*; return c;}

void Complex::display()

{cout<<\

int main()

{Complex c1(3,4),c2(5,-10),c3; c3=c1+c2; cout<<\ (); c3=c1-c2; cout<<\ (); c3=c1*c2; cout<<\ (); c3=c1/c2; cout<<\ (); return 0; } 3:

#include ,\ ( ); return 0; } 10:

#include #include using namespace std;

class Teacher um<<\\\ ((char *)&staf[i],sizeof(staf[i]));}

cout<<\ for(i=0;i<2;i++) {cin>>>>>>>>; (0,ios::end);

((char *)&staf1,sizeof(staf1));} (0,ios::beg); for(i=0;i<7;i++)

{((char *)&staf[i],sizeof(staf[i])); cout<

cout<<\ cin>>num; while(num) {find=false;

\

\

(0,ios::beg); for(i=0;i<7;i++)

{((char *)&staf[i],sizeof(staf[i])); if(num==staf[i].num) {m=();

cout<

\ find=true; break; } } if(!find)

cout<<\

cout<<\ cin>>num; } (); return 0; }

6:解法一

#include #include using namespace std;

struct student

\

c++面向对象程序设计课后习题答案(谭浩强版)

doubleimag;};doubleComplex::get_real(){returnreal;}doubleComplex::get_imag(){returnimag;}voidComplex::display(){cout<<\Complexoperator+(C
推荐度:
点击下载文档文档为doc格式
3ac2t6ev9r6b8ve00zsa83uyx967u500v8d
领取福利

微信扫码领取福利

微信扫码分享