微软小冰第5代 安卓:C++编程学生成绩管理程序最重要的是流程图

来源:百度文库 编辑:查人人中国名人网 时间:2021/09/17 05:22:34

我大一的课程设计是C语言的 学生学籍管理系统 显示格式不太好 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i,j,k,h,N;
char id,password;
FILE *fp;
struct student
{
char name[6];
int number;
char institute[10];
int birthday;
char classes[10];
int tel;
char sex[5];
char address[10];
float score0;
float score1;
float score2;
}student[30],temp,temp1;
void readin();//初始化
void pass();//身份验证
void newpass();
void delwork();//删除
void putin();//添加
void rework();//修改
void compositor();//排序
void compositor0();
void compositor1();
void compositor2();
void average();//平均值
//void star();//分数统计
void sortbycmark();
void sortbygmark();
void sortbyymark();
void read();//打印数据
void search();//数据查询
void search1();//按学号查询
void search2();//按姓名查询
void main()
{
pass();
int a;
do
{
printf(" **************************************************************\n");
printf(" * 学生学籍管理系统 *\n");
printf(" * *\n");
printf(" * 1-----------数据初始化 2-----------数据修改 *\n");
printf(" * *\n");
printf(" * 3-----------数据删除 4-----------添加数据 *\n");
printf(" * *\n");
printf(" * 5-----------计算平均值 6-----------打印数据 *\n");
printf(" * *\n");
printf(" * 7-----------数据排序 8-----------数据查询 *\n");
printf(" * *\n");
printf(" * ☆★☆★☆★☆★☆★ 0-----------保存退出 *\n");
printf(" * *\n");
printf(" * *\n");
printf(" * 按数字键选择相应程序 *\n");
printf(" **************************************************************\n");
printf("Choose a number please:\n");
scanf("%d",&a);
switch(a)
{
case 1:readin();break;
case 2:rework();break;
case 3:delwork();break;
case 4:putin();break;
case 5:average();break;
case 6:read();break;
case 7:compositor();break;
case 8:search();break;
case 0:printf("您可以安全的退出了!\n");exit(0);break;
};
}while(1);
}
void pass()
{
int a,b;
id=123,password=123;
printf("Input your id please:\n");
scanf("%d",&a);
if(a==id)
{
printf("Input your password please:\n");
scanf("%d",&b);
if(b==password)
printf("Welcome!\n");
else
{
printf("You have input a wrong password!\n");
printf("Input your password please:\n");
scanf("%d",&b);
if(b==password)printf("Welcome\n");
else exit(0);
}
}
else
{
printf("You have input a wrong id!\n");
printf("Input your id please:\n");
scanf("%d",&a);
if(a==id)
{
printf("Input your password please:\n");
scanf("%d",&b);
if(b==password)printf("Welcome!\n");
else
{
printf("You have input a wrong password!\n");
printf("Input your password please:\n");
scanf("%d",&b);
if(b==password)printf("Welcome\n");
else exit(0);
}
}
else exit(0);
}
}
void readin()
{
FILE *fp;
char a;
printf("初始化将会使您丢失原有数据,是(y)否(n)继续?");
scanf("%s",&a);
while(a!='n')
{
if((fp=fopen("c://work.txt","w"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
printf("请输入您要初始化的学生总数:\n");
scanf("%d",&h);
fprintf(fp,"%d",h);
fprintf(fp,"\n");
printf("请输入姓名 学号 学院 班级 生日 性别 电话 住址 c语言成绩 高数成绩 英语成绩:\n");
for(i=0;i<h;i++)
{
fscanf(stdin,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
fprintf(fp,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
}
fclose(fp);
break;
}
}
void search()
{
int a;
printf("1----按学号查询 2----按姓名查询\n");
scanf("%d",&a);
switch(a)
{
case 1:search1();break;
case 2:search2();break;
}
}
void search1()//按学号查询
{
int a,b=0;
printf("请输入学生学号:\n");
scanf("%d",&a);
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
for(i=0;i<N;i++)
if(a==student[i].number)
{
b=1;
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
break;
}
if(b=0)
{
printf("输入学号错误,请重新输入。");
printf("请输入学生学号:");
scanf("%d",&a);
for(i=0;i<N;i++)
if(a==student[i].number)
{
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
}
}
}
void search2()//按姓名查询
{
int b=0;
char a[4];
printf("请输入学生姓名:\n");
scanf("%s",&a);
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
for(i=0;i<N;i++)
if(strcmp(a,student[i].name)==0)
{
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
b=1;
break;
}
if(b=0)
{
printf("查无此人,请重新输入。");
printf("请输入学生姓名:");
scanf("%d",&a);
for(i=0;i<N;i++)
if(strcmp(a,student[i].name)==0)
{
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
}
}
}
void read()
{
char ch;
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this file!\n");
exit(0);
}
fscanf(fp,"%d",&N);
printf("学生总数为%d\n",N);
while((ch=fgetc(fp))!=EOF)
{
fputc(ch,stdout);
}
putchar('\n');
fclose(fp);
}
void putin()
{
FILE *fp;
if((fp=fopen("c://work.txt","r+"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
printf("请输入您要添加的学生总数:\n");
scanf("%d",&k);
N+=k;
rewind(fp);
fprintf(fp,"%d",N);
fclose(fp);
if((fp=fopen("c://work.txt","a"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
printf("请输入姓名 学号 学院 班级 生日 性别 电话 住址 英语成绩 高数成绩 c语言成绩:\n");
for(i=0;i<k;i++)
{
fscanf(stdin,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
fprintf(fp,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
}
fclose(fp);
}
void rework()
{
int a;
printf("请输入您要修改的学生学号:\n");
scanf("%d",&a);
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
fclose(fp);
for(i=0;i<N;i++)
{
if(a==student[i].number)
{
j=i;
printf("该生的信息为:\n");
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
printf("输入新的姓名 学号 学院 班级 生日 性别 电话 住址 c语言成绩 高数成绩 英语成绩:\n");
fscanf(stdin,"%s%d%s%s%d%s%d%s%f%f%f",temp.name,&temp.number,temp.institute,temp.classes,&temp.birthday,temp.sex,&temp.tel,temp.address,&temp.score0,&temp.score1,&temp.score2);
break;
}
}
student[j]=temp;
fp=fopen("c://work.txt","w");
fprintf(fp,"%d",N);
fprintf(fp,"\n");
for(i=0;i<N;i++)

fprintf(fp,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
}
void delwork()
{
int a;
char b;
printf("请输入您要删除的学生学号:\n");
scanf("%d",&a);
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
fclose(fp);
for(i=0;i<N;i++)
{
if(a==student[i].number)
{
j=i;
printf("该生的信息为:\n");
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
printf("删除数据将无法找回,是(y)否(n)继续?");
scanf("%s",&b);
while(b!='n')
{
for(;j<N;j++)
student[j]=student[j+1];
N--;
fp=fopen("c://work.txt","w");
fprintf(fp,"%d",N);
fprintf(fp,"\n");
for(i=0;i<N;i++)
fprintf(fp,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
fclose(fp);
printf("删除成功!\n");
break;
}
}
}
}
void average()
{
float s;
printf("请输入要计算平均值的学生学号:");
scanf("%d",&j);
if((fp=fopen("c://work.txt","r"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
for(i=0;i<N;i++)
{
if(j==student[i].number)
s=student[i].score0+student[i].score1+student[i].score2;
s/=3;
printf("%s同学三科的平均成绩为%3.1f\n",student[i].name,s);
break;
}
}
void compositor0()
{
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
if(student[i].score0<student[j].score0)
{
temp=student[i];
student[i]=student[j];
student[j]=temp;
}
for(i=0;i<N;i++)
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
break;

}

}
void compositor1()
{
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
if(student[i].score1<student[j].score1)
{
temp=student[i];
student[i]=student[j];
student[j]=temp;
}
for(i=0;i<N;i++)
fprintf(stdout,"%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
break;

}

}
void compositor2()
{
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
if(student[i].score2<student[j].score2)
{
temp=student[i];
student[i]=student[j];
student[j]=temp;
}
for(i=0;i<N;i++)
printf("%s%7d%7s%8s%8d%7s%8d%7s%7.1f%7.1f%7.1f\n",student[i].name,student[i].number,student[i].institute,student[i].classes,student[i].birthday,student[i].sex,student[i].tel,student[i].address,student[i].score0,student[i].score1,student[i].score2);
break;

}
}
void compositor()
{
int b;
printf("请输入---1按C成绩排序;---2按数学成绩排序---3按英语成绩排序");
scanf("%d",&b);
if((fp=fopen("c://work.txt","r+"))==NULL)
{
printf("Can't open this fill!");
exit(0);
}
fscanf(fp,"%d",&N);
for(i=0;i<N;i++)
fscanf(fp,"%s%d%s%s%d%s%d%s%f%f%f",student[i].name,&student[i].number,student[i].institute,student[i].classes,&student[i].birthday,student[i].sex,&student[i].tel,student[i].address,&student[i].score0,&student[i].score1,&student[i].score2);
switch(b)
{
case 1:compositor0();break;
case 2:compositor1();break;
case 3:compositor2();break;
}
fclose(fp);
}