C语言课程设计实验报告Word格式.docx
《C语言课程设计实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《C语言课程设计实验报告Word格式.docx(25页珍藏版)》请在冰点文库上搜索。
3.printlist"
显示链表中所有记录
4.Searchrecordonname"
按照姓名查找记录
5.Savethefile"
将链表中记录保存到文件中
6.Loadthefile"
从文件中读入记录
7.computethescore"
计算所有学生的总分和均分
8.insertrecordtolist"
插入记录到表中
9.Quit"
退出
3.完成查找、显示记录;
(周三)
4.完成保存数据到文件和从文件读数据的过程;
(周四)
5.完成学生的总分和均分的计算;
(周五)
五、要求
1.只能使用C语言,源程序要有适当的注释,使程序容易阅读。
2.要有用户界面。
要求至少采用文本菜单界面;
鼓励采用图形菜单界面。
3.必须使用结构和链表等数据结构。
4.使用文件保存数据。
5.写实验报告(要求正规打印,A4幅面),内容包括:
题目
系统功能模块结构图
数据结构设计及用法说明
程序结构(画流程图)
各模块的功能
实验结果(包括输入数据和输出结果)
体会
附录:
程序清单及源程序软盘
6.凡发现抄袭,抄袭者与被抄袭者皆以零分计入本课程设计成绩并向学院报告。
凡发现实验报告或源程序雷同,涉及的全部人员皆以零分计入本课程设计成绩并向学院报告。
系统功能模块
12345
678910
数据结构设计与用法说明
一.菜单。
本程序分为10个功能,在菜单上都有显示。
输入你想进行操作的数字号进入不同功能。
二.输入功能。
当输入1时为输入数据功能,按照要求即可输入数据,最后会问你是否要继续,当输入“y”时会重复上述操作,当输入“n”时返回菜单。
三.删除功能。
当输入2时,为删除功能,按照要求输入学号,会把该生打印出来,但你再输入“y”时会删除该生档案,当输入“n”会取消该删除操作。
四.输出功能。
当输入3时为输出功能,会把所有档案都打印出来。
五.通过名字搜索。
当输入4时为通过名字搜索功能,按照要求输入名字即可查到该生成绩。
六.通过学号搜索。
当输入5时为通过学号搜索功能,按照要求输入学号即可查到该生成绩。
七.存储功能。
当输入6时为存储功能,输入要存储的地方即可完成存储。
八.读取功能。
当输入7是为读取功能,即可再次使用存储的档案。
九.运算功能。
当输入8为运算功能,即可完成一系列要求的数据并打印。
十.插入功能。
当输入9时为插入功能,按照要求即可完成插入档案。
十一。
离开。
当输入十时为离开功能,即可返回。
程序源代码
#include<
stdio.h>
stdlib.h>
string.h>
#defineLENsizeof(STUDENT)
#definepaixu10
typedefstructs1
{
charno[9];
charname[15];
charsex;
intage;
intscore[4];
floatsum;
floataverage;
intorder;
structs1*next;
}STUDENT;
staticinta=0;
STUDENT*head;
STUDENT*inport()
inti,s;
chary='
y'
;
STUDENT*head=NULL,*p;
while(y=='
)
{
p=(STUDENT*)malloc(LEN);
if(!
p)
{
printf("
Outofmemory."
);
return(head);
}
printf("
inportthenum:
\n"
scanf("
%s"
p->
no);
inportthename:
name);
printf("
inportthesex:
m\\f?
%c"
&
p->
sex);
while(p->
sex!
='
f'
&
m'
)
{printf("
pleaseinportagain\n"
scanf("
}
inporttheage:
%d"
age);
if(p->
age<
0||p->
age>
100){
printf("
error,pleaseinportagain.\n"
scanf("
}while(p->
0||p->
100);
Pleaseinportthe%dscores\n"
4);
s=0;
for(i=0;
i<
4;
i++)
{
do
{
printf("
score%d:
"
i+1);
scanf("
score[i]);
if(p->
score[i]<
score[i]>
100)
Dataerror,pleaseenteragain.\n"
s=s+p->
score[i];
p->
sum=(float)s;
average=(float)s/4;
order=0;
next=head;
head=p;
doyouwanttocontinue,y\\n?
:
y);
}
return(head);
}
voidprint(STUDENT*head)
inti=0;
STUDENT*p;
p=head;
\nthosearewhatyouwant.\n"
NO:
Num:
Name:
sex:
age:
Sc1:
Sc2:
Sc3:
Sc4:
Sum:
Ave:
Order:
while(p!
=NULL)
{
i++;
%3d%4s%-4s%3c%3d%3d%3d%3d%3d%4.2f%4.2f%-5d\n"
i,p->
no,p->
name,p->
sex,p->
age,p->
score[0],p->
score[1],p->
score[2],p->
score[3],p->
sum,p->
average,p->
order);
p=p->
next;
}
thatisall.\n"
a=i;
voidsearchname(STUDENT*head)
chars[5];
system("
cls"
Pleaseinportthename.\n"
scanf("
s);
Num:
Order:
=NULL)
if(strcmp(p->
name,s)&
p!
p=p->
else{
%4s%-4s%3c%3d%3d%3d%3d%3d%4.2f%4.2f%-5d\n"
p->
voidsearchnum(STUDENT*head)
chars[9];
Pleaseinportthenum.\n"
no,s)&
voidsave(STUDENT*head)
FILE*fp;
charoutfile[10];
c:
\\£
¨
inportoutfilename£
©
forexamplec:
\\score\n"
outfile);
if((fp=fopen(outfile,"
w"
))==NULL)
Cannotopenthefile\n"
return;
fwrite(p,LEN,1,fp);
fclose(fp);
Savethefile!
voidcompute_the_score(STUDENT*head)
inti,j,m,z,w,k=0;
floatthesum=0;
STUDENT*r[paixu];
STUDENT*p0,*p;
p0=head;
while(p0!
r[k++]=p0;
p0=p0->
m=k;
r[k]=NULL;
for(i=0;
m-1;
i++)
for(j=0;
j<
m-1-i;
j++)
if((*r[j]).sum<
(*r[j+1]).sum)
p=r[j];
r[j]=r[j+1];
r[j+1]=p;
}
for(i=0,j=1;
m;
(*r[i]).order=j++;
Theorder:
%d\n"
(*r[i]).order);
no.:
%sname:
%ssex:
%cage:
(*r[i]).no,(*r[i]).name,(*r[i]).sex,(*r[i]).age);
score:
sc1:
%dsc2:
%dsc3:
%dsc4:
%d\n"
(*r[i]).score[0],(*r[i]).score[1],(*r[i]).score[2],(*r[i]).score[3]);
thesum:
%4.2fave:
%4.2f\n\n\n"
(*r[i]).sum,(*r[i]).average);
Doyouwanttowatchthedetailofscore.inportyes
(1)orno
(2):
z);
if(z==1){
pleaseinput`90807060`tochoicetheleave."
w);
if(w==90){printf("
\n\nthosestudentsareover90or90.\n"
if((*r[i]).average>
=90)
{printf("
no:
}}
if(w==80){printf("
\n\nthosestudentsareover80or80\n"
=80)
}
}}
if(w==70){printf("
\n\nthosestudentsareover70or70\n"
=70)
}}
if(w==60){printf("
\n\nthosestudentsareover60or60\n"
=60)
}}
\n\nthosestudentsdidn`tpasstheexam.\n"
if((*r[i]).average<
60)
STUDENT*delete_data(STUDENT*head)
STUDENT*p1,*p2;
charc,s[9];
Pleaseinportthenoyouwanttodelete:
p1=p2=head;
while(strcmp(p1->
p1!
p2=p1;
p1=p1->
if(strcmp(p1->
no,s)==0)
{printf("
NumNamesc1sc2sc3sc4SumAveOrder\n"
%4s%4s%3d%3d%3d%3d%3f%4.2f%-5d\n"
p1->
no,p1->
name,p1->
score[0],p1->
score[1],p1->
score[2],p1->
score[3],p1->
sum,p1->
average,p1->
Areyousurey/n?
while
(1)
c);
if(c=='
n'
||c=='
N'
)break;
Y'
if(p1==head)
head=p1->
else
p2->
next=p1->
%sthestudenthavebeenDeleted.\n"
break;
}
if(p1==NULL)
Thereisnonumstudentonthelist.\n"
STUDENT*Insert(STUDENT*head,STUDENT*New)
STUDENT*p0,*p1,*p2;
intsum1,i,s;
p1=head;
p0=New;
sum1=0;
New->
New->
while(New->
if(New->
0||New->
}while(New->
0||New->
if(New->
s=s+New->
New->
if(head==NULL)
head=p0;
p0->
n