class Builing { private: int cengshu;//层数 int fangjianshu;//房间数 double total_area;//总平方米 public: //构造函数 Builing(int ceng = 0, int fangjian = 0, double area =0.0) :cengshu(ceng), fangjianshu(fangjian), total_area(area) { //检验合法性 if (cengshu < 0) { cengshu = 0; } if (fangjianshu < 0) { fangjianshu = 0; } if (total_area < 0) { total_area = 0; } } //获得属性 int getcengshu()const { return cengshu; } int getfangjianshu()const { return fangjianshu; } double gettotal_area()const { return total_area; } //设置属性 int setcengshu(int ceng) { if (cengshu >= 0) { cengshu = ceng; } } int setfangjianshu(int fangjian) { if (fangjianshu >=0 ) { fangjianshu = fangjian; } } int settotal_area(double area) { if (total_area >=0) { total_area = area; } } //显示信息 virtual void show()const { cout << "楼房信息 " << endl; cout << "层数" << cengshu << endl; cout << "房间数量" << fangjianshu << endl; cout << "总平方米" << total_area << "平方米" << endl; } }; class House :public Builing { private: int bedroom_count;//卧室数量 int bathroom_count;//浴室数量 public: //构造函数 House(int ceng = 0, int fangjian = 0, double area = 0.0, int bedroom = 0, int bathroom = 0) : Builing(ceng, fangjian, area), bedroom_count(bedroom), bathroom_count(bathroom) { //检验合理性 if (bedroom_count < 0) { bedroom_count = 0; } if (bathroom_count < 0) { bathroom_count = 0; } } //显示信息 void show()const { //因为show是虚函数 Builing::show(); cout << "住宅信息" << endl; cout << "卧室数量" << bedroom_count << endl; cout << "浴室数量" << bathroom_count << endl; } }; class Office :public Builing { private: int fire_extinguisher;//灭火器数量 int phone_count;//电话数量 public: Office(int ceng = 0, int fangjian = 0, double area = 0.0, int fire = 0, int phone = 0) : Builing(ceng, fangjian, area), fire_extinguisher(fire), phone_count(phone) { if (fire_extinguisher < 0) { fire_extinguisher = 0; } if (phone_count < 0) { phone_count = 0; } } //显示信息 void show()const { Builing::show(); cout << "办公室信息" << endl; cout << "灭火器数量" << fire_extinguisher << endl; cout << "电话数量" << phone_count << endl; } }; int main() { Builing* b1 = nullptr, * b2 = nullptr; House house(3, 8, 120, 2, 4); b1 = &house; Office office(3, 8, 120, 8, 4); b2 = &office; b1->show(); cout << endl; b2->show(); return 0; }建立普通的基类Building,用来存储一座楼房的层数、房间数以及它的总平方米数。建立派生类House,继承Building,并存储下面的内容:卧室与浴室的数量。另外,建立派生类Office,继承Bu
张小明
前端开发工程师
【JPCS出版,有ISSN号,高录用,EI稳检索,福州大学、青岛大学威海创新研究院联合主办,Fellow报告,会议有保障】2026年能源、电力与可持续发展国际学术会议(EESD 2026)
2026年能源、电力与可持续发展国际学术会议(EESD 2026) 2026 International Conference on Energy, Electricity and Sustainable Development 2026年3月6-8日 中国昆明(可线上参会) JPCS出版!有ISSN号,…
【广东工业大学主办,SAE出版,EI快速稳定检索,学术大咖加盟 | 低空经济、交通系统、机器制造、供应链网络、无人机等主题均可投递】 2026年低空经济与技术应用国际学术会议 (LETA 2026)
2026年低空经济与技术应用国际学术会议 (LETA 2026) 2026 International Conference on Low - altitude Economy and Technology Application 低空经济、交通系统、机器制造、技术应用、供应链网络、无人机等主题均可投递 SAE出版!EI&SCOPUS快速稳定检索&…
【悬臂梁挠度问题】基于PINN物理信息神经网络计算一维悬臂梁挠度问题附Python代码
✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。 🍎 往期回顾关注个人主页:Matlab科研工作室 🍊个人信条:格物致知,完整Matlab代码及仿真…
软件时代正在终结?2026,一场静默的AI革命正重塑我们的工作与未来
当AI能自动写代码、维护系统、搬运数据,软件公司靠“复杂性”构筑的护城河,正在一夜干涸。就在几天前,硅谷四位顶级投资人的一场闭门对话,意外释放出一个令人警醒的信号:5000亿美元资本正悄然撤离软件赛道。这不是周期…
用了一年Cursor,我的代码能力反而退化了
昨天晚上,我盯着屏幕发了半小时呆。 不是在等编译,是在等AI生成代码——然后我发现,离开AI提示,我竟然写不出一个完整的React组件了。 手指悬在键盘上,脑子一片空白。 这种感觉,就像你开了三年自动挡&am…
AI原生应用助力业务流程增强的实战指南
AI原生应用助力业务流程增强的实战指南 关键词:AI原生应用、业务流程增强、大语言模型(LLM)、智能自动化、人机协作 摘要:本文从企业业务流程的实际痛点出发,系统讲解"AI原生应用"这一新一代技术形态如何从底…