云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 面向对象程序设计课后习题答案

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/7 16:19:41

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<<\

搜索更多关于: 面向对象程序设计课后习题答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

date::display(); cout<

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com