计算机软件基础实验报告.docx

上传人:b****5 文档编号:30288767 上传时间:2023-08-13 格式:DOCX 页数:39 大小:1.27MB
下载 相关 举报
计算机软件基础实验报告.docx_第1页
第1页 / 共39页
计算机软件基础实验报告.docx_第2页
第2页 / 共39页
计算机软件基础实验报告.docx_第3页
第3页 / 共39页
计算机软件基础实验报告.docx_第4页
第4页 / 共39页
计算机软件基础实验报告.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

计算机软件基础实验报告.docx

《计算机软件基础实验报告.docx》由会员分享,可在线阅读,更多相关《计算机软件基础实验报告.docx(39页珍藏版)》请在冰豆网上搜索。

计算机软件基础实验报告.docx

计算机软件基础实验报告

《计算机软件基础》

实验报告

 

*******

学号:

**********

班级:

11电气1班

专业:

电气工程及其自动化

学院:

电气与信息工程学院

 

2013年12月

 

实验一线性表的插入和删除

一、实验目的

1.熟悉C++上机环境;

2.掌握线性表的基本操作:

查找、插入、删除等运算在链接存储结构上的运算。

二、实验内容

【任务一】阅读理解

阅读后面的程序,并将其输入到计算机中,调试成功,运算出结果。

这个程序中我们创建了一个整数类型的升序单,演示了单链表的创建、输出和删除操作。

【任务二】完善功能

构造函数node*insert(node*head,intnum),实现把一个节点插入链表,仍保持链表上各节点的升序关系,并在主函数中完成对你所添加函数的测试。

三、算法描述

建立含有若干个元素的升序单链表,对其进行插入、删除等操作,并将结果在屏幕上输出。

//实验一线性表

#include"stdafx.h"

constintSIZE0=2;

constintSTEP=1;

structList{

int*A,len,size;

List(){

A=(int*)malloc(SIZE0*sizeof(int));

if(!

A)exit

(1);

len=0;

size=SIZE0;

}

~List(){

delete[size]A;

}

intGetLen();

voidOutput();

intInsert(intloc,intx);

intDelete(intloc,int&y);

intGeti(intloc,int&y);

List(int*p,intn);

voidStraightInsertSort();

voidBinaryInsertSort();

voidBubbleSort();

intPatation(intlow,intup);

voidQuickSort(intlow,inthigh);

voidSelectSort();

voidShift_down(intheapsize,intindex);

voidDeleteNodeofHeap(intheapsize,intindex);

voidcreateHeap();

voidHeapSort();

voidShellInsert(intdk);

voidShellSort(int*delta,intt);

};

List:

:

List(int*p,intn)

{

A=newint[n];

for(inti=0;i

len=size=n;

};

//简单选择排序

voidList:

:

SelectSort()

{

inti,j,temp,max;

for(i=len-1;i>0;i--)

{

max=0;

for(j=1;j<=i;j++)

if(A[j]>A[max])max=j;

temp=A[i];A[i]=A[max];A[max]=temp;

cout<<"第"<

this->Output();cout<

}

}

//将当前A[0]~A[heapsize-1]构成的完全二叉树中下标为index的结点A[index]

//在其子树T中进行下移,使T成为大头堆O(log2(heapsize))

voidList:

:

Shift_down(intheapsize,intindex)//大头堆

{

intmax,temp,i=index,j=2*i+1;

while(j

{

max=j;

if(j+1A[j])max=j+1;//左右子树均存在

if(A[i]

{

temp=A[i];A[i]=A[max];A[max]=temp;

i=max;j=2*i+1;

}

elsebreak;

}

}

//删除当前A[0]~A[heapsize-1]构成的大头堆中下标为index的结点A[index],

//将其与A[heapsize-1]交换,并将A[0]~A[heapsize-2]调整为大头堆

voidList:

:

DeleteNodeofHeap(intheapsize,intindex)

{

inttemp=A[index];

A[index]=A[heapsize-1];

A[heapsize-1]=temp;

Shift_down(heapsize-1,index);

//cout<<"delete...\n";

//this->Output();cout<

};

voidList:

:

createHeap()//生成大头堆O(len)

{

inti,j,max,temp;

for(i=len/2-1;i>=0;i--)

{

max=j=2*i+1;

if(j+1

if(A[i]

{temp=A[i];A[i]=A[max];A[max]=temp;}

}

//cout<<"createHeap()...\n";

//this->Output();cout<

};

//堆排序O(len*log2(len))

voidList:

:

HeapSort()

{

inti;

createHeap();

for(i=len;i>1;i--)DeleteNodeofHeap(i,0);

};

voidList:

:

ShellInsert(intdk)//升序

{

inti,j,temp;

for(i=dk;i

{

temp=A[i];

for(j=i-dk;j>=0;j=j-dk)

{

if(A[j]>temp)A[j+dk]=A[j];

elsebreak;

};

A[j+dk]=temp;

};

//this->Output();

//cout<

};

voidList:

:

ShellSort(int*delta,intt)

{

intk;

for(k=0;k

};

intList:

:

Patation(intlow,intup)//划分,升序

{

intpivot,mid,temp;

//先选择枢轴

if(up-low>1)

{

mid=(low+up)/2;

if(A[mid]A[low]||A[mid]A[up])

{pivot=A[low];A[low]=A[mid];A[mid]=pivot;}

else

if(A[up]A[low]||A[up]A[mid])

{pivot=A[low];A[low]=A[up];A[up]=pivot;}

};

//==========

temp=A[low];

//cout<<"temp="<

while(up>low)

{

while(up>low)

{

if(A[up]>=temp)up--;

else{A[low]=A[up];break;}

};

while(up>low)

{

if(A[low]<=temp)low++;

else{A[up]=A[low];break;}

};

};

//cout<<"up="<

A[up]=temp;

//this->Output();

return(up);

}

voidList:

:

QuickSort(intlow,inthigh)

{

intpivot;

if(low

{

pivot=Patation(low,high);

QuickSort(low,pivot-1);

QuickSort(pivot+1,high);

};

};

voidList:

:

StraightInsertSort()//直接插入排序,升序

{

inti,j,temp;

for(i=1;i

for(j=i;j>0;j--)

if(A[j]

elsebreak;

};

voidList:

:

BinaryInsertSort()//折半插入排序,升序

{

inti,j,low,up,mid,temp;

for(i=1;i

{

low=0;up=i-1;temp=A[i];

while(up>=low)

{

mid=(low+up)/2;

if(temp

elselow=mid+1;

};

for(j=i-1;j>=up+1;j--)A[j+1]=A[j];

A[up+1]=temp;

};

};

voidList:

:

BubbleSort()//冒泡排序,升序

{

inti,j,temp,tag;

for(i=len-1;i>0;i--)//共len-1趟

{

tag=1;//逆序标志

for(j=0;j

if(A[j]>A[j+1])

{temp=A[j];A[j]=A[j+1];A[j+1]=temp;tag=0;}

if(tag)break;//本趟无逆序

}

};

intList:

:

GetLen(){

return(len);

}

voidList:

:

Output(){

for(inti=0;i

{cout<<"A["<

if((i+1)%5==0)cout<

};

cout<

}

intList:

:

Geti(intloc,int&y){

if(len==0)return(-1);

if(loc<0||loc>=len)return(0);

y=A[loc];

return

(1);

}

intList:

:

Insert(intloc,intx){

int*p,i;

if(loc<0||loc>len)return(0);

if(len==0){

A[0]=x;

len=len+1;

return

(1);

};

if(len==size){

p=(int*)malloc((size+STEP)*sizeof(int));

if(!

p)return(-1);

for(i=0;i

delete[len]A;

A=p;

size=size+STEP;

};

for(i=len;i>loc;i--)A[i]=A[i-1];

A[loc]=x;

len=len+1;

return

(1);

}

intList:

:

Delete(intloc,int&y){

inti;

if(len==0)return(-1);

if(loc<0||loc>=len)return(0);

y=A[loc];

for(i=loc+1;i

len=len-1;

return

(1);

}

voidmain(intargc,char*argv[]){

intloc,value,ok,sel;

charch='N';

ListL1;

intB[]={8,5,6,4,2,7,3,1};

intdelta[]={3,2,1};

ListL10(B,8);

do{

cout<<"线性表抽象数据类型及其实现\n";

cout<<"1--输出线性表\n";

cout<<"2--插入一元素\n";

cout<<"3--删除一结点\n";

cout<<"4--求表的长度\n";

cout<<"5--取某位序元素\n";

cout<<"6--排序\n";

cout<<"66--排序(新插入的元素)\n";

cout<<"7--退出\n";

cout<<"请选择相应的功能(1~7)\n";

cin>>sel;

switch(sel){

case1:

L1.Output();

break;

case2:

cout<<"插入一元素合法位序为:

0~"<

cout<<"请输入位序和元素的值:

\n";

cin>>loc>>value;

ok=L1.Insert(loc,value);

if(ok==1)cout<<"插入成功!

\n";

elseif(ok==0)cout<<"插入位序非法!

\n";

elsecout<<"表满!

\n";

break;

case3:

cout<<"删除一元素合法位序为:

0~"<

cout<<"请输入位序:

\n";

cin>>loc;

ok=L1.Delete(loc,value);

if(ok==1)cout<<"删除成功!

删除结点的值="<

elseif(ok==0)cout<<"删除位序非法!

\n";

elsecout<<"表空!

\n";

break;

case4:

cout<<"表的长度="<

break;

case5:

cout<<"取某一元素\n";

cout<<"请输入位序:

\n";

cin>>loc;

ok=L1.Geti(loc,value);

if(ok==1)cout<<"第"<

elseif(ok==0)cout<<"取值位序非法!

\n";

elsecout<<"表空!

\n";

break;

case6:

L10.StraightInsertSort();

L10.Output();

break;

case66:

L1.StraightInsertSort();

L1.Output();

break;

case7:

ch='Y';

};

}while(ch!

='Y');

}

四、实验数据及截图

图1在0位置插入10

图2插入位序非法

图3继续插入元素

图4输出线性表

图5删除一元素后输出

图6求表的长度

图7取某一元素

图8排序(原程序)

图9输出和排序新插入的元素(程序修改后)

图10退出

实验二栈抽象数据及实现

一、实验目的

1.掌握栈的数据类型描述、站的特点及栈的存储结构;

2.掌握栈的基本运算及应用。

二、实验内容

1、从顶到底输出栈;2、入栈一元素;3、出栈一结点;4、求栈的长度;5、取某位序元素;6、退出。

请完善主函数实现是那个数功能。

三、算法描述

//实验二线性栈.cpp:

Definestheentrypointfortheconsoleapplication.

#include"stdafx.h"

constintSIZE0=2;

constintSTEP=1;

structStack{

int*A,top,size;

Stack(){

A=(int*)malloc(SIZE0*sizeof(int));

if(!

A)exit

(1);

top=0;

size=SIZE0;

}

~Stack(){

delete[size]A;

}

intGetlen();

voidOutput();

intPush(intx);

intPop(int&y);

intGeti(intloc,int&y);

};

intStack:

:

Getlen(){

return(top);

}

voidStack:

:

Output(){

for(inti=top-1;i>=0;i--)

{cout<<"A["<

if((i+1)%5==0)cout<

};

if(top==0)cout<<"栈为空!

\n";

elsecout<

}

intStack:

:

Geti(intloc,int&y){

if(top==0)return(-1);

if(loc<0||loc>=top)return(0);

y=A[loc];

return

(1);

}

intStack:

:

Push(intx){

int*p,i;

if(top==size){

p=(int*)malloc((size+STEP)*sizeof(int));

if(!

p)return(-1);

for(i=0;i

delete[top]A;

A=p;

size=size+STEP;

};

A[top++]=x;

return

(1);

}

intStack:

:

Pop(int&y){

inti;

if(top==0)return(-1);

y=A[--top];

return

(1);

}

intmain(intargc,char*argv[]){

intloc,value,ok,sel;

charch='N';

StackL1;

do{

cout<<"栈抽象数据类型及其实现\n";

cout<<"1--从顶到底输出栈\n";

cout<<"2--入栈一元素\n";

cout<<"3--出栈一结点\n";

cout<<"4--求栈的长度\n";

cout<<"5--取某位序元素\n";

cout<<"6--退出\n";

cout<<"请选择相应的功能(1~6)\n";

cin>>sel;

switch(sel){

case1:

L1.Output();

break;

case2:

cout<<"入栈一元素"<

cout<<"请输入元素的值:

\n";

cin>>value;

ok=L1.Push(value);

if(ok==1)cout<<"入栈成功!

\n";

elsecout<<"栈满!

\n";

break;

case3:

cout<<"出栈一元素"<

ok=L1.Pop(value);

if(ok==1)cout<<"出栈成功!

出栈结点的值="<

elsecout<<"栈空!

\n";

break;

case4:

cout<<"栈的长度="<

break;

case5:

cout<<"取某一元素\n";

cout<<"请输入位序:

\n";

cin>>loc;

ok=L1.Geti(loc,value);

if(ok==1)cout<<"第"<

elseif(ok==0)cout<<"取值位序非法!

\n";

elsecout<<"栈空!

\n";

break;

case6:

ch='Y';

};

}while(ch!

='Y');

return0;

}

四、实验数据及截图

图1入栈一元素

图2从顶到底输出栈

图3出栈一结点

图4求栈的长度

图5取某位元素

图6退出

实验三数据库基本操作

一、实验目的

1.掌握数据库的基本思想。

2.掌握在VFP中建立数据库、数据表以及对其进行增、删、改操作的方法。

二、实验内容

【任务1】在VFP中建立学生信息数据库

【任务2】在该数据库中添加学生基本信息表、学生成绩表、学生家庭情况表,并建立关系。

【任务3】在上述标中添加记录、删除记录、修改记录。

【任务4】查询某学生信息:

成绩、家庭情况。

三、表的创建与使用

1.表的结构创建

创建“表一”,字段名为A,B,C,D,E,如图所示

2.记录的输入

(1)建立表示输入数据,1,2,3,4,5,6,如上图所示

(2)浏览数据表

(3)追加方式输入数据

3.记录的定位与修改

定位程序:

GOTO1;

修改程序:

REPLACEWITH

4.删除和恢复表中的数据

方法一:

在“浏览”窗口,把鼠标对准其删除标记栏,单击左键,这是要进行逻辑删除的记录就被加上了删除标记。

方法二:

在“浏览”窗口,打开“表”菜单,选择“删除记录”,在“删除”窗口,可以通过选择作用范围来确定要进行逻辑删除的部分记录。

4.查询与查询设计器

在数据库的应用中,查询时最常用的功能。

查询是指向一个数据库发出的检索信息的请求,它使用一些条件提取特定的记录。

(1)启动查询设计器

(2)查询设计器操作步骤

a)启动查询设计器(如上图)

b)选择出现在查询中的字段

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1