版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PAGE1面向对象程序设计上机考试班级:学号:姓名:时间120分钟说明:所有程序都来自教材中的例题,并对个别地方进行修改,务必仔细阅读程序。评分原则:除了特别说明外,每个题目如能得到正确结果,就得满分,否则得零分。要求:集成编码环境指定为VS2013,分析设计工具为POWERDESIGNER,要求将结果截屏粘贴在题目后面,并保存到一个PDF文件,其文件名格式为【学号_姓名.pdf】,最终提交这个文件。第一部分编码调试(每题20分,共60分)1、编辑运行程序编辑、编译、连接下面的程序,最后运行。答案:结果正确2结果正确20分2、调试程序修复下面程序的Bug。#include<iostream>usingnamespacestd;classPoint{public: Point(intx,inty){ cout<<"构造Point("<<x<<","<<y<<")"<<endl; x=x; y=y; } Point(constPoint&oldPoint){ cout<<"拷贝构造Point("<<oldPoint.x<<","<<oldPoint.y<<")"<<endl; memcpy(this,&oldPoint,sizeof(Point)); } ~Point(){ cout<<"析构Point("<<x<<","<<y<<")"<<endl; }private: intx; inty;};intmain(){ Pointp1(2,3); Pointp2(p1);}答案:构造函数Point(intx,inty)对成员变量的赋值方式不正确,改成this->x=x;this->y=y;答案不一,能正确赋值即可,2答案不一,能正确赋值即可,20分结果正确20分3、编写代码根据下面的类图和时序图编写矩形类Rectangle代码和main函数代码,贴出代码截图和运行结果截图。答案:类正确10类正确10分,main()正确5分,有运行截图5分第二部分设计程序(每题20分,共40分)1、使用类图描述程序的静态结构1)阅读下面的程序,画出程序的类图,建立程序的静态模型。#include<iostream>#include<string>usingnamespacestd;classDepartment{public: Department(stringname){ this->name=name; } voidprint(){ cout<<name<<endl; }private: stringname;};classEmployee{public: Employee(stringname){ this->name=name; } Employee(stringname,Department&department){ this->name=name; this->department=&department; } voidbelongTo(Department&department){ this->department=&department; } voidprint(){ cout<<"我是:"<<name<<",我所在的部门是:"; department->print(); }private: stringname; Department*department=NULL;};intmain(){ Departmentdepartment1("研发部"); Employeeemployee1("张三"); employee1.belongTo(department1); employee1.print(); Departmentdepartment2("财务部"); Employeeemployee2("李四",department2); employee2.print();}类图各2分,连接类图各2分,连接1分2)生成代码请将题中所有成员函数的实现代码复制到其静态模型,采用正向工程生成程序的源代码,并与原来的源代码进行比较。5分5分1.将函数Employee(stringname,Department&department)的复制界面截图;2分4个文件各2分2.调试PowerDesigner2分4个文件各2分3.贴出运行结果图。答案:1.2./************************************************************************Module:Department.h*Author:MrWong*Modified:2023年6月28日11:09:36*Purpose:DeclarationoftheclassDepartment***********************************************************************/#if!defined(__上机B_Department_h)#define__上机B_Department_h单独添加#include<string>单独添加classDepartment{public:Department(std::stringname);voidprint(void)const;protected:private:std::stringname;};#endif/************************************************************************Module:Employee.h*Author:MrWong*Modified:2023年6月28日11:09:36*Purpose:DeclarationoftheclassEmployee***********************************************************************/#if!defined(__上机B_Employee_h)#define__上机B_Employee_h单独添加单独添加#include<string>#include"Department.h"classEmployee{public:Employee(std::stringname);Employee(std::stringname,Department&department);~Employee();voidbelongTo(Department&department);voidprint(void);protected:private:std::stringname;Department*department;};#endif/************************************************************************Module:Department.cpp*Author:MrWong*Modified:2023年6月28日11:09:36*Purpose:ImplementationoftheclassDepartment***********************************************************************/单独添加单独添加#include"Department.h"#include<iostream>usingnamespacestd;//////////////////////////////////////////////////////////////////////////Name:Department::Department(std::stringname)//Purpose:ImplementationofDepartment::Department()//Parameters://-name//Return:////////////////////////////////////////////////////////////////////////Department::Department(std::stringname){ this->name=name;}//////////////////////////////////////////////////////////////////////////Name:Department::print()//Purpose:ImplementationofDepartment::print()//Return:void////////////////////////////////////////////////////////////////////////voidDepartment::print(void)const{ cout<<name<<endl;}/************************************************************************Module:Employee.cpp*Author:MrWong*Modified:2023年6月28日11:09:36*Purpose:ImplementationoftheclassEmployee***********************************************************************/单独添加单独添加#include"Employee.h"#include<iostream>usingnamespacestd;//////////////////////////////////////////////////////////////////////////Name:Employee::Employee(std::stringname)//Purpose:ImplementationofEmployee::Employee()//Parameters://-name//Return:////////////////////////////////////////////////////////////////////////Employee::Employee(std::stringname){ this->name=name;}//////////////////////////////////////////////////////////////////////////Name:Employee::Employee(std::stringname,Department&department)//Purpose:ImplementationofEmployee::Employee()//Parameters://-name//-department//Return:////////////////////////////////////////////////////////////////////////Employee::Employee(std::stringname,Department&department){ this->name=name; this->department=&department;}//////////////////////////////////////////////////////////////////////////Name:Employee::~Employee()//Purpose:ImplementationofEmployee::~Employee()//Return:////////////////////////////////////////////////////////////////////////Employee::~Employee(){ //TODO:implement}//////////////////////////////////////////////////////////////////////////Name:Employee::belongTo(Department&department)//Purpose:ImplementationofEmployee::belongTo()//Parameters://-department//Return:void////////////////////////////////////////////////////////////////////////voidEmployee::belongTo(Department&department){ this->department=&department;}//////////////////////////////////////////////////////////////////////////Name:Employee::print()//Purpose:ImplementationofEm
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 劳动创造价值热爱劳动实践小学主题班会课件
- 网络安全管理与合规性操作手册
- 2026年软装设计SPA空间规划
- 航空旅客行李托运规程与注意事项指南
- 关于合作伙伴技术交流会议的邀请函(7篇)
- 分布式能源建设方案
- 智能体构建与应用开发(Python+LangChain)-教案 项目1-4 认识大语言模型和智能体-实现对话上下文记忆管理
- 处级领导考试试题及答案
- 智能炒菜机项目可行性研究报告
- 能源储存技术市场深度剖析及发展趋势与投资前景展望研究报告
- 企业导师带徒弟培训课件
- 企业资产管理制度模板通则
- 中石油购油协议书
- 手工编织手绳课件
- 农产品贮藏与营销课件
- 液压基础知识培训入门课件
- 《电动商用车动力域控制系统功能安全要求及试验方法》
- 隧洞安全生产培训内容课件
- 定向钻施工技术交底详细方案
- 非法采矿案例课件
- 二氧化硅的气化温度
评论
0/150
提交评论