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

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

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

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++实验报告 - 实验十六、十七 的文档
C++实验报告 - 实验十六、十七.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5aqqs3t3s62ubi97rwuy_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top