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

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

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

int i; protected: void f2(); int j; private: int k; };

class B: public A //B为A的公用派生类 {public: void f3( ); protected: int m; private: int n; };

class C: public B {public: void f4(); private: int p; };

int main()

{A a1; B b1; C//c1是派生类C的对象 return 0; }

6:

#include using namespace std; class A {public: void f1( ); protected: void f2(); private: int i; };

class B: public A {public:

//C为B的公用派生类 //a1是基类A的对象 //b1是派生类B的对象 void f3( ); int k; private: int m; };

class C: protected B {public: void f4(); protected: int n; private: int p; };

class D: private C {public: void f5(); protected: int q; private: int r; };

int main() {A a1; B b1; C c1; D d1; return 0; } 7:

#include using namespace std; class A {

public:

A(){a=0;b=0;} A(int i){a=i;b=0;} A(int i,int j){a=i;b=j;}

void display(){cout<<\ private: int a; int b;

};

class B : public A {

public: B(){c=0;}

B(int i):A(i){c=0;}

B(int i,int j):A(i,j){c=0;} B(int i,int j,int k):A(i,j){c=k;} void display1() {display();

cout<<\ }

private: int c; };

int main() { B b1; B b2(1); B b3(1,3); B b4(1,3,5); b1.display1();

b2.display1(); b3.display1(); b4.display1(); return 0; } 8:

#include using namespace std; class A {

public:

A(){cout<<\ ~A(){cout<<\ };

class B : public A {

public:

B(){cout<<\ ~B(){cout<<\};

class C : public B {

public:

C(){cout<<\ ~C(){cout<<\};

int main() { C c1;

return 0; }

9: #include #include using namespace std; class Teacher {public:

Teacher(string nam,int a,char s,string tit,string ad,string t); void display(); protected: string name; int age; char sex; string title; string addr; string tel; };

Teacher::Teacher(string nam,int a,char s,string tit,string ad,string t): name(nam),age(a),sex(s),title(tit),addr(ad),tel(t){ } void Teacher::display()

{cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ }

class Cadre {public:

Cadre(string nam,int a,char s,string p,string ad,string t); void display(); protected:

string name; int age; char sex; string post; string addr; string tel; };

Cadre::Cadre(string nam,int a,char s,string p,string ad,string t): name(nam),age(a),sex(s),post(p),addr(ad),tel(t){}

void Cadre::display()

{cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ }

class Teacher_Cadre:public Teacher,public Cadre {public:

Teacher_Cadre(string nam,int a,char s,string tit,string p,string ad,string t,float w); void show( ); private:

float wage; };

Teacher_Cadre::Teacher_Cadre(string nam,int a,char s,string t,string p,string ad,string tel,float w): Teacher(nam,a,s,t,ad,tel),Cadre(nam,a,s,p,ad,tel),wage(w) {} void Teacher_Cadre::show( ) {Teacher::display();

cout<<\ cout<<\ }

int main( )

{Teacher_Cadre te_ca(\Beijing Road,Shanghai\ te_ca.show( ); return 0; } 10:

#include

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

inti;protected:voidf2();intj;private:intk;};classB:publicA//B为A的公用派生类{public:voidf3();protected:intm;private:intn;};classC:
推荐度:
点击下载文档文档为doc格式
1snua7w6oy37lyd0yejn
领取福利

微信扫码领取福利

微信扫码分享