关键词不能为空

当前您在: 大学查询网 > 大学 >

广西大学2017重庆邮电大学-软件技术基础 实验报告(耿道渠)

作者:高考题库网
来源:https://bjmy2z.cn/daxue
2020-12-08 15:13
tags:

-

2020年12月8日发(作者:董太乾)


《软件技术基础》实验报告


实验名称

顺序表的操作



9

2

5

6


一、实验目的


1

、掌握顺序表结构的实现方式;


2

、掌握顺序表常用算法的实现;


3

、熟悉利用顺序表解决问题的一般思路;

< p>
4

、参照给定的顺序表的程序样例,验证给出的顺序表的常见算法,


领会顺序表结构的优点和不足。


二、实验内容


1

< p>、设计一个静态数组存储结构的顺序表,要求编程实现如下任务:


1

)建立一个顺序表,首先依次输人整数数据元素(个数根据需要


键盘给定)


2

删除指定位置的数据元素

(指定元素位置通过键盘输入)

再依


次显示删除后的顺序表中的数据元素。


3

查找指定数据的数据元素

( 指定数据由键盘输入)

若找到则显


示位置,若没有找到 则显示

0


2

、使用顺 序表实现一个电话本的管理程序,电话本中的每条记录包


括学号、姓名、手机号码和固定 电话四项。要求实现菜单、初始化、


添加、删除和显示等功能。


三、实验结果



- 1 -











四、实验中遇到的问题及解决方法:




- 2 - < /p>


第一次编写

C++

,感觉力不从心,回去多看看

< p>PPT



五、实验心得体会:



对顺序表的一些常用语句不熟悉,

对 顺序表的整体思路理解不深刻以


后要加强练习


附:源程序(自行编写或修改的程序。若为修改程序请注明修改部分的功能,若


为书上实 例则可不附。)


#include


#include


#include


#include


#define MAXSIZE 20


using namespace std;


int num;


typedef struct


{


string student_number;


string name;


string tel;


string home_phone;


int id;


}

TEL;


void shuaxin(TEL *);


void delet(TEL *);


- 3 -


void find(TEL *);


void show(TEL *);


int main(void)


{


int choose;


TEL List[MAXSIZE];


while(1)


{


cout <<

欢迎来到

XXX

电话本系统


*********************


cout <<

初始化并建立


cout <<

删除


cout <<

查找


cout <<

显示全部


cin >> choose;


system(


while( choose < 1 || choose > 4)


{


cout <<

输入错误,数字

1-4

,请重新输入

!


cin >> choose;


system(


}


- 4 -












}











}


switch(choose)


{






}


//system(


case 1: shuaxin(List); break;


case 2: delet(List); break;


case 3: find(List); break;


case 4: show(List); break;


return 0;


void shuaxin(TEL * list)


{










int i,j;


for(i = 0; i < MAXSIZE; i++)


{







list[i].id = i + 1;


list[i].home_phone =


list[i].name =


list[i].student_number =


list[i].tel =


- 5 -






}


system(


cout <<

初始化成功,现在开始建表

:


cout <<

请输入需要建立的电话个数

:(

小于


<



















cin >> num;


while( num < 1 || num > MAXSIZE )


{





}


system(


cout <<

请依次输入学生的学号,姓名,移动电话,家庭电话


fo r(j = 1; j <= num; j++)


{








cout << j << '.';


cin >> list[j - 1].student_number;


cin >> list[j - 1].name;


cin >> list[j - 1].tel;


cin >> list[j - 1].home_phone;


cout << endl;


system(


cout <<

输入错误,请重新输入


cin >> num;


- 6 -








}



}


if(num == (j - 1) )


{




}


system(


cout <<

建立表完毕

!


void delet(TEL * list)


{














int j,i = 0;


cout <<

请输入你需要删除的序号


cin >> j;


while( j < 0 || j > num)


{




}


while(list[i].id != j)


i++;


cout <<

输入错误

,

请重新输入


cin >> j;


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


{


- 7 -

















}






}


list[j].name = list[j + 1].name;


list[j].tel = list[j + 1].tel;


list[j].student_number = list[j + 1].student_number;


list[j].home_phone = list[j + 1].home_phone;


list[j].home_phone =


list[j].name =


list[j].student_number =


list[j].tel =


num--;


system(


cout <<

删除完毕




void find(TEL * list)


{






string telnum;


int i,key = 0;


cout <<

请输入你需要查找的电话号码


cin >> telnum;


- 8 -


system(


for(i = 0; i < MAXSIZE; i++)


{


if(telnum == list[i].tel || telnum == list[i].home_phone)


{


if(key == 0)


cout <<

依次

学号

姓名

移动电话


庭电话



cout << list[i].id << '.';


cout << setw(12) << list[i].student_number;


cout << setw(10) << list[i].name;


cout << setw(14) << list[i].tel;


cout << setw(10) << list[i].home_phone;


cout << endl;


key = 1;


}


}


if( key == 0)


cout <<

未找到此电话号码



}


- 9 -



void show(TEL * list)


{





int i;


cout <<

现在有

个电话号码


cout <<

依次

学号

姓名

移动电话

家庭电话



for(i = 0; i < num; i++)


{


cout << list[i].id << '.';


cout << setw(12) << list[i].student_number;


cout << setw(10) << list[i].name;


cout << setw(14) << list[i].tel;


cout << setw(10) << list[i].home_phone;


cout << endl;


}


cout <<

输出完毕


}







- 10 -


《软件技术基础》实验报告


实验名称

链表的操作(一)



10

2

5

6


一、实验目的


1

、掌握单链表结构的实现方式;


2

、掌握单链表常用算法的实现。


二、实验内容


1

、设计一个链表,要求编程实现如下任务:


1

)建立一个链表,首先依次输人整数数据元素(个数根据需要 键


盘给定)


2

删除指定值的结点

(指定值通过键盘输入)

再依次显示删除后


的链表中的数据元素。

< p>

3

查找指定值的结点

(指定数据 由键盘输入)

若找到则显示查找


成功,若没有找到则显 示查找失败。


4)

在第

< p>i

个节点(

i

由键盘输入,

i=0

< p>表示插入的结点作为第

1


结点)之后插入一个元素 为

x

的节点。


三、实验结果



四、实验中遇到的问题及解决方法:


- 11 -



编 写过程中经常把

C

语言和

C++

的语句形式搞混乱 ,

课后认真了


解了

C++

后得以解决。< /p>



五、实验心得体会:



对单链表的实现方式和常用算法掌 握不足,

C++

部分基本概念


不熟悉, 需课后补强


附:源程序(自行编写或修改的程序。若 为修改程序请注明修改部分的功能,若


为书上实例则可不附。)


#include


#include


#include



struct LNode


{


int data;



};



LNode *find(LNode *head,int x)


{





LNode *p=head->next;


while(p!=NULL && p->data!=x)


p=p->next;


struct LNode *next;


- 12 -



}



return p;


void Insert(LNode *head,int i,int x)


{


if(i<1)


















cout<<

不存在第

个位置


else


{




LNode *p=head;


int k=0;


while(p!=NULL && k


{




}


if(p==NULL)


cout<

超出链表最大可插入位置


p=p->next;


k++;


else


{


LNode *s=new LNode;


s->data=x;


- 13 -






}





}


}


s->next=p->next;


p->next=s;


void Delete(LNode *head,int i)


{
















if(i<1)


cout<<

不存在第

个元素


else


{





LNode *p=head;


LNode *q;


int k=0;


while(p!=NULL && k


{


q=p;




}


if(p==NULL)


p=p->next;


k++;


- 14 -









}



cout<< i<<

超出链表长度


else


{


q->next=p->next;



}


}


delete p;


void main()


{


LNode *head,*p;












head=new LNode;


head->next=NULL;


int i,x,y;


cout<<

请输入

5

个数,每个书中间 空一格:


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


{




}


i=0;


cin>>x;


Insert(head,i,x);


- 15 -
























cou t<<

请输入需要删除的节点

(1~5)


cin>>i;


Delete(head,i);


cout<<

删除的节点

后输出为

:


p=head->next;


while(p!=NULL)


{




}


cout<


cout<<

请输入 需要查找的指定值的结点:


cin>>x;


if(find(head,x)!=NULL)


cout<<

查找成功


else


cout<<

查找失败



cout<data<<


p=p->next;


cout<


i=0;


x=0;


cout<<

请输入在

i

节点及元素

x


cin>>i>>x;


- 16 -


Insert(head,i,x);


cout<<

显示:


p=head->next;


while(p!=NULL)


{


cout<data<<


p=p->next;


}


cout<



}













- 17 -


《软件技术基础》实验报告


实验名称

链表的操作(二)



11

2

5

6


一、实验目的


1

、熟悉利用线性链表解决问题的一般思路;


2

、参照给定的链表的程序样例,验证给出的链表的常见算法,

< br>了解单链表结构的优点和不足。


二、实验内容


1

< p>、使用链表实现一个电话本的管理程序,电话本中的每条记录


包括姓名和电话两项。 要求实现菜单管理、记录的添加、删除和


显示等功能。


三、实验结果



- 18 -





四、实验中遇到的问题及解决方法:


对查找名字、查找号码等功能掌握不清,问老师和同学后基

< p>
本清楚


五、实验心得体会:


< /p>


体会到了

C++

的神奇与精彩,但是自己还不能实现这种神


奇,达到这种精彩,但是增强了自身兴趣


附: 源程序(自行编写或修改的程序。若为修改程序请注明修改部分的功能,若


为书上实例则 可不附。)


#include


#include


#include


#include


#define LEN sizeof(TEL)


- 19 -


#define SIZE sizeof(Size)



int n = 0;



typedef struct tel


{





char name[10];


long num;


struct tel * next;


}TEL;



typedef struct tel_size


{




char name[10];


long num;


}Size;



TEL * search(void);//

从文件读取


TEL * insert(TEL *head);//

插入


TEL * del(TEL * head);//

删除


void showall(TEL * head);//

输出到屏幕


void find_name(TEL * head);//

通过名字查找


- 20 -


void find_number(TEL * head);//

通过号码查找


TEL * revise(TEL * head);


void sav(TEL * head);//

储存



int main(void)


{


















printf(


head = search();



printf(

//

选择显示界面


printf(


printf(


printf(


printf(


printf(


pri ntf(


printf(



do

//

选择项


TEL * head = NULL;


int choose;


- 21 -






















}



{

















pri ntf(


scanf(


switch(choose)


{












}


case 1:head = insert(head);break;


case 2:head = del(head);break;


case 3:showall(head);break;


case 4:find_name(head);break;


case 5:find_number(head);break;


case 6:head = revise(head);break;


case 7:sav(head);break;


case 8:return 0;


default:printf(


p rintf(


}while(1);




return 0;


- 22 -


TEL * search(void)//

寻找文件是否存在函数


{






















if( ( fp = fopen(

打开或者新建文件


{




}


fs eek(fp,0L,0);//

文件指针倒回到开头



while(!feof(fp))


{







if( fread(p1,SIZE,1,fp) != 1 )//

需要防止读出错误情况


break;


printf(


exit(0);


FILE * fp;


TEL * head = NULL;


TEL * p2,* p1;


p1 = p2 = (TEL *)malloc(LEN);


if(head == NULL)


head = p1;


else p2->next = p1;


- 23 -












}






}


p2 = p1;


n++;


p1 = (TEL *)malloc(LEN);


free(p1);


p2->next = NULL;


fclose(fp);



return head;


TEL * insert(TEL * head)//

插入新号码函数


{










TEL * p0, * p1, * p2;


p0 = (TEL *)malloc(LEN);


printf(


scanf(


p1 = head;


p2 = p1;


if(head == NULL)


{


- 24 -









head = p0;


p0->next = NULL;


}else


{


while( strcmp(p0->name,p1->name) > 0 && p1->next !=


NULL)//

比较字符串,找到应该插入位置



























}


n++;


if( strcmp(p0->name,p1->name) <= 0 )//

比较字符串,插入新号码


{




p2->next = p0;


p0->next = p1;






{




}


p2 = p1;


p1 = p1->next;


}else


{




}


p1->next = p0;


p0->next = NULL;


- 25 -



}



return head;


TEL * del(TEL * head)//

删除函数


{






TEL * p1, * p2;


p1 = head;


long dele;


printf(

输入删除


的电话号 码














if(head == NULL)


printf(

空表情况


else


{







}


while(dele != p1->num && p1 != NULL)//

找到位置


{




}


p2 = p1;


p1 = p1->next;


scanf(


- 26 -















}



void showall(TEL * head)//

打印函数


{







int i = 0;


TEL * p;


p = head;


if(head == NULL)


printf(

空表情况


return head;


if(dele == p1->num)


{










if(dele == head->num)//

删除在头部情况


head = head->next;


else p2->next = p1->next;

//

输出删除的数据并用链表架空


< /p>


printf(


printf(


n--;


}else printf(

没找到情况


- 27 -













}



else


{










}


printf(

%d number:n


printf(

name

number

n


do


{





i++;


printf(

%10s %15ldn


p = p->next;


}while(p != NULL);


void find_name(TEL * head)//

以名字方式寻找号码


{









TEL * p;


int dis = 0;


char f_name[20];


p = head;


printf(

输入名字


scanf(


if(head == NULL)


- 28 -



















}



printf(

空表情况


else


{












}


do


{









if(strcmp(p->name,f_name) == 0)//

只要找到同名

均输出


{





}


p = p->next;


dis = 1;


printf(


p rintf(


}while(p != NULL);


if(dis == 0)


printf(


void find_number(TEL * head)//

以号码方式寻找号码


{


TEL * p;


- 29 -
























long f_num;


int dis = 0;//dis

作为判定是否找到变量


p = head;


printf(

输入号码


scanf(


if(head == NULL)


printf(

空表情况


else


{











}


do


{








if(f_num == p->num)


{




}


else p = p->next;


dis = 1;


break;


}while(p != NULL);


if(dis == 1)


{


- 30 -






}





}


printf(


printf(< /p>


else printf(


TEL * revise(TEL * head)//

修改函数


{





TEL * p = head;


int choose,num,i;


printf(


numbern












//find_name(TEL * head);


scanf(


for(i = 2; i <= num; i++)


p = p->next;


pr intf(


printf(


scanf(


switch(choose)


{


case 1:{


- 31 -













}













printf(


scanf(


break;


}


case 2:{






}


return head;








printf(


scanf(


break;


}


void sav(TEL * head)//

储存函数


{









FILE * fp;


TEL * p;


if( ( fp = fopen(

打开或者新建文件


{




}


printf(


exit(0);


- 32 -














}











p = head;


while(p != NULL)


{









}


fclose(fp);


if( fwrite(p,SIZE,1,fp) == 1 )


p = p->next;


else


{




}


printf(


exit(0);


- 33 -


《软件技术基础》实验报告


实验名称

栈的操作



1 2

2

5

6


一、实验目的


掌握栈的的定义和运算,了解栈的应用。


二、实验内容


1

、堆栈的测试和应用。要求:


设计一个主函数 实现对顺序堆栈代码进行测试。测试方法


为:

依次把数据元素

< p>1,3,5

7,9

入栈,

然后出栈堆栈中的 数据元


素并在屏幕上显示。


三、实验结果





- 34 -





四、实验中遇到的问题及解决方法:


问题不是太多,但是编写过程还是比较艰辛。


五、实验心得体会:



栈在本书中比较 重要,

要多多理解书本知识,

多问老师,

多实践。


附:源程序(自行编写或修改的程序。若为修改程序请注明修改部分的功能,若


为书上实例则可不附。)


#include


#include


#define MAX_SIZE 30


- 35 -


using namespace std;



struct SqStack


{





};



int InitStack(SqStack *,int);


void push(SqStack *,int);


void del(SqStack *);



int main(void)


{









int choose,size;


int in,i;


SqStack p;


cout <<


cout <<

请输入长度:


cin >> size;


while(InitStack(&p,size))


int *data;


int top;


int stacksize;


- 36 -











{




}


system(


cout <<

请输入长度:


cin >> size;


while(1)


{


cout <<

















cout <<

入栈


cout <<

出栈


cout <<

栈内情况


cout <<

清空栈


cout <<

退出


cout <<

请输入选项


cout <<











cin >> choose;


while(choose < 0 || choose > 4)


{


cout <<

请输入一个

0-4

的常数


- 37 -















































}


cin >> choose;


system(


switch(choose)


{


















}


case 1: cout <<

输入一个整数






cin >> in;


push(&p,in);break;


case 2: del(&p);


break;


case 3: cout <<

栈底








for(i = 0; i <= i++)


cout << [i] << endl;


break;


case 4: while( > -1)












{




}


break;



cout << [] << endl;


--;


case 0: return 0; break;


- 38 -

-


-


-


-


-


-


-


-



本文更新与2020-12-08 15:13,由作者提供,不代表本网站立场,转载请注明出处:https://bjmy2z.cn/daxue/21095.html

重庆邮电大学-软件技术基础 实验报告(耿道渠)的相关文章