高级数据库系统作业答疑

上传人:飞*** 文档编号:57155597 上传时间:2018-10-19 格式:PPT 页数:44 大小:1.77MB
返回 下载 相关 举报
高级数据库系统作业答疑_第1页
第1页 / 共44页
高级数据库系统作业答疑_第2页
第2页 / 共44页
高级数据库系统作业答疑_第3页
第3页 / 共44页
高级数据库系统作业答疑_第4页
第4页 / 共44页
高级数据库系统作业答疑_第5页
第5页 / 共44页
点击查看更多>>
资源描述

《高级数据库系统作业答疑》由会员分享,可在线阅读,更多相关《高级数据库系统作业答疑(44页珍藏版)》请在金锄头文库上搜索。

1、高级数据库系统作业答疑,2007.11,第一次作业,7.2解:第三句有问题,左边为string类型,右边是City类型。cityOfLA.name := cityOfLA.mayor.spouse.livesIn; 7.4解:前一种的输出结果为:Donald DuckMickey Mouse后一种的输出结果为:6060因为前一种是引用语义,而后一种是复制语义。,第一次作业,7.7 引用:共享子对象,一个对象被两个或者多个对象引用。例如: someMaterial := id88; 隐式引用:赋值语句处理对象时,将该对象的对象表示OID赋给相应的变量或属性。例如: myCuboid.mat :=

2、 someMaterial; someMaterial.create; 隐式重引用:引用语义随着引用链的传递。通过“.”操作符的重载构造的引用链来实现。例如: w := myCuboid.mat.specWeight; 复制语义的:将一个值直接复制到变量或属性中。 引用:相当于地址的复制,类似于C+的指针。例如: anotherMaterial := myCuboid.mat; myCuboid.mat.create;,第一次作业,7.9解:(1)(2)执行完毕后,mary.children = joe.children = littleJoe,第一次作业,(3)(4)执行完毕后, betty

3、.children = jimbo jim.children = ,第二次作业,8.8persistent type Cuboid ispublic length, width, height, surface, volume, weight, translate, scale, rotate, certer, diagonal, minDistance;body v1, v2, v3, v4, v5, v6, v7, v8 : Vetex; mat : Material; value : float;operationsdeclare surface : float;declare scal

4、e : Vertex voidcode scaleCuboid;declare center : Vertex;declare diagonal: float;declare minDistance : Vertex floatcode minDistanceCode;,第二次作业,implementationdefine surface isreturn 2.0 * (self.length*self.width + self.length*self.height + self.width*self.height);define scaleCuboid(s) is beginself.v1.

5、scale(s);self.v8.scale(s);end define scaleCuboid;,第二次作业,define center isvar c : Vertex;beginc.create;c.x = 0.5 * (self.v1.x + self.v7.x);c.y = 0.5 * (self.v1.y + self.v7.y);c.z = 0.5 * (self.v1.z + self.v7.z);return c;end define certer; define diagonal isreturn self.v1.distance(self.v7);,第二次作业,defin

6、e minDistanceCode(v) isvar v0;begin/将长方体的6个面无限延伸,可将整个空间分为27个区域if (v在长方体内部或表面上)return 0;else begin根据v所在区域,可简单判断出长方体上距v最近的点v0所在 的面/棱/顶点,进而求出v0;return v.distance(v0);end elseend deine minDistanceCode; end type Cuboid;,第二次作业,9.1 答:(1)方法一采用1:1关系表示1:N关系,存在较多冗余;不考虑索引,已知left查询对应的right集时,方法二效果明显好 于方法一;已知righ

7、t查询对应的left时,方法一效果好于方法二。当插入新关系时,两种方法都无法保证一致性,即原关系 1:N的语义约束可能被违反,需要对insert操作做修改,保证每一 个Tright实例仅有至多一个对应的Tleft实例。 删除关系时,方法一中直接删除对应的TR实例,方法二中 只需修改right集合,直到right集合为空时,才需要删除对应的TR 实例。更新操作由插入删除操作组合而成,不再讨论。(2)方法一、二的insert操作均需修改,以保证一致性,方法二的 delete操作也需要修改。修改思想上边已说明,具体算法不再给 出。,第二次作业,9.7 答:在对象内部设计一个计数器对于专用对象,生成实

8、例,置为,当实例被引用,置为;对于依赖对象,引用则加一,不再引用就减一,当计数器为的时候,就删除对象,第三次作业,10.5解:declare connect : Pipe | Pipe void;refine connect : ConicalPipe | ConicalPipe void;一个合法的重定义要求:操作名不变,参数个数不变;操作的接收者类型是原操作中接收者类型的子类;操作的返回值类型是原操作返回值的子类;操作的参数类型是原操作参数类型的超类。题中的重定义仅满足(1)(2)(3),但违反(4)。ConicalPipe是Pipe的子类而非超类,故不合法。考虑下面的程序段:var aP

9、ipe, anotherPipe : Pipe;aConicalPipe : ConicalPipe;anotherPipe := aConicalPipe; /可替换性,合法anotherPipe.connect(aPipe); /编译通过,执行时由于动态绑定,出错,第三次作业,10.6解:继承属性的类型是不能重定义的,必须保持原类型。(1) 子类中继承属性的类型不能是该类型的子类,即特化不合法。特化举例:type Person isbody name : string;age : int;type Employee supertype Person isbody boss : Employ

10、ee;type Manager supertype Employee isbody refine boss : Manager;,第三次作业,程序段:var anEmp : Employee;aMgr : Manager;aMgr.boss := anEmp; /语法错误anEmp.boss := aMgr; /可替换性,合法anEmp.boss.boss := anEmp; /语法检查合法,但有潜在问题(2) 子类中继承属性的类型不能是该类型的超类,即泛化不合法。Person和Employee的类型定义同上, Manager类型定义如下:type Manager supertype Empl

11、oyee isbody refine boss : Person;程序段:var aPerson : Person;anEmp : Employee;aMgr : Manager;anEmp.boss := anEmp; /合法aMgr.boss := anEmp; /可替换性,合法aMgr.boss.boss := anEmp; /语法错误,第三次作业,12.3解:(1)Polymorph declare member (ListType ) : ListType | ElemType bool;define member (t) isvar item : ElemType;beginfor

12、each (item in self)if (item = t)return true;return false;end define member;,第三次作业,(2)Polymorph declare nthmember (ListType ) :ListType | int ElemType;define nthmember (n) isvar i : int;item : ElemType;Beginif (n self.length | n = 1 ,第四次作业,13.5 Assume a Swiss Knife consists of a blade of a certain le

13、ngth that is able to cut different kind of material. A small scissor that is able to cut paper and a screwdriver are also provided. Last but not least a corkscrew completes it. Every tool has a certain length and provides a certain capability. Model a Swiss knife using multiple inheritance. Try an a

14、lternative modeling with single inheritance only where the Swiss knife solely is-a knife, which additionally consists of the other tools. What is the difference?,第四次作业,多继承缺点: 1.IS-A语义不清 2.方法需要重定义以避免冲突 3.某个部件不能作为单独的部件使用 单继承多置换: 单独的部件可以作为整个对象来使用,使用灵活。,第四次作业,14.8 Retrieve all Emps who earn more than their Manager. But note that Managers ara also Emps and may work in their own Dept.select e from e in EMP where e.salary e.worksin.mgr.salary;,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号