您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页20071395-王蒙-实验3

20071395-王蒙-实验3

来源:意榕旅游网


黑龙江大学 实 验 报 告

课程名称 数据库系统原理与实现 创建数据库及数据操作功能 实验项目名称 实验时间 第10~13 节 (日期及节次) 专业 年级 姓名 计算机科学与技术 2007级 王蒙 学生所在学院 学号 指导教师 计算机科学技术学院 20071395 钟颖莉 实验室名称 实验成绩 教师签字

软件第一实验室 预习情况 操作技术 实验报告 附加:综合实验 创新能力 综合成绩

黑龙江大学教务处

实验名称:创建数据库及数据操作功能

实验目的

(1)熟悉关系数据库建库语句和数据操作语句的功能。 (2)熟悉关系数据库中关系模式维护语句的功能。 (3)掌握用高级程序设计语言创建数据库的方法。 (4)掌握数据操作功能的实现方法。 (5)掌握修改关系模式的方法。

实验类型

设计型

实验环境

编程环境:Visual C++ 6.0 运行环境:Windows XP等

主要设计思想与算法

表的数据结构为结构体类型 每个表是一个节点

表和表之间用指针连接而每个表中包含属性链表,指针,存储表名的字符串等 输出属性和表时只需要把相应节点产出即可 void alter_add_property() {

head *nowhead=NULL; property *now=NULL,*ab=NULL; nowhead=Head->next_head; if(nowhead==NULL) cout<name,g_words[1])==0) break; else { nowhead=nowhead->next_head; if(nowhead==NULL) break; } } if(nowhead==NULL)

cout<<\"对不起,没有此表!\"<name,g_words[2]); ab->next=NULL; now=nowhead->next_property; if(now==NULL) now->next=ab; else { while(now->next!=NULL) { now=now->next; } now->next=ab; } } } }

void update_element()//修改数据库记录的功能 { head *nowhead=NULL; property *now=NULL; nowhead=Head->next_head; int i_g=2; if(nowhead==NULL) cout<<\"现在没有任何表存在\"<name,g_words[1])==0) break; else { nowhead=nowhead->next_head; if(nowhead==NULL) break; } } if(nowhead==NULL) cout<<\"对不起,没有此表可以插入数据!\"< else { int state_value;//用于标记所要修改的属性值是否存在 int state_property; int i_element=-1;//用于确定所要修改的行的数组序号 i_g=i_update; int element;//用于修改set后需要修改的属性在g_words里的下标 while(g_words[i_g][0]!='\\0') { state_property=0; state_value=0; now=nowhead->next_property; while(now!=NULL) { if(strcmp(now->name,g_words[i_g])==0) { state_property=1; for(int i=0;i<=nowhead->num;i++) { if(strcmp(now->ele[i].a,g_words[i_g+1])==0) { state_value=1; i_element=i; break;//跳出for循环 } } } else now=now->next; if(state_property==1) break; } if(state_property==0) cout<<\"您所输入的属性名称不存在\"<next_property; while(now!=NULL)

{ if(strcmp(now->name,g_words[element])==0) { strcpy(now->ele[i_element].a,g_words[element+1]); now->ele[i_element].state=1; break; } else now=now->next; } element=element+2; } ////////////////////////////// i_g=i_g+2; } } } }

void alter_add_property() {

head *nowhead=NULL; property *now=NULL,*ab=NULL; nowhead=Head->next_head; if(nowhead==NULL) cout<name,g_words[1])==0) break; else { nowhead=nowhead->next_head; if(nowhead==NULL) break; } } if(nowhead==NULL) cout<<\"对不起,没有此表!\"<else { ab=(property*)malloc(sizeof(property)); strcpy(ab->name,g_words[2]); ab->next=NULL; now=nowhead->next_property; if(now==NULL) now->next=ab; else { while(now->next!=NULL) { now=now->next; } now->next=ab; } } } }

void create_index(char chars1[],char chars2[],index indexs[],int &k) //创建属性并对属性值排序 { where_behind now; strcpy(now.table,chars1); strcpy(now.shuxing,chars2); property *now_property=NULL; head *head_now=NULL; find_property(now,now_property,head_now);//查找对应表和相应的属性 // head_now->index_state=0; int j=-1; for(int i=0;inum;i++) { if(j==-1) {j++;strcpy(indexs[j].propertys,now_property->ele[i].a);indexs[j].number=i;} else { if(analyse_stack[8]=='p'||analyse_stack[7]=='p') { int m=0; while((strcmp(now_property->ele[i].a,indexs[m].propertys)>=0)&&(m<=j)) { m++; } if(m>j)//当前要插入的属性要比所有索引里的属性值都要大,则插到最后

一位 { j++; strcpy(indexs[j].propertys,now_property->ele[i].a);indexs[j].number=i; } else { for(int n=j+1;n>m;n--) { strcpy(indexs[n].propertys,indexs[n-1].propertys);indexs[n].number=indexs[n-1].number; } strcpy(indexs[m].propertys,now_property->ele[i].a);indexs[m].number=i; j++; } } else//降序 { int m=0; while((strcmp(now_property->ele[i].a,indexs[m].propertys)<=0)&&(m<=j)) { m++; } if(m>j)//当前要插入的属性要比所有索引里的属性值都要小,则插到最后一位 { strcpy(indexs[m].propertys,now_property->ele[i].a);indexs[m].number=i; j++; } else { for(int n=j+1;n>m;n--) { strcpy(indexs[n].propertys,indexs[n-1].propertys);indexs[n].number=indexs[n-1].number; } strcpy(indexs[m].propertys,now_property->ele[i].a);indexs[m].number=i; j++; } } } }

// }

cout<<\"索引中排列如下:\"<cout<<\"&&&&\"<实验结果(测试用例、实验结果)

删除数据:

添加数据,更改数据:

添加属性:

删除表:

全选关系的操作:

实验总结与心得

通过这次实验,对数据库系统的各项功能加以实现,从系统的实现层次加以实现,在实验2的基础上对各项功能赋予其灵魂,从中不仅提高了自己的编程能力而且对数据库的基本操作有了进一步的理解

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务