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

2026/1/17 2:11:56

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文档下载到电脑
搜索更多关于: 面向对象程序设计课后习题答案 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219