stu[i]=stu[j] stu[i]=stu[j] stu[j]=temp stu[j]=temp3.3 系统特点
【1】特点:这个学生信息管理系统建立了学生信息的结构体,实现了学生信息的录入、添加、修改、删除、查找等功能,并能计算学生的平均分和总分,对学生进行排序。 4. 程序代码
【1】程序代码
void Help(); void Save(struct student stu[]); void InputStu(struct student stu[]); void DelStu(struct student stu[]); void ModifyStu(struct student stu[]); void FindStu(struct student stu[]); void InsertStu(struct student stu[]); void SortStu(struct student stu[]); void ListStu(struct student stu[]); void main()
_
{ struct student stu[50]; struct student *p; int in; int in1; char ch;
void InputStu(struct student stu[]) { pp=stu; system(\"cls\"); int i;
printf(\"Number of students you want to enter information:\"); scanf(\"%d\
if((fp=fopen(\"inputdata.sys\ { printf(\"Cannot open file strike any key exit!\"); getch(); exit(1); } void ModifyStu(struct student stu[]) { system(\"cls\");
pp=stu; int id,i,flag=1; if((fp=fopen(\"modifydata.sys\ { printf(\"Cannot open file strike any key exit!\"); getch(); exit(1); }
void FindStu(struct student stu[])
{ system(\"cls\"); int i=0,id,flag=1,chose;
printf(\"\\nPlease select query: 1.No. inquiries by school;2.Query by class;3.Query by name\\n\");
scanf(\"%d\
_
switch(chose){
case 1: printf(\"Please enter your query No. students:\"); scanf(\"%d\for(i=0;i { if (stu[i].num==id) { flag=0;
stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3; stu[i].ave=stu[i].sum/3;
printf(\"\\nNo. Studies\\ Name\\ No. classes\\ The first subjec\\ The third subject\\Average \\Total\\n\");
void InsertStu(struct student stu[ ]) { system(\"cls\");
int flag=1; pp=stu; int i,id;
if((fp=fopen(\"insertdata.sys\ { printf(\"Cannot open file strike any key exit!\"); getch(); exit(1); }
void ListStu(struct student stu[]) { int i=0;
for(i=0;i { stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3; stu[i].ave=stu[i].sum/3;}
printf(\"\\nNo. Studies\\ Name\\ No. classes\\ The first subjec\\ The second subject\\ The second subject\\
_
The third subject\\Average \\Total\\n\"); for(i=0;i %d
%s
%d
\%d
\%d
\%d
\%d %d\e3,stu[i].ave, stu[i].sum); } getch(); }
void DelStu(struct student stu[]) { system(\"cls\");
pp=stu; int delnum,flag=1; char ask; int i,j; if((fp=fopen(\"Deldata.sys\ { printf(\"Cannot open file strike any key exit!\"); getch(); exit(1); }
void SortStu(struct student stu[]) { system(\"cls\");
int i,j,chose; struct student temp;
printf(\"To sort the data before:\\n\");
printf(\"\\nNo. Studies\\ Name\\ No. classes\\ The first subjec\\ The second subject\\ The third subject\\Average \\Total\\n\"); for(i=0;i {printf(\"\\n %d %s %d %d\ %d\ %d\ %d\ %d\\n\[i].classid,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].ave,stu[i].sum); }
_
printf(\"\\n1.Sort by Student ID\2.By the average score (high → low) Sort\\n\"); void Save(struct student stu[])
{ int i,j; pp=stu; system(\"cls\");
printf(\"\\n\\n\\n\\n\\\Saving\");
if((fp=fopen(\"stu_list2.doc\ { printf(\"Cannot open file strike any key exit!\"); getch(); exit(1); }
【2】程序执行结果
【3】结果的讨论:系统最后将修改过后的学生信息保存了下来 5.调试情况
三科成绩、平均分、总分不能用float定义应改为int
定义应在函数的最前端
_
文件未定义
这是建立学生信息文件
添加学生信息并计算平均分和总分
_
找不到要删除的学生信息
删除了学号为12的学生信息
修改学生信息
新学生信息记录
_
保存信息后退出程序 6.结论
(1)能够通过编译时出现的出错提示信息,进行初步的纠错。
(2)完成一个程序的一般步骤为设计,录入 ,编译 ,如果出错,则修改,然后再编译,编译成功后,看看结果是否正确,如果结果不正确,则再重复以上步骤。 (3)从这次编程序的过程中,我学到了编程所必须具备的专业技能,更领会编译程序所需要的细心和耐心。