杭州电子科技大学短学期编程实训Word文档格式.docx
- 文档编号:18398000
- 上传时间:2022-12-16
- 格式:DOCX
- 页数:12
- 大小:246.42KB
杭州电子科技大学短学期编程实训Word文档格式.docx
《杭州电子科技大学短学期编程实训Word文档格式.docx》由会员分享,可在线阅读,更多相关《杭州电子科技大学短学期编程实训Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
编写控制台程序,将班级学生信息通过创建链表保存,可以添加、删除、查找某一学生的信息,显示所有学生的信息,信息保存到文件中,从文件中读出信息。
3.程序代码
#include<
stdio.h>
stdlib.h>
string.h>
structstudent
{
charname[10];
intscore;
structstudent*next;
};
structstudent*create()
structstudent*head,*pn,*pt;
inti,n;
printf("
创建多少个学生信息:
"
);
scanf("
%d"
&
n);
pn=(structstudent*)malloc(sizeof(structstudent));
请输入学生的姓名和成绩\n"
%s%d"
pn->
name,&
pn->
score);
head=pt=pn;
for(i=1;
i<
n;
i++)
{
pn=(structstudent*)malloc(sizeof(structstudent));
scanf("
pt->
next=pn;
pt=pn;
}
pt->
next=NULL;
returnhead;
\n"
********************************************************************************\n"
}
structstudent*insert(structstudent*head)
structstudent*pn;
pn->
next=head;
head=pn;
structstudent*clear(structstudent*head)
structstudent*p,*pold;
intgrade;
请输入您要删除学生的成绩:
grade);
p=head;
while(head!
=NULL&
&
head->
score==grade)
head=head->
next;
free(p);
p=head;
if(head==NULL)returnhead;
p=head->
pold=head;
while(p!
=NULL)
if(p->
{
pold->
next=p->
free(p);
p=pold->
}
else
pold=p;
p=p->
}
voidfound(structstudent*head)
{
structstudent*p;
请输入您要查找学生的成绩:
printf("
姓名成绩\n"
printf("
%s%d\n"
p->
name,p->
elsep=p->
voidprint(structstudent*head)
p=p->
structstudent*save(structstudent*head)
FILE*fp;
fp=fopen("
C:
\\Users\\Administrator\\Desktop\\学生信息.txt"
"
w"
fprintf(fp,"
%s%d\n"
fclose(fp);
structstudent*read()
inti=1;
r"
while(!
feof(fp))
if(i==1)
pn=(structstudent*)malloc(sizeof(structstudent));
head=pn;
pt=pn;
fscanf(fp,"
name,pn->
i--;
pt->
voidmain()
structstudent*head;
while
(1)
intchoice;
学生信息系统\n"
1.创建学生信息链表\n"
2.添加学生信息\n"
3.删除学生信息\n"
4.查找学生信息\n"
5.显示所有学生信息\n"
6.保存链表数据到文件\n"
7.从文件读取链表\n"
8.退出程序\n"
请输入您的选择:
choice);
switch(choice)
case1:
head=create();
break;
case2:
head=insert(head);
case3:
head=clear(head);
case4:
found(head);
case5:
print(head);
case6:
save(head);
case7:
head=read();
case8:
exit(0);
default:
printf("
请您从1—8之间选择\n"
return;
4.程序运行部分截图
5.心得体会
这个就自己写呗,每个人不一样的!
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 杭州 电子科技大学 学期 编程
![提示](https://static.bdocx.com/images/bang_tan.gif)