虚基类——沙发床类
来源:互联网 发布:淘宝购物退货运费谁出 编辑:程序博客网 时间:2024/04/29 13:10
问题及代码:
/*。*Copyright(c)2014,烟台大学计算机学院*All right reserved,*文件名:test.cpp*作者:liu_feng_zi_*完成日期:2015年6月25日*版本号:v1.0*问题描述:虚基类————沙发床*输入描述:*程序输出:*/#include <iostream>using namespace std;class Furniture{public: Furniture(double w) { weight=w; } void display() { cout<<"weight:"<<weight<<endl; }protected: double weight; //家具重量};class Bed: virtual public Furniture{public: Bed(double we,double l,double wi):Furniture(we),length(l),width(wi) {} void display() { cout<<"length:"<<length<<endl; cout<<"width:"<<width<<endl; }protected: double length; //床的长 double width; //床的宽};//沙发类Sofaclass Sofa: virtual public Furniture{public: Sofa(double w,double h):Furniture(w),height(h) {} void display() { cout<<"height:"<<height<<endl; }protected: double height; //沙发的高度};//沙发床class SleeperSofa:public Bed, public Sofa{public: SleeperSofa(double we,double l,double wi,double h):Furniture(we),Bed(we,l,wi),Sofa(we,h) { } void display() { cout<<"weight:"<<weight<<endl; Bed::display(); Sofa::display(); }};int main(){ double weight,length,width,height; cin>>weight>>length>>width>>height; SleeperSofa ss(weight,length,width,height); ss.display(); return 0;}运行结果:
0 0
- 虚基类——沙发床类
- OJ第三批——Problem Q: B 虚拟继承(虚基类)-沙发床(改错题)
- OJ第六批——Problem J: B 虚拟继承(虚基类)-沙发床(改错题)
- OJ嘻唰唰之改错题(6)-虚拟继承(虚基类)沙发床
- 嘻唰唰第六批Problem J: B 虚拟继承(虚基类)-沙发床(改错题)
- YTU 2622: B 虚拟继承(虚基类)-沙发床(改错题)
- [YTU]_2622(B 虚拟继承(虚基类)-沙发床(改错题))
- 刚买的沙发床,推荐一下
- 讨论沙发床的面向对象模拟
- 虚基类——动物
- 29.C++类的多重继承——虚基类
- c++—虚基类
- 面试题目(4)——虚基类
- 继承与派生——虚基类
- C++虚基类的实现机制:笔记 && C++学习笔记(10)——虚基类的作用
- C++学习笔记(10)——虚基类的作用
- virtual public CParent的含义及作用——虚基类
- C++语言笔记系列之十七——虚基类
- MAPConfidenceScorer API
- 六月二十四
- 观察者模式(Observer Pattern)
- Node API
- C语言:目标代码文件,可执行文件和库
- 虚基类——沙发床类
- c++ 输出虚函数表内容
- 用base64加密
- 遇到的一些小问题
- Android 应用四大组件
- CF 12C Fruits
- Android基础组件(一)自动完成控件AutoCompleteTextView
- UIControl IOS控件编程—IOS开发
- linux回到用户上次所在目录/上一级目录/用户家目录/顶级目录