第一范文网 - 专业文章范例文档资料分享平台

面向对象程序设计课后习题答案

来源:用户分享 时间:2025/5/16 5:59:41 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

date::display(); cout<

time::display(); } protected:

char childname[20]; };

void main()

{ birthtime yx(\ yx.display(); }

[5_17]程序如下

#include #include class animal { public: animal()

{ name=NULL; } animal(char *n); ~animal()

{ delete name; } virtual void whoami(); protected:

char *name; };

class cat:public animal { public:

cat():animal() { }

cat(char *n):animal(n) { }

void whoami(); };

class tiger:public cat { public:

tiger():cat() { }

tiger(char *n):cat(n) { }

void whoami(); };

animal::animal(char *n)

{ name=new char [strlen(n)+1]; strcpy(name,n);

}

void animal::whoami()

{ cout<<\ } void cat::whoami()

{ cout<<\ } void tiger::whoami()

{ cout<<\void main() //添加的主函数 { cat cat(\ cat.whoami();

tiger tiger(\ tiger.whoami(); }

[5_18]实现本题功能的程序如下: #include class building { public:

building(int f,int r,double ft) { floors=f; rooms=r;

footage=ft; }

protected:

int floors;//层数

int rooms; //房间数 double footage;//平方数 };

class house:public building { public:

house(int f,int r,double ft,int br,int bth) nbsp; :building(f,r,ft)

{ bedrooms=br; bathrooms=bth; } void show()

{ cout<<\ cout<<\ \

cout<<\ cout<<\ cout<<\ } private:

int bedrooms;//卧室数 int bathrooms;//浴室数 };

class office:public building

{ public:

office(int f,int r,double ft,int p,int ext) :building(f,r,ft)

{ phones=p; extinguishers=ext; } void show()

{ cout<<\ cout<<\ \

cout<<\ cout<<\ cout<<\ cout<

int phones;//电话数

int extinguishers;//灭火器数 }; main()

{ house h_ob(2,12,5000,6,4); office o_ob(4,25,12000,30,8); cout<<\ h_ob.show();

cout<<\ o_ob.show(); return 0; }

[5_19]实现本题功能的程序如下: #include #include const int l=80; class person { public:

void input()

{ cout<<\ cin>>name;

cout<<\ cin>>id; }

void print()

{ cout<<\ } void printname()

{ cout<

char name[l],id[l]; };

class stud { public:

void input()

{ cout<<\ cin>>addr;

cout<<\ cin>>tel; }

void print()

{ cout<<\ cout<<\ } private:

char addr[l]; char tel[l]; };

class student:private person { public:

void input()

{ person::input();

cout<<\ cin>>old;

cout<<\ cin>>sno; }

void print()

{ person::print();

cout<<\ cout<<\ }

void printname()

{ person::printname(); } private:

int old;

unsigned long sno; };

class score:private student,private stud { public:

void input()

{ student::input(); stud::input();

cout<<\ cin>>math;

cout<<\

搜索更多关于: 面向对象程序设计课后习题答案 的文档
面向对象程序设计课后习题答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c23wyh0n2zf4c2db00666_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top