急求C语言课程设计:学生成绩管理程序

一、系统的主要功能
(1)输入若干条记录
(2)显示所有记录
(3)按学号排序
(4)插入一条记录
(5)按姓名查找,删除一条记录
(6)查找并显示一条记录
(7)输出统计信息(新增)
(8)从正文中添加数据到结构体数组中
(9)将所有数据写入文件中
(0)退出程序
二、题目分析
该题主要考察学生对结构体,指针,文件的操作,以及C语言算法的掌握,所以完成此道题目要求较强的设计能力,尤其是要有一种大局观的意识。如何调程序也非常重要,通过这个程序可以学习到以前调试短程序没有的的经验。
下面就各个子程序中的功能进行说明:
功能1和4的算法相似,输入一条记录到结构体中去,其中有一部很关键,就是通过gets将所有的多余的字符,回车读去,否则就会出错。
功能2是显示所有的记录,通过循环输出,格式也比较重要。
功能3为按学号排序,因为学号定义成了字符数组的形式,因此在运用冒泡法进行排序的时候,要用到strcmp,strcpy等函数。
功能5为按姓名删除记录,先输入姓名,再一一比较,如果没有则返回失败信息,如果找到就将此记录都向前移一位,返回n-1。
功能6的算法在5中就已经体现了,输入姓名,一一比较。
功能7为新增的功能,因为考虑到原来给出的函数中竟然没有对学生成绩的统计功能,因此新增此功能,可以得出所有的记录个数,最高、最低、平均分,并输出相关的学生信息等。
功能8和9是对文件的操作,提前准备好数据。

#include<stdio.h>
#include<string.h>
#define LIST_INIT_SIZE 10
#define INCREAMENT 5
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
#define OK 1
#define LT(a,b) ((a)<(b))
int i,j,low,high;
typedef int Status;
typedef struct
{int seat;
char name[7];
char sex[7];
int year;
int score[3];
int total;
float average;
}rec;
typedef struct
{rec *stu;
int length;
int listsize;
}SqList;
typedef struct
{int grade;
int lowest;
int highest;
double ave;
int nam;
}dis;
typedef struct
{dis *sco;
int len;
int size;
}Dis;
Status InitList_Sq(SqList *L)
{(*L).stu=(rec *)malloc(LIST_INIT_SIZE*sizeof(rec));
if(!(*L).stu) exit (OVERFLOW);
(*L).length=5;
(*L).listsize=10;
return OK;
}
Status List_Sq(Dis *S)
{(*S).sco=(dis *)malloc(LIST_INIT_SIZE*sizeof(dis));
if(!(*S).sco) exit (OVERFLOW);
(*S).len=3;
(*S).size=10;
return OK;
}
Status Insert(SqList *L)
{int g;
printf("\nHow many students you want to input:");
scanf("%d",&g);
for(i=(*L).length+1;i<=(*L).length+g;i++)
{if((*L).listsize<=(*L).length)
{(*L).stu=(int *)realloc((*L).stu,((*L).listsize+INCREAMENT)*sizeof(int));
if(!(*L).stu)exit(OVERFLOW);
(*L).listsize+=INCREAMENT;
}
printf("please input student'infmation:");
printf("\nxue hao:");
scanf("%d",&(*L).stu[i].seat);
printf("\nname:");
scanf("%s",&(*L).stu[i].name);
printf("\nsex:");
scanf("%s",&(*L).stu[i].sex);
printf("\nyear:");
scanf("%d",&(*L).stu[i].year);
printf("\ngrades of three disciplines:");
for(j=0;j<3;j++)
scanf("%d",&(*L).stu[i].score[j]);
}
(*L).length+=g;
}
Status Delete(SqList *L,int i)
{rec *p,*q;
rec *e;
if((i<1)||(i>(*L).length))return ERROR;
p=&((*L).stu[i]);
*e=*p;
q=(*L).stu+(*L).length;
for(++p;p<=q;++p)*(p-1)=*p;
--(*L).length;
return OK;
}
Computing(SqList *L)
{for(i=0;i<=(*L).length;i++)
{(*L).stu[i].total=(*L).stu[i].score[0]+(*L).stu[i].score[1]+(*L).stu[i].score[2];
(*L).stu[i].average=(*L).stu[i].total/3;
}
return OK;
}
void BInsertSort(SqList *L)
{int m;
for(i=2;i<=(*L).length;++i)
{(*L).stu[0]=(*L).stu[i];
low=1;
high=i-1;
while(low<=high)
{m=(low+high)/2;
if(LT((*L).stu[0].seat,(*L).stu[m].seat)) high=m-1;
else low=m+1;
}
for(j=i-1;j>=high+1;--j) (*L).stu[j+1]=(*L).stu[j];
(*L).stu[high+1]=(*L).stu[0];
}
}
int Partion(SqList *L,int low ,int high)
{int pivotkey;
(*L).stu[0]=(*L).stu[low];
pivotkey=(*L).stu[low].total;
while(low<high)
{while(low<high&&(*L).stu[high].total>=pivotkey) --high;
(*L).stu[low]=(*L).stu[high];
while(low<high&&(*L).stu[low].total<=pivotkey) ++low;
(*L).stu[high]=(*L).stu[low];
}
(*L).stu[low]=(*L).stu[0];
return low;
}
int QSort(SqList *L, int low,int high)
{int pivotloc;
if(low<high)
{pivotloc=Partion(&(*L),low,high);
QSort(&(*L),low,pivotloc-1);
QSort(&(*L),pivotloc+1,high);
}
}
int Com(Dis *S,SqList *L)
{int g;
for(j=0;j<3;j++)
{(*S).sco[j].highest=(*L).stu[1].score[j];
(*S).sco[j].lowest=(*L).stu[1].score[j];
(*S).sco[j].grade=0;
}
(*S).sco[0].nam=1;
(*S).sco[1].nam=2;
(*S).sco[2].nam=3;
for(j=0;j<(*S).len;j++)
{for(i=0;i<(*L).length;i++)
{(*S).sco[j].grade+=(*L).stu[i+1].score[j];
if((*S).sco[j].highest<(*L).stu[i+1].score[j])
(*S).sco[j].highest=(*L).stu[i+1].score[j];
if((*S).sco[j].lowest>(*L).stu[i+1].score[j])
(*S).sco[j].lowest=(*L).stu[i+1].score[j];
}
(*S).sco[j].ave=(*S).sco[j].grade/(*L).length;
}
printf("\nPlease input the discipline:1.Math 2.English 3.Program design");
scanf("%d",&g);
for(i=0;i<3;i++)
if((*S).sco[i].nam==g)
print_3(&(*S),i);
}
print_1(SqList *L)
{int i;
printf("\nseat name sex year Math English Program\n");
for(i=1;i<=(*L).length;i++)
{printf("%d %s %s %d %d %d %d\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2]);
}
return OK;
}
print_2(SqList *L)
{int i;
printf("\nseat name sex year Math English Program total averge\n");
for(i=(*L).length;i>=1;i--)
{printf("%d %s %s %d %d %d %d %d %f\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2],(*L).stu[i].total,(*L).stu[i].average);

}
return OK;
}
print_3(Dis *S,int g)
{printf("\nThe average:%lf",(*S).sco[g].ave);
printf("\nThe highest:%d",(*S).sco[g].highest);
printf("\nThe lowest:%d",(*S).sco[g].lowest);
}
print(SqList *L,int i)
{
printf("\nseat name sex year Math English Program\n");
printf("%d %s %s %d %d %d %d\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2]);

return OK;
}
main()
{SqList L;
Dis S;
int i,j,k;
i=InitList_Sq(&L);
if(i)
{rec s[5]={{103,"zhao","male ",19,80,90,75},
{102,"qian","female",20,85,82,69},
{105,"sun ","male ",20,90,56,81},
{104,"li ","male ",20,89,78,88},
{101,"zhou","female",19,78,79,86}};
for(i=0;i<5;i++)
{L.stu[i+1]=s[i];
}
}
print_1(&L);
while(1)
{printf("Please choose to search:1.Insert 2.delete 3.sort according to xuehao 4.continue");
scanf("%d",&k);
if(k==1)
{Insert(&L);
print_1(&L);
}
if(k==2)
{printf("Please input the student's xue hao you want to delete\n");scanf("%d",&j);
for(i=1;L.stu[i].seat!=j&&i<=L.length;i++);
if(i<=L.length) {Delete(&L,i);print_1(&L);}
else printf("There is none of the person\n");
}
if(k==3)
{BInsertSort(&L);
print_1(&L);
}
if(k==4) break;
getch();
}
List_Sq(&S);
while(1)
{printf("\nPlease choose 1.the sort of total 2.one subject 3.search 4.leave");
scanf("%d",&k);
if(k==1)
{Computing(&L);
QSort(&L,1,L.length);print_2(&L);
}
if(k==2)Com(&S,&L);
if(k==3)
{printf("Please input the student's xue hao you want to search:");scanf("%d",&j);
for(i=1;L.stu[i].seat!=j&&i<=L.length;i++);
if(i<=L.length) print(&L,i);
else printf("There is none of the person\n");
}
if(k==4) break;
}
}还有 这个C语言学得好的话真的很好玩的 要认真学啊同学
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-12
#include<stdio.h>
#include<string.h>
#define LIST_INIT_SIZE 10
#define INCREAMENT 5
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
#define OK 1
#define LT(a,b) ((a)<(b))
int i,j,low,high;
typedef int Status;
typedef struct
{int seat;
char name[7];
char sex[7];
int year;
int score[3];
int total;
float average;
}rec;
typedef struct
{rec *stu;
int length;
int listsize;
}SqList;
typedef struct
{int grade;
int lowest;
int highest;
double ave;
int nam;
}dis;
typedef struct
{dis *sco;
int len;
int size;
}Dis;
Status InitList_Sq(SqList *L)
{(*L).stu=(rec *)malloc(LIST_INIT_SIZE*sizeof(rec));
if(!(*L).stu) exit (OVERFLOW);
(*L).length=5;
(*L).listsize=10;
return OK;
}
Status List_Sq(Dis *S)
{(*S).sco=(dis *)malloc(LIST_INIT_SIZE*sizeof(dis));
if(!(*S).sco) exit (OVERFLOW);
(*S).len=3;
(*S).size=10;
return OK;
}
Status Insert(SqList *L)
{int g;
printf("\nHow many students you want to input:");
scanf("%d",&g);
for(i=(*L).length+1;i<=(*L).length+g;i++)
{if((*L).listsize<=(*L).length)
{(*L).stu=(int *)realloc((*L).stu,((*L).listsize+INCREAMENT)*sizeof(int));
if(!(*L).stu)exit(OVERFLOW);
(*L).listsize+=INCREAMENT;
}
printf("please input student'infmation:");
printf("\nxue hao:");
scanf("%d",&(*L).stu[i].seat);
printf("\nname:");
scanf("%s",&(*L).stu[i].name);
printf("\nsex:");
scanf("%s",&(*L).stu[i].sex);
printf("\nyear:");
scanf("%d",&(*L).stu[i].year);
printf("\ngrades of three disciplines:");
for(j=0;j<3;j++)
scanf("%d",&(*L).stu[i].score[j]);
}
(*L).length+=g;
}
Status Delete(SqList *L,int i)
{rec *p,*q;
rec *e;
if((i<1)||(i>(*L).length))return ERROR;
p=&((*L).stu[i]);
*e=*p;
q=(*L).stu+(*L).length;
for(++p;p<=q;++p)*(p-1)=*p;
--(*L).length;
return OK;
}
Computing(SqList *L)
{for(i=0;i<=(*L).length;i++)
{(*L).stu[i].total=(*L).stu[i].score[0]+(*L).stu[i].score[1]+(*L).stu[i].score[2];
(*L).stu[i].average=(*L).stu[i].total/3;
}
return OK;
}
void BInsertSort(SqList *L)
{int m;
for(i=2;i<=(*L).length;++i)
{(*L).stu[0]=(*L).stu[i];
low=1;
high=i-1;
while(low<=high)
{m=(low+high)/2;
if(LT((*L).stu[0].seat,(*L).stu[m].seat)) high=m-1;
else low=m+1;
}
for(j=i-1;j>=high+1;--j) (*L).stu[j+1]=(*L).stu[j];
(*L).stu[high+1]=(*L).stu[0];
}
}
int Partion(SqList *L,int low ,int high)
{int pivotkey;
(*L).stu[0]=(*L).stu[low];
pivotkey=(*L).stu[low].total;
while(low<high)
{while(low<high&&(*L).stu[high].total>=pivotkey) --high;
(*L).stu[low]=(*L).stu[high];
while(low<high&&(*L).stu[low].total<=pivotkey) ++low;
(*L).stu[high]=(*L).stu[low];
}
(*L).stu[low]=(*L).stu[0];
return low;
}
int QSort(SqList *L, int low,int high)
{int pivotloc;
if(low<high)
{pivotloc=Partion(&(*L),low,high);
QSort(&(*L),low,pivotloc-1);
QSort(&(*L),pivotloc+1,high);
}
}
int Com(Dis *S,SqList *L)
{int g;
for(j=0;j<3;j++)
{(*S).sco[j].highest=(*L).stu[1].score[j];
(*S).sco[j].lowest=(*L).stu[1].score[j];
(*S).sco[j].grade=0;
}
(*S).sco[0].nam=1;
(*S).sco[1].nam=2;
(*S).sco[2].nam=3;
for(j=0;j<(*S).len;j++)
{for(i=0;i<(*L).length;i++)
{(*S).sco[j].grade+=(*L).stu[i+1].score[j];
if((*S).sco[j].highest<(*L).stu[i+1].score[j])
(*S).sco[j].highest=(*L).stu[i+1].score[j];
if((*S).sco[j].lowest>(*L).stu[i+1].score[j])
(*S).sco[j].lowest=(*L).stu[i+1].score[j];
}
(*S).sco[j].ave=(*S).sco[j].grade/(*L).length;
}
printf("\nPlease input the discipline:1.Math 2.English 3.Program design");
scanf("%d",&g);
for(i=0;i<3;i++)
if((*S).sco[i].nam==g)
print_3(&(*S),i);
}
print_1(SqList *L)
{int i;
printf("\nseat name sex year Math English Program\n");
for(i=1;i<=(*L).length;i++)
{printf("%d %s %s %d %d %d %d\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2]);
}
return OK;
}
print_2(SqList *L)
{int i;
printf("\nseat name sex year Math English Program total averge\n");
for(i=(*L).length;i>=1;i--)
{printf("%d %s %s %d %d %d %d %d %f\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2],(*L).stu[i].total,(*L).stu[i].average);

}
return OK;
}
print_3(Dis *S,int g)
{printf("\nThe average:%lf",(*S).sco[g].ave);
printf("\nThe highest:%d",(*S).sco[g].highest);
printf("\nThe lowest:%d",(*S).sco[g].lowest);
}
print(SqList *L,int i)
{
printf("\nseat name sex year Math English Program\n");
printf("%d %s %s %d %d %d %d\n",(*L).stu[i].seat,(*L).stu[i].name,(*L).stu[i].sex, (*L).stu[i].year,(*L).stu[i].score[0],(*L).stu[i].score[1],(*L).stu[i].score[2]);

return OK;
}
main()
{SqList L;
Dis S;
int i,j,k;
i=InitList_Sq(&L);
if(i)
{rec s[5]={{103,"zhao","male ",19,80,90,75},
{102,"qian","female",20,85,82,69},
{105,"sun ","male ",20,90,56,81},
{104,"li ","male ",20,89,78,88},
{101,"zhou","female",19,78,79,86}};
for(i=0;i<5;i++)
{L.stu[i+1]=s[i];
}
}
print_1(&L);
while(1)
{printf("Please choose to search:1.Insert 2.delete 3.sort according to xuehao 4.continue");
scanf("%d",&k);
if(k==1)
{Insert(&L);
print_1(&L);
}
if(k==2)
{printf("Please input the student's xue hao you want to delete\n");scanf("%d",&j);
for(i=1;L.stu[i].seat!=j&&i<=L.length;i++);
if(i<=L.length) {Delete(&L,i);print_1(&L);}
else printf("There is none of the person\n");
}
if(k==3)
{BInsertSort(&L);
print_1(&L);
}
if(k==4) break;
getch();
}
List_Sq(&S);
while(1)
{printf("\nPlease choose 1.the sort of total 2.one subject 3.search 4.leave");
scanf("%d",&k);
if(k==1)
{Computing(&L);
QSort(&L,1,L.length);print_2(&L);
}
if(k==2)Com(&S,&L);
if(k==3)
{printf("Please input the student's xue hao you want to search:");scanf("%d",&j);
for(i=1;L.stu[i].seat!=j&&i<=L.length;i++);
if(i<=L.length) print(&L,i);
else printf("There is none of the person\n");
}
if(k==4) break;
}
}
第2个回答  2012-05-31
好可怕啊,还好没学
第3个回答  2012-05-31
额???
第4个回答  2012-05-31
留个邮箱

发给你追问

920914166@qq.com谢谢

追答

发了
希望能帮助你

相似回答