班级学生管理系统麻烦各位
这是做一个班级信息管理系统,运行完之后没有错误,但是不知道为什么不是我想要的结果,拜托各位帮忙看看,在此先谢过
程序代码:#include<stdio.h>
#include<string.h>
/*数据结构设计*/
typedef int keytype;
typedef struct Student
{
keytype sno;
float ChineS;
float MathS;
float EnglS;
float SumS;
float AveS;
struct Student *next;
}linkStu;
/*输入学生成绩,并插入学生信息*/
linkStu *InputStu(linkStu *L)
{
linkStu *p,*stu;
int s;
float cs,ms,es;
p=(linkStu *)malloc(sizeof(linkStu));
p=L;
stu=(linkStu *)malloc(sizeof(linkStu));
stu->next=NULL;
printf("请输入学生的sno cs ms es:\n");
scanf("%d,%f,%f,%f",&s,&cs,&ms,&es);
stu->sno=s; stu->ChineS=cs;stu->MathS=ms;stu->EnglS=es;
stu->SumS=stu->ChineS+stu->MathS+stu->EnglS;
stu->AveS=(stu->ChineS+stu->MathS+stu->EnglS)/3;
if(p->next==NULL)
p=stu;
else
{while(p->next!=NULL&&p->sno<stu->sno) p=p->next;
p->next=stu;
}
free(stu);
return L;
}
/*输出所有学生的成绩*/
void OutputStuA(linkStu *L)
{
linkStu *p;
p=L;
printf("sno\tChineseScore\tMathScore\tEnglishScore\tSumScore\tAverageScore\n");
printf("%d\t%f\t%f\t%f\t%f\t%f\t\n",p->sno,p->ChineS,p->MathS,p->EnglS,p->SumS,p->AveS);
p=p->next;
if(p->next!=NULL)
printf("%d\t%f\t%f\t%f\t%f\t%f\t\n",p->sno,p->ChineS,p->MathS,p->EnglS,p->SumS,p->AveS);
}
/*显示按照指定分数段以及科目*/
void OutputStu(linkStu *L,float l,float h,char object)
{
linkStu *p;
p=L;
if(object='c')
{
if(p->next!=NULL)
{
if(p->ChineS>=l||p->ChineS<=h)
printf("%d\t%f\t%f\t%f\t%f\t%f\t\n",p->sno,p->ChineS,p->MathS,p->EnglS,p->SumS,p->AveS);
}
}
if(object='m')
{
if(p->next!=NULL)
{
if(p->MathS>=l||p->MathS<=h)
printf("%d\t%f\t%f\t%f\t%f\t%f\t\n",p->sno,p->ChineS,p->MathS,p->EnglS,p->SumS,p->AveS);
}
}
if(object='e')
{
if(p->next!=NULL)
{
if(p->EnglS>=l||p->EnglS<=h)
printf("%d\t%f\t%f\t%f\t%f\t%f\t\n",p->sno,p->ChineS,p->MathS,p->EnglS,p->SumS,p->AveS);
}
}
}
/*统计班级人数*/
int CountStu(linkStu *L)
{
int count;
linkStu *p;
p=L;
count=0;
if(p->next!=NULL) count++;
return count;
}
/*班级的平均成绩*/
float AveScore(linkStu *L)
{
linkStu *p;
int j;
float sum,ave;
p=L;
sum=0;
j=CountStu(L);
if(p->next!=NULL)
sum=sum+p->AveS;
ave=sum/j;
return ave;
}
/*删除指定学生信息*/
linkStu *DeleteStu(linkStu *L,char sno)
{
linkStu *p,*q;
p=L;
q=L->next;
while(q!=NULL&&q->sno!=sno)
{
p=q;
q=q->next;
}
if(q==NULL) printf("您所要删除的学生不存在\n");
else
{
q->next=q->next;
free(q);
}
return L;
}
void main()
{
int i;linkStu *L;int sno;
L=(linkStu *)malloc(sizeof(linkStu));
L->next=NULL;
printf("******************************选择您所需要的操作*************************\n\n");
printf("**************************************菜单*******************************\n\n");
printf("********************************1、插入学生******************************\n\n");
printf("******************************2、查看学生信息****************************\n\n");
printf("********************************3、班级人数******************************\n\n");
printf("**********************************0、退出********************************\n\n");
scanf("%d",&i);
while(i!=0)
{
if(i=1) InputStu(L);
if(i=2) OutputStuA(L);
if(i=3) CountStu(L);
}
}







