杭州电子科技大学短学期编程实训.docx

上传人:b****3 文档编号:5410490 上传时间:2022-12-16 格式:DOCX 页数:12 大小:246.42KB
下载 相关 举报
杭州电子科技大学短学期编程实训.docx_第1页
第1页 / 共12页
杭州电子科技大学短学期编程实训.docx_第2页
第2页 / 共12页
杭州电子科技大学短学期编程实训.docx_第3页
第3页 / 共12页
杭州电子科技大学短学期编程实训.docx_第4页
第4页 / 共12页
杭州电子科技大学短学期编程实训.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

杭州电子科技大学短学期编程实训.docx

《杭州电子科技大学短学期编程实训.docx》由会员分享,可在线阅读,更多相关《杭州电子科技大学短学期编程实训.docx(12页珍藏版)》请在冰豆网上搜索。

杭州电子科技大学短学期编程实训.docx

杭州电子科技大学短学期编程实训

杭州电子科技大学短学期编程实训

 

 

————————————————————————————————作者:

————————————————————————————————日期:

 

 

《编程实习》报告

 

指导老师:

朱胜利王春林

专业:

班级:

姓名:

学号:

1.实训目的

通过本次编程实训,让我们更好的掌握对C语言知识的运用,加深对C语言的理解。

2.实训任务

通过使用VisualC++这个软件,编写一个能存储学生信息(姓名,成绩)的简单程序

例如:

编写控制台程序,将班级学生信息通过创建链表保存,可以添加、删除、查找某一学生的信息,显示所有学生的信息,信息保存到文件中,从文件中读出信息。

3.程序代码

#include

#include

#include

structstudent

{

charname[10];

intscore;

structstudent*next;

};

structstudent*create()

{

structstudent*head,*pn,*pt;

inti,n;

printf("创建多少个学生信息:

");

scanf("%d",&n);

pn=(structstudent*)malloc(sizeof(structstudent));

printf("请输入学生的姓名和成绩\n");

scanf("%s%d",pn->name,&pn->score);

head=pt=pn;

for(i=1;i

{

pn=(structstudent*)malloc(sizeof(structstudent));

scanf("%s%d",pn->name,&pn->score);

pt->next=pn;

pt=pn;

}

pt->next=NULL;

returnhead;

printf("\n");

printf("\n");

printf("********************************************************************************\n");

}

structstudent*insert(structstudent*head)

{

structstudent*pn;

pn=(structstudent*)malloc(sizeof(structstudent));

printf("请输入学生的姓名和成绩\n");

scanf("%s%d",pn->name,&pn->score);

pn->next=head;

head=pn;

returnhead;

printf("\n");

printf("\n");

printf("********************************************************************************\n");

}

structstudent*clear(structstudent*head)

{

structstudent*p,*pold;

intgrade;

printf("请输入您要删除学生的成绩:

");

scanf("%d",&grade);

p=head;

while(head!

=NULL&&head->score==grade)

{

head=head->next;

free(p);

p=head;

}

if(head==NULL)returnhead;

p=head->next;

pold=head;

while(p!

=NULL)

{

if(p->score==grade)

{

pold->next=p->next;

free(p);

p=pold->next;

}

else

{

pold=p;

p=p->next;

}

}

returnhead;

printf("\n");

printf("\n");

printf("********************************************************************************\n");

}

voidfound(structstudent*head)

{

structstudent*p;

intgrade;

printf("请输入您要查找学生的成绩:

");

scanf("%d",&grade);

p=head;

while(p!

=NULL)

{

if(p->score==grade)

{

printf("姓名成绩\n");

printf("%s%d\n",p->name,p->score);

p=p->next;

}

elsep=p->next;

}

printf("\n");

printf("\n");

printf("********************************************************************************\n");

}

voidprint(structstudent*head)

{

structstudent*p;

p=head;

printf("姓名成绩\n");

while(p!

=NULL)

{

printf("%s%d\n",p->name,p->score);

p=p->next;

}

}

structstudent*save(structstudent*head)

{

structstudent*p;

FILE*fp;

p=head;

fp=fopen("C:

\\Users\\Administrator\\Desktop\\学生信息.txt","w");

while(p!

=NULL)

{

fprintf(fp,"%s%d\n",p->name,p->score);

p=p->next;

}

fclose(fp);

returnhead;

}

structstudent*read()

{

structstudent*head,*pn,*pt;

inti=1;

FILE*fp;

fp=fopen("C:

\\Users\\Administrator\\Desktop\\学生信息.txt","r");

printf("姓名成绩\n");

while(!

feof(fp))

{

if(i==1)

{

pn=(structstudent*)malloc(sizeof(structstudent));

head=pn;

pt=pn;

fscanf(fp,"%s%d\n",pn->name,&pn->score);

printf("%s%d\n",pn->name,pn->score);

i--;

}

else

{

pn=(structstudent*)malloc(sizeof(structstudent));

fscanf(fp,"%s%d\n",pn->name,&pn->score);

printf("%s%d\n",pn->name,pn->score);

pt->next=pn;

pt=pn;

}

}

pt->next=NULL;

fclose(fp);

returnhead;

}

voidmain()

{

structstudent*head;

while

(1)

{

intchoice;

printf("学生信息系统\n");

printf("1.创建学生信息链表\n");

printf("2.添加学生信息\n");

printf("3.删除学生信息\n");

printf("4.查找学生信息\n");

printf("5.显示所有学生信息\n");

printf("6.保存链表数据到文件\n");

printf("7.从文件读取链表\n");

printf("8.退出程序\n");

printf("\n");

printf("\n");

printf("********************************************************************************\n");

printf("请输入您的选择:

");

scanf("%d",&choice);

switch(choice)

{

case1:

head=create();break;

case2:

head=insert(head);break;

case3:

head=clear(head);break;

case4:

found(head);break;

case5:

print(head);break;

case6:

save(head);break;

case7:

head=read();break;

case8:

exit(0);

default:

printf("请您从1—8之间选择\n");

return;

}

}

}

4.程序运行部分截图

5.心得体会

这个就自己写呗,每个人不一样的!

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

当前位置:首页 > 医药卫生 > 基础医学

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

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