《C面向对象程序设计答案》第五章谭浩强清华大学出版社_第1页
《C面向对象程序设计答案》第五章谭浩强清华大学出版社_第2页
《C面向对象程序设计答案》第五章谭浩强清华大学出版社_第3页
《C面向对象程序设计答案》第五章谭浩强清华大学出版社_第4页
《C面向对象程序设计答案》第五章谭浩强清华大学出版社_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

创作时间:贰零贰壹年柒月贰叁拾日之巴公井创始作创作时间:贰零贰壹年柒月贰叁拾日#include<iostream>usingnamespacestd;classStudent{public:voidget_value( ){cin>>num>>name>>sex;}voiddisplay( ){cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}private:intnum;charname[10];charsex;};classStudent1:publicStudent{public:voidget_value_1( ){get_value( );cin>>age>>addr;}创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日voiddisplay_1( ){cout<<"age:"<<age<<endl;//引用派生类的私有成员,正确。cout<<"address:"<<addr<<endl;}//引用派生类的私有成员,正确。private:intage;charaddr[30];};intmain( ){Student1stud1;stud1.get_value_1( );stud1.display( );stud1.display_1( );return0;}2:#include<iostream>usingnamespacestd;classStudent{public:voidget_value( )创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日{cin>>num>>name>>sex;}voiddisplay( ){cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}private:intnum;charname[10];charsex;};classStudent1:privateStudent{public:voidget_value_1( ){get_value( );cin>>age>>addr;}voiddisplay_1( ){display( );cout<<"age:"<<age<<endl;//引用派生类的私有成员,正确。cout<<"address:"<<addr<<endl;}//引用派生类的私有成员,正确。private:创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日intage;charaddr[30];};intmain( ){Student1stud1;stud1.get_value_1( );stud1.display_1( );return0;}3:#include<iostream>usingnamespacestd;classStudent//申明基类{public://基类公用成员voidget_value( );voiddisplay( );protected://基类珍爱成员intnum;charname[10];charsex;};voidStudent::get_value( )创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日{cin>>num>>name>>sex;}voidStudent::display( ){cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}classStudent1:protectedStudent//申明一个珍爱派生类{public:voidget_value_1( );voiddisplay1( );private:intage;charaddr[30];};voidStudent1::get_value_1( ){get_value( );cin>>age>>addr;}voidStudent1::display1( ){cout<<"num:"<<num<<endl;//引用基类的珍爱成员cout<<"name:"<<name<<endl;//引用基类的珍爱成员创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日cout<<"sex:"<<sex<<endl;//引用基类的珍爱成员cout<<"age:"<<age<<endl;//引用派生类的私有成员cout<<"address:"<<addr<<endl;//引用派生类的私有成员}intmain( ){Student1stud1;//stud1是派生类student1类的对象stud1.get_value_1( );//调用派生类对象stud1的公用成员函数stud1.display1( );//调用派生类对象stud1的公用成员函数return0;}4:解法一#include<iostream>usingnamespacestd;classStudent//申明基类{public://基类公用成员voidget_value( );voiddisplay( );protected://基类珍爱成员intnum;创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日charname[10];charsex;};voidStudent::get_value( ){cin>>num>>name>>sex;}voidStudent::display( ){cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}classStudent1:publicStudent//申明一个公用派生类{public:voidget_value_1( );voiddisplay1( );private:intage;charaddr[30];};voidStudent1::get_value_1( ){get_value( );cin>>age>>addr;创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日}voidStudent1::display1( ){cout<<"num:"<<num<<endl;//引用基类的珍爱成员,合法cout<<"name:"<<name<<endl;//引用基类的珍爱成员,合法cout<<"sex:"<<sex<<endl;//引用基类的珍爱成员,合法cout<<"age:"<<age<<endl;//引用派生类的私有成员,合法cout<<"address:"<<addr<<endl;//引用派生类的私有成员,合法}intmain( ){Student1stud1;//stud1是派生类student1类的对象stud1.get_value_1( );//调用派生类对象stud1的公用成员函数get_value_1stud1.display1( );//调用派生类对象stud1的公用成员函数display1return0;}创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日解法二#include<iostream>usingnamespacestd;classStudent//申明基类{public://基类公用成员voidget_value( );voiddisplay( );protected://基类珍爱成员intnum;charname[10];charsex;};voidStudent::get_value( ){cin>>num>>name>>sex;}voidStudent::display( ){cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}classStudent1:protectedStudent//申明一个公用派生类{public:创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日voidget_value_1( );voiddisplay1( );private:intage;charaddr[30];};voidStudent1::get_value_1( ){cin>>age>>addr;}voidStudent1::display1( ){cout<<"age:"<<age<<endl;cout<<"address:"<<addr<<endl;}intmain( ){Student1stud1;//stud1是派生类student1类的对象stud1.get_value( );stud1.get_value_1( );stud1.display( );stud1.display1( );//合法。display1是派生类中的公用成员函数return0;}创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日5:classA//A为基类{public:voidf1( );inti;protected:voidf2( );intj;private:intk;};classB:publicA//B为A的公用派生类{public:voidf3( );protected:intm;private:intn;};classC:publicB//C为B的公用派生类{public:voidf4( );创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日private:intp;};intmain( ){Aa1;//a1是基类A的对象Bb1;//b1是派生类B的对象Cc1;//c1是派生类C的对象return0;}6:#include<iostream>usingnamespacestd;classA{public:voidf1( );protected:voidf2( );private:inti;};classB:publicA{public:创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日voidf3( );intk;private:intm;};classC:protectedB{public:voidf4( );protected:intn;private:intp;};classD:privateC{public:voidf5( );protected:intq;private:intr;};intmain( )创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日{Aa1;b1;c1;d1;return0;}7:#include<iostream>usingnamespacestd;classA{public:A( ){a=0;b=0;}A(inti){a=i;b=0;}A(inti,intj){a=i;b=j;}voiddisplay( ){cout<<"a="<<a<<"b="<<b;}private:inta;intb;};classB:publicA{创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日public:B( ){c=0;}B(inti):A(i){c=0;}B(inti,intj):A(i,j){c=0;}B(inti,intj,intk):A(i,j){c=k;}voiddisplay1( ){display( );cout<<"c="<<c<<endl;}private:intc;};intmain( ){Bb1;Bb2(1);Bb3(1,3);b4(1,3,5);b1.display1( );b2.display1( );b3.display1( );b4.display1( );return0;创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日}8:#include<iostream>usingnamespacestd;classA{public:A( ){cout<<"constructingA"<<endl;}~A( ){cout<<"destructingA"<<endl;}};classB:publicA{public:B( ){cout<<"constructingB"<<endl;}~B( ){cout<<"destructingB"<<endl;}};classC:publicB{public:C( ){cout<<"constructingC"<<endl;}~C( ){cout<<"destructingC"<<endl;}};创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日intmain( ){Cc1;return0;}9:#include<string>#include<iostream>usingnamespacestd;classTeacher{public:Teacher(stringnam,inta,chars,stringtit,stringad,stringt);voiddisplay( );protected:stringname;intage;charsex;stringtitle;stringaddr;stringtel;};Teacher::Teacher(string创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日nam,inta,chars,stringtit,stringad,stringt):name(nam),age(a),sex(s),title(tit),addr(ad),tel(t){}voidTeacher::display( ){cout<<"name:"<<name<<endl;cout<<"age"<<age<<endl;cout<<"sex:"<<sex<<endl;cout<<"title:"<<title<<endl;cout<<"address:"<<addr<<endl;cout<<"tel:"<<tel<<endl;}classCadre{public:Cadre(stringnam,inta,chars,stringp,stringad,stringt);voiddisplay( );protected:stringname;intage;charsex;stringpost;stringaddr;stringtel;};创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日Cadre::Cadre(stringnam,inta,chars,stringp,stringad,stringt):name(nam),age(a),sex(s),post(p),addr(ad),tel(t){}voidCadre::display( ){cout<<"name:"<<name<<endl;cout<<"age:"<<age<<endl;cout<<"sex:"<<sex<<endl;cout<<"post:"<<post<<endl;cout<<"address:"<<addr<<endl;cout<<"tel:"<<tel<<endl;}classTeacher_Cadre:publicTeacher,publicCadre{public:Teacher_Cadre(stringnam,inta,chars,stringtit,stringp,stringad,stringt,floatw);voidshow( );private:floatwage;};Teacher_Cadre::Teacher_Cadre(stringnam,inta,chars,stringt,stringp,stringad,stringtel,float创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日w):Teacher(nam,a,s,t,ad,tel),Cadre(nam,a,s,p,ad,tel),wage(w){}voidTeacher_Cadre::show( ){Teacher::display( );cout<<"post:"<<Cadre::post<<endl;cout<<"wages:"<<wage<<endl;}intmain( ){Teacher_Cadrete_ca("Wang-li",50,'f',"prof.","president","135BeijingRoad,Shanghai","(021)61234567",1534.5);te_ca.show( );return0;}10:#include<iostream>#include<cstring>usingnamespacestd;classTeacher//教师类{public:创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日Teacher(int,char[],char);//申明结构函数voiddisplay( );//申明输出函数private:intnum;charname[20];charsex;};Teacher::Teacher(intn,charnam[],chars)//定义结构函数{num=n;strcpy(name,nam);sex=s;}voidTeacher::display( )//定义输出函数{cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}classBirthDate//诞辰类{public:创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日BirthDate(int,int,int);//申明结构函数voiddisplay( );//申明输出函数voidchange(int,int,int);//申明改正函数private:intyear;intmonth;intday;};BirthDate::BirthDate(inty,intm,intd)//定义结构函数{year=y;month=m;day=d;}voidBirthDate::display( )//定义输出函数{cout<<"birthday:"<<month<<"/"<<day<<"/"<<year<<endl;}voidBirthDate::change(inty,intm,intd)//定义改正函数{year=y;创作时间:贰零贰壹年柒月贰叁拾日创作时间:贰零贰壹年柒月贰叁拾日month=m;day=d;}cl

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论