面向对象软件工程 第三章 答案
- 格式:pdf
- 大小:472.06 KB
- 文档页数:4
面向对象程序设计课后答案(完整版)第二章2-4#includeusing namespace std;Add(int a,int b);int main(){int x,y,sum;cout>x>>y;sum = add(x,y);cout >*p;p++;}p = p-20;for( i=0;i0) countp++;if(*p>age ;try{checkagescore(name,age);}catch( string){cout<<"exception :name is exit"<<endl;continue;}catch(int){cout<<"exception :age is not proper"<<endl;continue;}cout<<"name:"<<name<<" age :"< }return 0;}第三章3-1(1)A (2)C (3)B (4)C (5)C(6)B (7)B (8)C (9)C3-7(1)main()函数中p1.age = 30;语句是错误的。
age 是类的私有成员(2)构造函数应当给常数据成员和引用成员初始化,将构造函数改为:A(int a1,int b1):a(a1),b(b1){}或A(int a1 ):a(a1),b(a){}再将main中的A a(1,2); 改为A a(1);(3)(1)在Test 类中添加语句:void print();void Print(){cout<<x<<"-"<<y<<"="<<x-y<<endl;}改为void Test::Print(){cout<<x<<"-"<<y<<"="<<x-y<<endl;}main函数中Init(38,15);改为:A.Init(38,15);Print();改为:A.Print();3-8(1)Constructing AConstructing BDestructing BDestructing A(2)double a,double bpoint & pp.x3-9class box{int len1,len2,len3;public:box(int l1,int l2,int l3){len1 = l1;len2 = l2; len3 = l3;} long volumn(){return len1*len2*len3;}};3-10class Test{int m1,m2;public:void Init(int a,int b){m1 = a;m2 = b;}void Pring(){cout<<m1<<" "<<m2<<endl;}};3-11略3-12}第四章4-6(1)D (2)D (3)D (4)D (5)B(6)D4-7(1)static int count = 0;这样初始化静态成员值是不对的将其改为static int count;在类外,main函数前加int Sample::count = 0;(2)#include//#includeusing namespace std;class Ctest{private:int x; const int y1;public:const int y2;Ctest(int i1,int i2):y1(i1),y2(i2) {y1 =10;//y1 为常量不能赋值x = y1;}int readme() const;};int Ctest::readme ()const{int i;i = x;x++; //常函数内不能改变成员值return x;}int main(){Ctest c(2,8);int i = c.y2;c.y2 = i;//y2为常量,不能改值i = c.y1;//y1私有,类外不能访问return 0;}将出错语句全部注释4-8(1)题中印刷错误,将class C构造函数改为: C(){cout<<"constructor C:";}运行结果为:constructor Aconstructor Bconstructor C(2)40(3)3434-9#include#includeclass Date{int year;int month;int day;public:Date(int y,int m,int d){year=y;month=m;day=d;}void disp(){cout<<year<<" "<<month<<" "<<day<<endl;}friend int count_day(Date &d,int k);friend int l(int year);friend int h(Date &d1,Date &d2);};int count_day(Date &d,int k){static int day_tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,3 1},{31,29,31,30,31,30,31,31,30,31,30,31}};// 使用二维数组存放各月天数,第一行对应非闰年,第二行对应闰年int j,i,s;if(l(d.year))j=1;//闰年,取1else j=0;//非闰年,取0if(k)//K非0时{s=d.day;for(i=1;i<d.month;i++)//d.month为输入的月份s+=day_tab[j][i-1];}else//K为0时{s=day_tab[j][d.month]-d.day;for(i=d.month+1; i<=12; i++)s+=day_tab[j][i-1];}return s;//S为相差的天数}int l(int year){if(year%4==0&&year%100!=0||year%400==0) // 是闰年return 1;else // 不是闰年return 0;}int h(Date &d1,Date &d2){int days,day1,day2,y;if(d1.year<d2.year)//第一个日期年份小于第二个日期年份{days=count_day(d1,0);for(y=d1.year+1;y<d2.year;y++)if(l(y))//闰年。
第三章测验一、单选题(共40.00分)1. 状态是任何可被观察到的系统()。
A. 外部接口B. 动作C. 行为模式D. 信息流动正确答案:C2. ()是复审需求分析成果时的焦点。
A. 代码B. 需求规格说明C. 模型D. 计划正确答案:C3. 在对数据流图分层细化时必须保持()。
A. 信息连续性B. 信息流封闭C. 不产生新信息D. 输入数据与输出数据平衡正确答案:A4. 一张状态图中只能有一个()。
A. 初态B. 终态C. 中间状态D. 以上都不正确正确答案:A二、多选题(共33.00分)1. DFD的基本符号包括()。
A. 数据的源点或终点B. 变换数据的处理C. 数据存储D. 数据流正确答案:A B C D2. ()通常不会出现在DFD中。
A. 输入数据处理B. 出错处理C. 内务处理(如打开/关闭文件)D. 数据合并正确答案:B C3. 支持分层细化的图形有()。
A. 数据字典B. ER图C. DFDD. STD正确答案:C D三、判断题(共27.00分)1. 需求分析是开发方的工作,用户的参与度不大。
()A. 正确B. 错误正确答案:B答案解析:用户与分析员应密切合作共同分析需求2. 结构化分析实质上就是一种建模活动。
()A. 正确B. 错误正确答案:A3. 模型是验证规格说明的完整性、一致性和准确性的重要依据。
()A. 正确B. 错误正确答案:A。
C++⾯向对象程序设计第三章习题答案解析整理⼀下⾃⼰写的作业,供考试前复习⽤,哈哈进⼊正题题⽬:2.分析下⾯的程序,写出其运⾏时的输出结果这⾥就不展⽰课本源代码,直接给出修改后的代码,错误部分代码已给出具体的注释1 #include<iostream>2//原题的#include<iostream.h>写法错误3 #include<stdlib.h>4//⽤于解决闪屏的头⽂件5using namespace std;6//原题缺少该⾏代码,⽤于输⼊cin和输出cout7class Date{8public:9 Date(int,int,int);10 Date(int,int);11 Date(int);12 Date();1314void display();15private:16int month;17int day;18int year;1920 };2122 Date::Date(int m,int d,int y):month(m),day(d),year(y){}2324 Date::Date(int m,int d):month(m),day(d)25 {year=2005;}2627 Date::Date(int m):month(m)28 {day=1;year=2005;}2930 Date::Date()31 {month=1;day=1;year=2005;}3233void Date::display()34 {35 cout<<month<<"/"<<day<<"/"<<year<<endl;36 }3738int main()39 {40 Date d1(10,13,2005);41 Date d2(12,30);42 Date d3(10);43 Date d4;44 d1.display();45 d2.display();46 d3.display();47 d4.display();48 system("pause");49//解决闪屏的代码50return0;51 }运⾏结果:3.如果将第2题中程序的第四⾏改为⽤默认参数,即Date(int =1,int =1,int =2005);分析程序有⽆问题。
面向对象软件工程答案【篇一:软件工程考试试题与答案】txt> 一、单项选择题1.好的软件结构应该是()a.低耦合、低内聚b.高耦合、高内聚c.高耦合、低内聚d.低耦合、高内聚答案: d2.需求分析中开发人员要从用户那里了解()a.软件的规模b.软件做什么c.用户使用界面d.输入的信息答案: b3.软件调试技术包括()a.演绎法b .循环覆盖c .边界值分析 d .集成测试答案: a4.软件需求规格说明书的内容不应包括对()的描述。
a.用户界面及运行环境b .主要功能c .算法的详细过程 d .软件的性能答案: c5.常用动词或动词词组来表示()a.属性b.关联c.类d.对象答案: b6.软件可行性研究实质上是要进行一次()需求分析、设计过程。
a.详细的b.深入的c.彻底的d.简化、压缩的答案: d7.软件部分的内部实现与外部可访问性分离,这是指软件的()a.继承性b.共享性c.抽象性d.封装性答案: d8.软件部分的内部实现与外部可访问性分离,这是指软件的()a.共享性b.继承性c.抽象性d.封装性答案: d9.在详细设计阶段,经常采用的工具有()a.pdlb. dfdc.scd.sa答案: a10.数据字典是对数据定义信息的集合,它所定义的对象都包含于()a.软件结构b .程序框图c .方框图d .数据流图答案: d11.软件工程结构化生命周期方法,提出将软件生命周期划分为计划、开发和运行三个时期,下述()工作应属于软件开发期的内容。
a.问题定义b.可行性研究c.都不是d.总体设计答案: d12 .应用执行对象的操作可以改变该对象的()a.功能b .数据c .属性d .行为答案: c13 .软件质量因素不包括()a.可理解性b .可测试性 c .正确性 d .高性能答案: d14 .软件可行性研究实质上是要进行一次()需求分析、设计过程。
a.详细的b .彻底的c .深入的d .简化、压缩的答案: d15 .结构化设计是一种面向()的设计方法。
第一章软件工程概述软件工程的基本原则是什么?1,抽象:采用分层次抽象,自顶向下逐层细化的办法控制软件开发过程的复杂性。
2,模块化:模块化有助于信息隐蔽和抽象,有助于表示复杂的系统。
3,信息隐蔽:将模块化设计成“黑箱”,实现的细节隐蔽在模块内部,不让模块的使用直接访问,这就是信息封装。
4,局部化:保证模块之间具有松散的耦合,模块内部具有较强的内聚,这有助于控制模块的复杂性5,一致性:整个软件系统使用一致的概念符号和术语。
6,完整性:软件系统不丢失任何重要成分,可以完全实现系统所要求功能的程度。
7,不可验证性:易于检查、测试、评审,确保系统的正确性。
第二章可行性研究选择题1,研究开发所需要的成本和资源属于可行性研究中(经济可行性)研究的一方面。
2,可行性分析研究的目的是(项目值得开发与否)。
3,软件分析的第一步要做的工作在于(分析系统开发的可行性)。
4,可行性研究目的主要在于(用最小的代价确定问题定义阶段所确定的目标和规模是否可实现,可解决)。
5,软件可行性分析是着重确定系统的目标和规模。
对功能,性能及约束条件的分析应属于下列(技术可行性分析)。
简答题简述可行性研究的步骤?1,复查系统规模和目标2,研究目前正在使用的系统3,导出新系统的高层逻辑模型4,重新定义问题5,导出和评价供选择方案6,推荐一个方案并说明理由7,推荐行动方针8,书写计划任务书9,提交审查应用题设计一个软件的开发成本为5万元,寿命为3年。
未来3年的每年收益预计为22000元,24000元,26620元,银行年利率为10%。
试对此项目进行成本效益分析,以决定其经济可行性。
答:设银行的年利率是10%,则下列出每年的收益第一年:22000/1.1=20000第二年:24000/1.21=19834.71第三年:26620/1.331=20000因此:现有值收益为20000+19834.71+20000=59834.71投资回收期2+10165/20000=2.51纯收入59835-50000=9834.71第三章需求分析需求分析的原则有哪些?1.需求分析方法应该容易被用户理解。
面向对象程序设计课后习题答案第一章:面向对象程序设计概述[1_1]什么是面向对象程序设计?面向对象程序设计是一种新型的程序设计范型。
这种范型的主要特征是:程序=对象+消息。
面向对象程序的基本元素是对象,面向对象程序的主要结构特点是:第一:程序一般类的定义和类的使用两部分组成,在主程序中定义各对象并规定它们之间传递消息的规律。
第二:程序中的一切操作都是通过向对象发送消息来实现的,对象接受到消息后,启动有关方法完成相应的操作。
面向对象程序设计方法模拟人类习惯的解题方法,代表了计算机程序设计新颖的思维方式。
这种方法的提出是软件开发方法的一场革命,是目前解决软件开发面临困难的最有希望、最有前途的方法之一。
[1_2]什么是类?什么是对象?对象与类的关系是什么?在面向对象程序设计中,对象是描述其属性的数据以及对这些数据施加的一组操作封装在一起构成的统一体。
对象可以认为是:数据+操作在面向对象程序设计中,类就是具有相同的数据和相同的操作的一组对象的集合,也就是说,类是对具有相同数据结构和相同操作的一类对象的描述。
类和对象之间的关系是抽象和具体的关系。
类是多个对象进行综合抽象的结果,一个对象是类的一个实例。
在面向对象程序设计中,总是先声明类,再类生成对象。
类是建立对象的“摸板”,按照这个摸板所建立的一个个具体的对象,就是类的实际例子,通常称为实例。
[1_3]现实世界中的对象有哪些特征?请举例说明。
对象是现实世界中的一个实体,其具有以下一些特征:每一个对象必须有一个名字以区别于其他对象。
需要用属性来描述它的某些特性。
有一组操作,每一个操作决定了对象的一种行为。
对象的操作可以分为两类:一类是自身所承受的操作,一类是施加于其他对象的操作。
例如:雇员刘名是一个对象对象名:刘名对象的属性:年龄:36 生日:工资:2000 部门:人事部对象的操作:吃饭开车[1_4]什么是消息?消息具有什么性质?在面向对象程序设计中,一个对象向另一个对象发出的请求被称为“消息”。
软件工程智慧树知到课后章节答案2023年下山东财经大学山东财经大学第一章测试1.软件没有相应的文档,且最终不能满足用户要求是软件危机的一种表现。
()答案:对2.软件本身的不可见性和复杂性随规模的增加呈指数上升是产生软件危机的主要原因。
()答案:错3.开发软件就是写程序。
()答案:错4.开发软件所需高成本和产品的低质量之间有着尖锐的矛盾,这种现象称()。
答案:软件危机5.以下对软件工程描述正确地是()。
答案:采用经过时间考验而证明正确的管理技术。
;一门工程学科。
;经济地开发出高质量的软件并有效地维护它。
;结合最好的技术方法。
6.软件生命周期中所花费费用最多的阶段是()。
答案:软件维护。
7.软件是()。
答案:程序、数据及其文档的集合。
8.同螺旋模型相比,原型模型主要缺少()。
答案:风险分析9.在软件生存周期模型中,不适应变化需求的软件开发模型是()。
答案:瀑布模型10.针对高质量软件的生产的软件过程模型()。
答案:净室模型第二章测试1.可行性研究的技术可行性是指现有技术是否可行。
()答案:对2.可行性研究的成本效益分析是从经济方面讨论是否可行。
()答案:对3.可行性分析研究的目的是()。
答案:项目值得开发否4.描绘物理系统的传统工具是()。
答案:系统流程图5.数据字典的基本功能是()。
答案:数据定义。
6.使用数据流图对工资系统进行需求分析建模,外部实体是()。
答案:接受工资单的银行7.数据流图的作用包括()。
答案:可以逻辑模型考虑系统的物理实现;作为交流信息的工具;作为分析和设计的工具8.典型环境下各个开发阶段需要使用的人力的百分比最多的是()。
答案:综合测试第三章测试1.需求分析阶段的产品是()。
答案:需求规格说明书。
2.进行需求分析可使用多种工具,但是()不适用。
答案:PAD图3.软件需求规格说明的内容不应该包括()。
答案:算法的描述。
4.在考察系统的一些涉及时序和改变的状况时,要用动态模型来表示。
Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises3. Project Communication: Solutions3-1What is the difference between a role and a participant?A participant is an individual. A role corresponds to a set of responsibilities. A single participant can assume many roles. Some roles may be shared among more than one participant.3–2Can a role be shared between two or more participants? Why or why not?Some roles are assigned to more than one participant. For example, a team of developers can be assigned to the same subsystem. Other roles, such as chief architect or project manager, can only be assigned to a single participant in the project. In the end, the issue is one of assigning clear and non-overlapping tasks to single participants: When two or more participants are responsible for exactly the same task, none of them will feel personally responsible for the success of the task.3–3What is the difference between a client and an end user?The client contracts the development of a system. The client is responsible for defining the scope of the system and for financing the project. The end users are the participants who actually uses the system to accomplish their work. In some project, the role of end user and client may be shared by the same participant. In general, however, this is not the case.3–4To which roles would you assign the following tasks?•Change a subsystem interface to accommodate a new requirement. [system architect]•Communicate the subsystem interface change to other teams. [API engineer (liaison)]•Change the documentation as a result of the interface change. [editor]•Design a test suite to find defects introduced by the change. [tester]•Ensure that the change is completed on schedule. [project manager or team leader]3–5You are responsible for coordinating the development of a system for processing credit applications for a bank.In what roles would the following project participants be able to contribute most to the project?• a bank employee responsible for processing credit applications [end user]•the manager of the information technology group at the bank, who contracted the system [client]• a free-lancer who developed similar systems in the past [developer]• a technical writer [editor]3–6Draw a UML activity diagram representing the meeting process described in Section 3.4.3. Focus in particular on the work products generated before and after the meeting, such as the agenda and the meeting minutes. Use swimlanes to represent roles.Figure 3-1 depicts an example solution. This exercise tests the student’s knowledge of the meeting process and of activity diagrams described in Chapter 2.3–7What is the difference between a work package and a work product?A work package is a description of work. A work product is the actual result of work (e.g., a document, a pieceof code, etc.).When is a work package defined?During planning.Consider an assignment where two students collaborate to plan and develop a system for sorting lists of names using two different sort algorithms. The deliverables for the assignment are the source code, the system documentation, and a manual for other developers explaining how new sorting algorithms can be integrated into the code. Give examples of work packages and work products in this project.Examples of work packages:•Plan developmentObject-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to ExercisesFigure 3-1An example meeting process (UML activity diagram).•Define and document interface between system and sort algorithms•Implement algorithms•Document systemExamples of work products:•development plan•source code•system documentation•manual for explaining how to integrate new sorting algorithms3–8What is the difference between a cross-functional team and a subsystem team? Provide examples and justify your choices.Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to ExercisesA subsystem team is completely responsible for the development of a subsystem.A cross-functional team is made out of liaison of subsystem teams and is responsible for support tasks, such as documentation and configuration management. Also, the system architecture can is often defined by a cross-functional team made out of liaison from all subsystem teams.3–9As many critical communication events are planned (e.g., client reviews, project reviews, peer reviews), why is there still a need for unplanned communication events (e.g., request for clarification, request for change, issue resolution)?There are many reasons for unplanned communication. Some of the more important ones are:•Reduce latency: While developers could wait for the next project review to request clarification on their tasks or on interfaces provided by other teams, this would slow down development significantly and introduce much rework (e.g., correcting code that was developed under incorrect assumptions).•React to unexpected events: Any system of a realistic size cannot be completely specified and understood a priori. This results in requirements and design changes during development, which often have to becommunicated and negotiated among several stakeholders. While change processes can be set in place to manage this communication, much unplanned and informal communication complements the formal communication events to motivate, clarify, understand, gauge, and negotiate the underlying issues introduced by the change.•Team building: Formal communication events are rarely conducive to a team atmosphere. It is during unplanned and informal events that participants get know each other and form a community working towards a common goal.3–10Select a random working day in your work week. Log all activities that qualify as communication activities(e.g., talking to friends over coffee, obtaining information from a fellow student, providing information,negotiating, advertising, browsing the web). Which fraction of your working day does communication represent?Typically, the fraction of the day spent of communication can easily reach 50% or more. However, there will be a wide variance in the numbers reported by the students, depending on whether or not they are currently doing project work.3–11You are a member of the user interface team. You are responsible for designing and implementing forms collecting information about users of the system (e.g., first name, last name, address, E-mail address, level of expertise). The information you are collecting is stored in the database and used by the reporting subsystem.You are not sure which fields are required information and which are optional. How do you find out?This is an open-ended question whose purpose is to have the student think of all the communication paths available. The side effect of this question is that the student will also have to think about the information sources associated with a project. A correct answer should contain at least two of the following points:•The user interface team member should first check the requirements analysis document, described in Chapter 1.•If the answer is not in the requirements analysis document, or if the answer is not clear, the document is incomplete or does not exist yet, in which case the user interface team member should ask the responsible analyst on the project. This is a request for change or a request for clarification.•If the analyst does not have the answer, he or she should investigate with a potential user and possibly get approval from the client. This is also a request for clarification.•In all cases, the answer should eventually make its way into the requirements analysis document.3–12You have been reassigned from the user interface team to the database team due to staff shortages and replanning. The implementation phase is well underway. In which role would you be most proficient given your knowledge of the user interface design and implementation?Liaison of the database team to the user interface team.Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises3–13Assume the development environment is Unix workstations, and the documentation team uses the Macintosh platform for writing documentation. The client requires the documents to be available on Windows platforms.Developers produce the design documentation using FrameMaker. The documentation team uses Microsoft Word for the user-level documentation. The client submits corrections on hardcopies and does not need to modify the delivered documents. How could the information flow between the developers, the technical writers, and the client be set up (e.g., format, tools, etc.) such that duplication of files is minimized while everybody’s tool preferences and platform requirements are still satisfied?This is a simple real life question with complicated answers. Several approaches are possible, including:•The project uses a printable format as a standard interchange format, such as Postscript or PDF (Portable Display Format). This allows every participant to access and view documents. Only the author of a document is able to make changes, however. This makes it difficult to move the document responsibility to move from one team to another (e.g., from a subsystem team to the documentation team).•The project uses an interchange format such as RTF or XML for all documents. Both formats are recognized by recent versions of both Microsoft Word and FrameMaker. This allows document responsibilities to be transferred between developers and technical writers. Unfortunately, this is currently not a practical solution as both tools understanding of the interchange formats is different and imperfect, resulting in some loss of formatting.3–14Which changes in the organization and communication infrastructure would you recommend for a successor of the Ariane 5 project as a consequence of the Ariane 501 failure described at the beginning of this chapter?This is an open-ended question as many solutions exist and detailed knowledge of the current team organization are not available. Note that this question is only interested in communication or organizational changes, not technical or methodological changes. A correct answer could include the following points:•Increase communication between the team responsible for system testing and the software developers. This can be done by introducing liaisons on both teams.•Increase communication between the team responsible for unit testing and for system testing.•Change documentation requirements for reused components.。