null高级数据库系统作业答疑高级数据库系统作业答疑
2007.11第一次作业 第一次作业 7.2
解:第三句有问
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
,左边为string类型,右边是City类型。
cityOfLA.name := cityOfLA.mayor.spouse.livesIn;
7.4
解:前一种的输出结果为:
Donald Duck
Mickey Mouse
后一种的输出结果为:
60
60
因为前一种是引用语义,而后一种是复制语义。
第一次作业第一次作业7.7
引用:共享子对象,一个对象被两个或者多个对象引用。
例如: someMaterial := id88;
隐式引用:赋值语句处理对象时,将该对象的对象
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
示OID赋给相应的变量或属性。例如: myCuboid.mat := 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.children = {jimbo}
jim.children = {}
第二次作业第二次作业8.8
persistent type Cuboid is
public 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;]
operations
…
declare surface : float;
declare scale : Vertex void
code scaleCuboid;
declare center : Vertex;
declare diagonal: float;
declare minDistance : Vertex float
code minDistanceCode;
…第二次作业第二次作业implementation
…
define surface is
return 2.0 * (self.length*self.width + self.length*self.height + self.width*self.height);
define scaleCuboid(s) is
begin
self.v1.scale(s);
…
self.v8.scale(s);
end define scaleCuboid; 第二次作业第二次作业 define center is
var c : Vertex;
begin
c.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 is
return self.v1.distance(self.v7); 第二次作业第二次作业 define minDistanceCode(v) is
var v0;
begin
//将长方体的6个面无限延伸,可将整个空间分为27个区域
if (v在长方体内部或表面上)
return 0;
else begin
根据v所在区域,可简单判断出长方体上距v最近的点v0所在 的面/棱/顶点,进而求出v0;
return v.distance(v0);
end else
end deine minDistanceCode;
…
end type Cuboid; 第二次作业第二次作业9.1
答:
(1)
方法
快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载
一采用1:1关系表示1:N关系,存在较多冗余;
不考虑索引,已知left查询对应的right集时,方法二效果明显好 于方法一;已知right查询对应的left时,方法一效果好于方法二。
当插入新关系
时,两种方法都无法保证一致性,即原关系 1:N的语义约束可能被违反,需要对insert操作做修改,保证每一 个Tright实例仅有至多一个对应的Tleft实例。
删除关系时,方法一中直接删除对应的TR实例,方法二中 只需修改right集合,直到right集合为空时,才需要删除对应的TR 实例。
更新操作由插入删除操作组合而成,不再讨论。
(2)方法一、二的insert操作均需修改,以保证一致性,方法二的 delete操作也需要修改。修改思想上边已说明,具体算法不再给 出。 第二次作业第二次作业9.7
答:在对象内部设计一个计数器
对于专用对象,生成实例,置为1,当实例被引用,置为0;
对于依赖对象,引用则加一,不再引用就减一,当计数器为0的时候,就删除对象.
第三次作业第三次作业10.5
解:
declare connect : Pipe || Pipe void;
refine connect : ConicalPipe || ConicalPipe void;
一个合法的重定义要求:
操作名不变,参数个数不变;
操作的接收者类型是原操作中接收者类型的子类;
操作的返回值类型是原操作返回值的子类;
操作的参数类型是原操作参数类型的超类。
题中的重定义仅满足(1)(2)(3),但违反(4)。ConicalPipe是Pipe
的子类而非超类,故不合法。
考虑下面的程序段:
var aPipe, anotherPipe : Pipe;
aConicalPipe : ConicalPipe;
anotherPipe := aConicalPipe; //可替换性,合法
anotherPipe.connect(aPipe); //编译通过,执行时由于动态绑定,出错第三次作业第三次作业10.6
解:
继承属性的类型是不能重定义的,必须保持原类型。
(1) 子类中继承属性的类型不能是该类型的子类,即特化不合法。
特化举例:
type Person is
body [name : string;
age : int;]
…
type Employee supertype Person is
body [boss : Employee;]
…
type Manager supertype Employee is
body [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 Employee is
body [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 <= <\ElemType>) : \ListType || \ElemType bool;
define member (t) is
var item : \ElemType;
begin
foreach (item in self)
if (item = t)
return true;
return false;
end define member; 第三次作业第三次作业 (2)
Polymorph declare nthmember (\ListType <= <\ElemType>) :
\ListType || int \ElemType;
define nthmember (n) is
var i : int;
item : \ElemType;
Begin
if (n > self.length || n < 1)
return null;
i := 0;
foreach (item in self)
begin
i++;
if (i = n)
return item;
endfor
end define nthmember; 第三次作业第三次作业 (3)
Polymorph declare substitute (\ListType <= <\ElemType>) :
\ListType || \ElemType, \ElemType void;
define substitute(old, new) is
var item : \ElemType;
begin
foreach (item in self)
begin
if (item = old)
begin
self.delete(old);
self.insert(new);
endif
endfor
end define substitute;第三次作业第三次作业 (4)
Polymorph declare sublist(\ListType <= <\ElemType>) :
\ListType || int, int \ListType;
define sublist(m, n) is
var newlist : \ListType;
item : \ElemType;
i : int;
begin
i := 0;
if (i >= 1 && i <= k && k <= self.length)
begin
newlist.create;
foreach (item in self)
begin
i++;
if (i >= m && i <= n)
newlist.insert(item);
endfor
endif
return newlist;
end define substitute; 第四次作业第四次作业13.5
Assume a Swiss Knife consists of a blade of a certain length 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 alternative 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;第四次作业第四次作业14.9
Retrieve all Managers of the R&D department(s), who supervise Emps located in the Building called “E1”.
select m
from m in Manager, e in EMP
where m = e.worksin.mgr
and m.worksin.name = ‘R&D’
and e.office.building = ‘E1’;第四次作业第四次作业14.10
List the name and salary of managers who manage more than 10 employees.
select m.name, m.salary
from m in Manager, e in EMP
where e.worksin.mgr = m
group by m.name
having count(e.name) > 10;第四次作业第四次作业类型定义
type CarVersion is
[versionNumber:int; !!CarVersion contains
preds:{CarVersion}; !!attributes for
succs:{CarVersion}; !!version management
car:Car;];
type Car is
[chassis:Chassis;
!!Car is the actual design object
engine:Engine;];
!!which may exist in several versionsnullType CarDesignObject is
Body [versionSet:{CarVersion};
Current:CarVersion;
VCount:int;]
operations
declare CarDesignObject:→CarDesignObject;
declare findVersion:int→CarVersion;
declare newVersion:→CarVersion;
declare mergeVersion:int,int→CarVersion;
declare deleteVersion:int→CarVersion;
implementation
define CarDesignObject is !!initializer
begin
self.vCount:=1
self.current.creat;
self.current.versionNumber:=self.vCount;
self.vCount:=self.vCount+1;
self.versionSet.create;
self.versionSet.insert(self.current);
return self;
end define CarDesignObject;nulldefine findVersion(vNumber)is !!retrieve the version
var cv:CarVersion; !!identified by vNumber
begin !!from the versionset
foreach(cv in self.versionSet)
if (cv.versionNumber=vNumber)return cv:
return NULL;
end define find version;
define.newVersion is !!create a new
var cvPred,cvNew:CarVersion; !!version
begin
cvPred:=self.Current;
if(cvPred=NULL) return NULL;
cvNew.create;
cvnew.versionNumber:=self.vCount;
self.vCount:=self.vCount+1;
self.versionSet.insert(cvNew);
cvPred.succs.insert(cvNew);
cvNew.preds.insert(cvPred);
self.current:=cvNew; !!most recent becomes current
return cvNew;
end define newVersion;nulldefine.mergeVersion(predVerNum1,predVerNum2) is
var cvPred1,cvPred2,cvNew:CarVersion;
begin
cvPred1:=self.findVerdsion(predVerNum1);
cvPred1:=self.findVerdsion(predVerNum2);
if(cvPred1=NULL||cvPred2=NULL) return NULL;
cvNew.create;
cvnew.versionNumber:=self.vCount;
self.vCount:=self.vCount+1;
self.versionSet.insert(cvNew);
cvPred1.succs.insert(cvNew);
cvPred2.succs.insert(cvNew);
cvNew.preds.insert(cvPred1);
cvNew.preds.insert(cvPred2);
self.current:=cvNew;
return cvNew;
end define mergeVersion;
nulldefine deleteVersion(vNumber)is
var cvDel,c:CarVersion;
begin
cvDel=self.findVersion(vNumber);
if(cvDel=Null) return Null;
foreach c in cnDel.preds
c.succs.remove(cvDel);
end for;
foreach c in cnDel.succs
c.preds.remove(cvDel);
end for;
self.vCount=self.vCount-1;
self.versionSet.remove(cvDel);
return cvDel;
end define deleteVersion;
end type CarDesignObject;
第五次作业第五次作业 schema C is
subsschema F;
subsschema G;
end schema C;
schema E is
subsschema H;
subsschema I;
end schema E;18.1 schema A is
subsschema B;
subsschema C;
end schema A;
schema B is
subsschema D;
subsschema E;
end schema B;
17.2 略.null18.4.如图18.3
Z:对应子模块Z1;
X/Y/Z:对应子模块Z2;
/X/Y/Z:对应子模块Z3;
…/…/Y/Z:对应子模块Z3;
18.2
schema B is
public S
interface
type S is …;
implementation
type T is…;
end schema B;
第六次作业第六次作业已知有如下两种段分配:
A> R1在Site1, R2在Site2, R3在Site3.
B> R1和R2在Site1, R2和R3在Site3.
另已知有如下应用(所有应用的频率相同)
A1: 在Site1上发出, 读5个 R1
记录
混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载
, 5个 R2记录
A2: 在Site3上发出, 读5个R3记录 , 5个R2记录
A3: 在Site2上发出, 读10个R2记录.
问: 1. 如果以本地应用为主要设计目标, 那个分配较优?
2. 假定A3改为要修改10个R2记录, 并仍以本地应用为其设计目标, 则那个分配
方案
气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载
较优? 第六次作业第六次作业解:首先完善模型如下:
假定:B方案中Site1上的R2和Site3上的R2是完全相同的,即冗余;本地读写的代价可忽略不计;所有异地读操作的单位记录代价均相等,记为1;所有异地写操作的单位记录代价均相等,记为1。
1 A方案 B方案 2 A方案 B方案
A1代价 5 0 5 0
A2代价 5 0 5 0
A3代价 0 10 0 10+10+10
故可知,第1个问题,A、B两种分配方案代价相等。
第2个问题,A分配方案较优。
第六次作业第六次作业习题: 假定全局关系和分段模式如下:
全局关系
Doctor (D#, Name, Dept)
Patient (P#, Name, Dept, Treat, D#)
Care (P#, Drug, QTY)
分段模式
Doctor1 = SLDEPT=‘Surgery’(Doctor)
Doctor2 = SLDEPT=‘Pediatrics’(Doctor)
Doctor3 = SLDEPT ‘Surgery’ and DEPT ‘Pediatrics’(Doctor)
Patient1 = SLDEPT=‘Surgery’ and treat=‘intensing’(Patient)
Patient2 = SLDEPT=‘Surgery’ and treat ‘intensing’(Patient)
Patient3 = SLDEPT ‘Surgery’ (Patient)
Care1 = Care SJ p#=p# Patient1
Care2 = Care SJ p#=p# Patient2
Care3 = Care SJ p#=p# Patient3
使用变换准则,将下面的全局查询变化为分段查询,并对它们加以简化。当需要时
用限定关系代数消除查询中不用的段。
(a) 列出在Care中使用‘Aspirin’的Patient 名字;
(b) 列出给病人开出接受精细护理的医生名字。第六次作业第六次作业(a)第六次作业第六次作业(a)第六次作业第六次作业(a)第六次作业第六次作业(b)第七次作业第七次作业对R的另一个简化程序:
R’=R SJ S, T’ = T SJ R’, S’ = S SJ T’
计算到R不再变化为止
R’=R SJ S T’= T SJ R’ S’ = S SJ T’ R’’=R’ SJ S’ T’’=T’ SJ R’
S’’=T’ SJ R’’ R’’’=R’’ SJ T’’ T’’’=T’’ SJ R’’’=
第七次作业 第七次作业 在如下R, S的概貌上计算R JNA=B S
Size(R)=50, Card(R)=100, Val(A[R])=50, Size(A)=3
Size(S)=5, Card(S)=50, Val(B[S])=50, Size(B)=3
R SJA=B S 的选择度 ρ = 0.2
S SJA=B R 的选择度 ρ = 0.8
问:
1. 使用 SJ简化程序在R站点执行JN
2. 使用 SJ简化程序在S站点执行JN
3. 使用直接连接在R站点执行JN
4. 使用直接连接在S站点执行JN
那种方案较优?第七次作业第七次作业解:
1. COST1 = 2C0 + C1( Size(A)·Val(A[R]) + Size(S)·Card(S)·ρS SJ R )
= 2C0 + C1( 3·50 + 5·50·0.8 ) = 2C0 + 350C1
2. COST2 = 2C0 + C1( Size(B)·Val(B[S]) + Size(R)·Card(R)·ρR SJ S )
= 2C0 + C1( 3·50 + 50·100·0.2 ) = 2C0 + 1150C1
3. COST3 = C0 + C1·Size(S)·Card(S)
= C0 + C1·5·50 = C0 + 250C1
4. COST4 = C0 + C1·Size(R)·Card(R)
= C0 + C1·50·100 = C0 + 5000C1
所以第三种方案最优。第八次作业第八次作业1.假设两个事务T 和 U 的 log 记录如下所示:
,,,,,,,,
如果系统故障时, 磁盘上记录的Log记录如下, 请描述数据库恢复管理器的动作.
a)
b)
c)
d) 第八次作业第八次作业1.
(a)undo T, undo U
(b)undo T, redo U
(c)undo T, redo U
(d)redo T, redo U附附本PPT可到:
ftp://addb:addb06@202.38.79.95 下载
Email: rea@mail.ustc.edu.cn
xzhang@mail.ustc.edu.cnnull
谢 谢!