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

当前位置:首页 > C++实验报告 - 实验十六、十七

C++实验报告 - 实验十六、十七

  • 62 次阅读
  • 3 次下载
  • 2025/5/31 2:32:43

void Show(){ cout<<\}};

int main(){ Point pt(0,0); Circle cl1(100,100,10); Cylinder cy1(100,100,10,8); cout<<\点面积:\ pt.Show();

cout<<\圆面积:\ cl1.Show(); cout<<\圆柱底面积:\ cout<<\圆柱侧面积:\ cout<<\圆柱全面积:\ cout<<\圆柱体积:\ cy1.Show(); return 0; }

实验十七 多重继承与虚基类

1.编程:已知时间类TimeType和日期类DateType,先通过多重继承定义日期时间类DateTimeType1,然后使用聚合方式定义功能完全一样的日期时间类DateTimeType2。

多继承类DateTimeType1:

#include using namespace std; class TimeType{

int hour,minute,second; public: TimeType(int h=0,int m=0,int s=0){ hour=h; minute=m; second=s; } void display(){ cout<

class DateType{ int month,day,year; public: DateType(int mo=1,int d=1,int y=2000){ month=mo; day=d; year=y; } void display(){ cout<

class DateTimeType:public TimeType,public DateType{ int month,minute,second,hour,day,year; public: DateTimeType (int h,int m,int s,int mo,int d,int y):TimeType(h,m,s),DateType(mo,d,y){ hour=h;minute=m;second=s;month=mo;day=d;year=y;} void display(){ DateType::display(); TimeType::display(); } void SetDateTime (int h,int m,int s,int mo,int d,int y){ DateType::SetDate (mo,d,y);

};

}

TimeType::SetTime (h,m,s);

int main(){ TimeType t1(8,30,30); cout<<\类示例:\ t1.SetTime(8,30,30); t1.display(); DateType d1(6,14,2011);

cout<<\类示例:\ d1.SetDate(6,14,2011); d1.display(); cout<<\类示例:\ DateTimeType t2(8,30,30,6,14,2011); t2.SetDateTime(8,30,30,6,14,2011); t2.display(); return 0; }

聚合类DateTimeType2:

#include using namespace std; class TimeType{ int hour,minute,second; public: TimeType(int h=0,int m=0,int s=0){ hour=h; minute=m; second=s; } void display(){ cout<

void SetTime(int h,int m,int s){ hour=h; minute=m; second=s; } };

class DateType{ int month,day,year; public: DateType(int mo=1,int d=1,int y=2000){ month=mo; day=d; year=y; } void display(){ cout<

实验小结:

这次实验重点在继承的理解。近段时间上课较快,我们很少时间消化,内容比较多,也感觉越来越难。所以从周一到周三一直在看书调程序。

通过一点点把错误改过,对继承的理解加深了,对多继承的操作

也明白了。其实实验也是一种很好的学习方法,实验迫使我们不断看书理解,在实验中消化了书本知识。

搜索更多关于: C++实验报告 - 实验十六、十七 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

void Show(){ cout<<\}}; int main(){ Point pt(0,0); Circle cl1(100,100,10); Cylinder cy1(100,100,10,8); cout<<\点面积:\ pt.Show(); cout<<\圆面积:\ cl1.Show(); cout<<\圆柱底面积:\ cout<<\圆柱侧面积:\ cout<<\圆柱全面积:\ cout<<\圆柱体积:\ cy1.Show(); return 0; } 实验十七 多重继承与虚基类 1.编程:已知时间类TimeType和日期类DateType,先通过多重继承定义日期时间类DateTimeType1,然

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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