用C语言编程实现一个简单的学生成绩管理系统
//姓名,学号,英语,语文,数学三种成绩
#include <stdio.h>
#include <stdlib.h>
#define maxnumber 30
int student_number;
int count1=0,count2=0,Operate1=3;
FILE *stream;
typedef struct stu{
int idnumber;
char name[20];
double English_score;
double chinese_score;
double math_score;
}Student;
//按学号排序
void putout_one(Student *sp)
{
for( int j=0;j<10;j++)
printf("******");
printf("\n");
printf(" %d %s %.1f %.1f %.1f\n",(*sp).idnumber,(*sp).name,(*sp).English_score,(*sp).chinese_score,(*sp).math_score);
for( j=0;j<10;j++)
printf("******");
printf("\n");
}
void putout_lot(Student *student)
{
for(int i=0;i<=Operate1;i++)
{
for(int j=0;j<10;j++)
printf("******");
printf("\n");
printf(" %d %s %.1f %.1f %.1f\n",student[i].idnumber,student[i].name,student[i].English_score,student[i].chinese_score,student[i].math_score);
}
for( int j=0;j<10;j++)
printf("******");
printf("\n");
}
void input_student(Student *S)//输入插入学生的信息
{
//printf("请输入第%d位学生(学号,名字,语文,英语,数学)\n",i+1);
scanf("%d",&(*S).idnumber);
scanf("%s",&(*S).name);
scanf("%lf%lf%lf",&(*S).chinese_score,&(*S).English_score,&(*S).math_score);
}
void id_find_in(Student *S,Student *q)//把新的学生信息加入表单
{
Student *p=S,*t;
while(count1<Operate1+1)
{
t=p;
p++;
count1++;
}
*t=*q;
count1=0;
Operate1++;
}
void insert_element(Student *S)//插入学生信息
{
printf("请输入1位学生(学号,名字,语文,英语,数学)\n");
Student *temp=(Student *)malloc(sizeof(Student)),*q=S;
input_student(temp);
id_find_in(S,temp);
}
void delet_element(Student *S,int id_n)
{
Student *p=S,*t;
while(count1<Operate1)
{
if((*p).idnumber==id_n)
{
t=p;
printf("已删除%d号学生信息\n",(*p).idnumber);
while(count2<Operate1-count1-1)
{
*(t-1)=*(++t);
count2++;
}
break;
}
count1++;
p++;
}
count1=0;
count2=0;
Operate1--;
}
int junge(char*a,char*b)
{
char *p=a,*q=b;
while(*p!='\0')
{
if(*p==*q)
{
p++;
q++;
continue;
}
else
break;
}
if(*p=='\0'&&*q=='\0')
return 1;
else
return 0;
}
void show_stu_element(Student*S,char*sp)//显示某人信息(功能已实现)
{
Student *p=S;
while(count1<Operate1)
{
if(junge((*p).name,sp))
{
printf("已找到此人:%s\n",(*p).name);
putout_one(p);
p=S;
break;
}
else
{
p++;
count1++;
continue;
}
}
if(p!=S)
printf("查无此人!\n");
count1=0;
}
void id_sort(Student *S)
{
Student *temp=(Student*)malloc(sizeof(Student)),*q=S,*t;
int num=Operate1;
while(count1<Operate1)
{
t=q+1;
while(count2<num)
{
if( (*q).idnumber> (*t).idnumber)
{
*temp=*q;
*q=*t;
*(t)=*temp;
// printf("%d\n",(*t).idnumber);
}
count2++;
t++;
// t=t+sizeof(Student); //这样无法实现why?
}
num--;
q++;
count2=0;
count1++;
//q=q+sizeof(Student);
}
count1=0;
count2=0;
}
void count_passnumber(Student *S)
{
Student *p=S;
int e_p_number=0,m_p_number=0,c_p_number=0,num=0;
while(num<=Operate1)
{
if(p->English_score>=60)
e_p_number++;
if(p->math_score>=60)
m_p_number++;
if(p->chinese_score>=60)
c_p_number++;
num++;
p++;
}
printf("/***学生总人数=:%d\n",Operate1);
printf("/***英语过关人数=%d 数学过关人数=%d 语文过关人数=%d\n",e_p_number,m_p_number,c_p_number);
printf("/***英语挂科人数=%d 数学挂科人数=%d 语文挂科人数=%d\n",Operate1+1-e_p_number,Operate1+1-m_p_number,Operate1+1-c_p_number);//因为数组下标是从0开始的
}
void main()
{
Student student[maxnumber];
stream=freopen("in.txt","r",stdin);
int Operate=3;int i;int id_n;
char student_element[20];
for(i=0;i<Operate1;i++)
{
printf("请输入第%d位学生(学号,名字,语文,英语,数学)\n",i+1);
scanf("%d",&student[i].idnumber);
scanf("%s",&student[i].name);
scanf("%lf%lf%lf",&student[i].chinese_score,&student[i].English_score,&student[i].math_score);
}
//fclose(stream);
for( i=0;Operate!=0;i++)
{
printf("输入:0.退出。 1.输入学生信息 2.按姓名查找并删除学生信息 \n3.按学号排序 4.查找显示一位学生信息 \n5.显示统计记录(成员数、每科平均分) 6.输出每科及格人数和不及格人数 7(default).操作完成,等待用户输入:\n");
scanf("%d",&Operate);
switch(Operate)
{
case 1:insert_element(student); break;
case 2: scanf("%d",&id_n); delet_element(student,id_n); break;
case 3:id_sort(student);break;
case 4:scanf("%s",student_element); show_stu_element(student,student_element);break;
case 5:putout_lot(student);break;
case 6:count_passnumber(student);break;
default: printf("请输入:\n");continue;
}
if(Operate==0)
break;
}
}