



#include
#include
#include
#include
#include
struct student
{
char name[21];
char number[21];
char specialty[21];
char sex[3];
int c_score;
int english_score;
int math_score;
int total_score;
};
typedef struct student student;
student studentArray[100];
char putout[9][21]={"姓名","学号","专业","性别","c语言","英语","数学","总成绩","名次"}; //为格式化输出做准备
int count=0; //用来记录学生的记录个数
//函数声明部分
void initialStudent();
void addStudent();
int judge(int );
void delstudent();
void modifyStudent();
void searchStudent();
void studentProfile();
void getaveragescore(int [],int ,double *);
void setOrder(int );
void selectSort(char [][21],int [],int ,int ,int ,char [][21]);
void printUnpassed();
void printAll();
int menuselect();
void clear();
//创建e:\\student.txt文件,并初始化,同时计算出文件中含有的记录总数
void initial()
{
FILE *fp;
char choice=''y'';
int i=0;
fp=fopen("e:\\student.txt","r");
if(!fp)
{
printf("创建文件失败,即将返回");
return ;
}
for(;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++);
count=i;
}
//添加学生信息
void addStudent()
{
FILE *fp;
char choice=''y'';
int i=0;
//int sum;
fp=fopen("e:\\student.txt","ab");
if(!fp)
{
printf("创建文件失败,即将返回");
return ;
}
while(choice==''y'')
{
printf("输入学生姓名,学号,专业,性别,中间以空格符隔开");
fflush(stdin);
scanf("%s%s%s%s",studentArray[i].name,studentArray[i].number,studentArray[i].specialty,studentArray[i].sex);
printf("输入学生c语言分数,英语分数,数学分数");
scanf("%d%d%d",&studentArray[i].c_score,&studentArray[i].english_score,&studentArray[i].math_score);
//sum=judge(studentArray[i].c_score)+judge(studentArray[i].english_score)+judge(studentArray[i].math_score);
while(!judge(studentArray[i].c_score)||!judge(studentArray[i].english_score)||!judge(studentArray[i].math_score))
{
printf("成绩输入错误,请重新输入");
scanf("%d%d%d",&studentArray[i].c_score,&studentArray[i].english_score,&studentArray[i].math_score);
//sum=judge(studentArray[i].c_score)+judge(studentArray[i].english_score)+judge(studentArray[i].math_score);
}
studentArray[i].total_score=studentArray[i].c_score+studentArray[i].english_score+studentArray[i].math_score;
fwrite(&studentArray[i],sizeof(struct student),1,fp); //将数据写入文件中
i++;
count++;
printf("是否继续输入,继续输入输入y或者Y,其它值退出");
fflush(stdin);
choice=getchar();
choice=tolower(choice);
fflush(stdin); //清空缓存输入流
}
fclose(fp);
printf("输入任意键继续");
getch();
//return ;
}
//判断输入成绩是否合法
int judge(int score)
{
if(score<0||score>100)
return 0;
else if(score<60) //只是为了计算后面的不及格学生相关信息
return 4;
else
return 1;
}
//删除学生信息
void delStudent()
{
FILE *fp,*fp2;
int i;
char choice;
int flag1=1;
int flag2=0;
int found=0; //用来标记文件中是否含有此人
char studentName[21];
char studentNumber[21];
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("文件中没有信息,即将退出");
//getch();
return ;
}
fp2=fopen("e:\ est.txt","wb");
if(!fp2)
{
printf("文件创建失败,即将退出");
return;
}
i=0;
found=0;
printf("按照姓名删除请输入0,按照学号删除请输入1");
scanf("%d",&flag2);
fflush(stdin);
if(flag2==0)
{
printf("输入要删除的学生的姓名,按回车键结束");
scanf("%s",studentName);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++) //将其他人信息转移到test.txt文件中
if(strcmp(studentArray[i].name,studentName))
fwrite(&studentArray[i],sizeof(struct student),1,fp2);
else
{
found=1;
}
fclose(fp);
fclose(fp2);
fflush(stdin);
if(found==1)
printf("是否确认删除姓名为%s该学生信息,确认删除,输入y或者Y:",studentName);
else
{
printf("没有此人信息,即将退出");
return ;
}
choice=getchar();
if(choice==''y''||choice==''Y'') //将文件结构指针重新定向
{
count--;
fp=fopen("e:\\student.txt","wb");
fp2=fopen("e:\ est.txt","rb");
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp2)!=0;i++)
fwrite(&studentArray[i],sizeof(struct student),1,fp);
fclose(fp);
fclose(fp2);
}
}
else if(flag2==1)
{
printf("输入要删除的学生的学号,按回车键结束");
scanf("%s",studentNumber);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++) //将其他人信息转移到test.txt文件中
if(strcmp(studentArray[i].number,studentNumber))
fwrite(&studentArray[i],sizeof(struct student),1,fp2);
else
found=1;
fclose(fp);
fclose(fp2);
fflush(stdin);
if(found==1)
printf("是否确认删除学号为%s的该学生信息,确认删除,输入y或者Y:",studentNumber);
else
{
printf("没有此人信息,即将退出");
return;
}
choice=getchar();
if(choice==''y''||choice==''Y'') //将文件结构指针重新定向
{
count--;
fp=fopen("e:\\student.txt","wb");
fp2=fopen("e:\ est.txt","rb");
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp2)!=0;i++)
fwrite(&studentArray[i],sizeof(struct student),1,fp);
fclose(fp);
fclose(fp2);
}
}
else
printf("输入错误");
}
//修改学生信息
void modifyStudent()
{
FILE *fp,*fp2;
int flag=0;
int i;
char studentName[21];
student newdata;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("文件中还没有学生信息,即将退出");
return ;
}
fp2=fopen("e:\ est.txt","wb");
if(!fp2)
{
printf("文件创建失败,即将返回");
return ;
}
printf("输入要修改的学生的姓名");
fflush(stdin);
scanf("%s",studentName);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++)
{
if(!strcmp(studentArray[i].name,studentName))
{
flag=1;
printf("输入要修改后学生的姓名,学号,专业,性别");
fflush(stdin);
scanf("%s%s%s%s",newdata.name,newdata.number,newdata.specialty,newdata.sex);
printf("输入修改后的学生的c语言分数,英语分数,数学分数");
scanf("%d%d%d",&newdata.c_score,&newdata.english_score,&newdata.math_score);
while(!judge(studentArray[i].c_score)||!judge(studentArray[i].english_score)||!judge(studentArray[i].math_score))
{
printf("输入不合法,请重新输入");
scanf("%d%d%d",&newdata.c_score,&newdata.english_score,&newdata.math_score);
}
newdata.total_score=newdata.c_score+newdata.english_score+newdata.math_score;
fwrite(&newdata,sizeof(struct student),1,fp2);
}
else
fwrite(&studentArray[i],sizeof(struct student),1,fp2);
}
if(flag==0)
{
printf("没有此人,即将退出");
return ;
}
fclose(fp);
fclose(fp2);
fp=fopen("e:\\student.txt","wb");
fp2=fopen("e:\ est.txt","rb");
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp2)!=0;i++)
fwrite(&studentArray[i],sizeof(struct student),1,fp);
printf("");
fclose(fp);
fclose(fp2);
}
//查找某学生信息
void searchStudent()
{
FILE *fp;
char studentName[21];
int flag=0;
int i;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("文件中还没有学生记录,即将退出");
return ;
}
printf("输入你要查找的学生姓名");
fflush(stdin);
scanf("%s",studentName);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(studentName,studentArray[i].name)==0)
{
flag=1;
printf("要查找的学生相关信息如下:");
printf("%-10s%-15s%-20s%-5s",putout[0],putout[1],putout[2],putout[3]);
printf("%-6s%-6s%-6s%-6s", putout[4],putout[5],putout[6],putout[7]);
printf("%-10s%-15s%-20s",studentArray[i].name,studentArray[i].number,studentArray[i].specialty);
printf("%-5s",studentArray[i].sex);
printf("%-6d%-6d",studentArray[i].c_score,studentArray[i].english_score);
printf("%-6d%-6d",studentArray[i].math_score,studentArray[i].total_score);
printf("");
printf("");
}
}
if(flag==0)
{
printf("没有找到姓名为%s的学生",studentName);
fflush(stdout);
printf("");
return ;
}
}
//学生信息总体概况,如平均分,总人数
void studentProfile()
{
FILE *fp;
int i;
int cArray[100]; //用来存储c语言分数
double cAverage; //用来存储c语言平均成绩
int englishArray[100];
double englishAverage;
int mathArray[100];
double mathAverage;
int totalArray[100];
double totalAverage;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("没有学生信息,即将退出");
return ;
}
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++)
{
cArray[i]=studentArray[i].c_score;
englishArray[i]=studentArray[i].english_score;
mathArray[i]=studentArray[i].math_score;
totalArray[i]=studentArray[i].total_score;
}
printf("共有%d个学生信息",count);
getaveragescore(cArray,i,&cAverage);
getaveragescore(englishArray,i,&englishAverage);
getaveragescore(mathArray,i,&mathAverage);
getaveragescore(totalArray,i,&totalAverage);
printf("c语言平均成绩为%.2f分",cAverage);
printf("英语平均成绩为%.2f分",englishAverage);
printf("数学平均成绩为%.2f分",mathAverage);
printf("总分平均成绩为%.2f分",totalAverage);
printf("");
}
//统计平均分
void getaveragescore(int arrayscore[],int n,double *averagescore)
{
double sum=0;
int i=0;
for(;i
*averagescore=sum/n;
}
//有序输出学生的成绩
void setOrder(int flag) //flag表示选择成绩是从低到高还是从高到底排序,0从低到高,1则反之
{
FILE *fp;
int i,j;
student temp;
int choice;
//flag=0;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("没有学生信息,即将退出");
return ;
}
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++); //将数据读入结构数组中
for(choice =1;choice<5;choice++)
switch(choice)
{
case 1:printf("c语言成绩:");
for(i=0;i
{
temp=studentArray[i];
studentArray[i]=studentArray[j];
studentArray[j]=temp;
}
if(!flag)
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[4]);
for(i=0;i
}
else
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[4]);
for(i=count-1;i>=0;i--)
printf("%-10d%-10s%-15s%-10d",count-i,studentArray[i].name,studentArray[i].number,studentArray[i].c_score);
}
break;
case 2:printf("英语成绩:");
for(i=0;i
{
temp=studentArray[i];
studentArray[i]=studentArray[j];
studentArray[j]=temp;
}
if(!flag)
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[5]);
for(i=0;i
}
else
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[5]);
for(i=count-1;i>=0;i--)
printf("%-10d%-10s%-15s%-10d",count-i,studentArray[i].name,studentArray[i].number,studentArray[i].english_score);
}
break;
case 3:printf("数学成绩:");
for(i=0;i
{
temp=studentArray[i];
studentArray[i]=studentArray[j];
studentArray[j]=temp;
}
if(!flag)
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[6]);
for(i=0;i
}
else
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[6]);
for(i=count-1;i>=0;i--)
printf("%-10d%-10s%-15s%-10d",count-i,studentArray[i].name,studentArray[i].number,studentArray[i].math_score);
}
break;
case 4:printf("总成绩:");
for(i=0;i
{
temp=studentArray[i];
studentArray[i]=studentArray[j];
studentArray[j]=temp;
}
if(!flag)
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[7]);
for(i=0;i
}
else
{
printf("%-10s%-10s%-15s%-10s",putout[8],putout[0],putout[1],putout[7]);
for(i=count-1;i>=0;i--)
printf("%-10d%-10s%-15s%-10d",count-i,studentArray[i].name,studentArray[i].number,studentArray[i].total_score);
}
break;
return ;
}
}
//输出不及格学生的相关信息
void printUnpassed()
{
FILE *fp;
int i;
int total=0;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("没有学生信息,即将退出");
return ;
}
printf("不及格学生相关信息如下所示");
printf("%-10s%-15s%-20s%-5s",putout[0],putout[1],putout[2],putout[3]);
printf("%-6s%-6s%-6s%-6s", putout[4],putout[5],putout[6],putout[7]);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++)
if(judge(studentArray[i].c_score)+judge(studentArray[i].english_score)+judge(studentArray[i].math_score)>3)
{
printf("%-10s%-15s%-20s",studentArray[i].name,studentArray[i].number,studentArray[i].specialty);
printf("%-5s",studentArray[i].sex);
printf("%-6d%-6d",studentArray[i].c_score,studentArray[i].english_score);
printf("%-6d%-6d",studentArray[i].math_score,studentArray[i].total_score);
printf("");
total++;
}
printf("不及格学生人数共有%d人",total);
return ;
}
//输出文件中所有学生信息记录
void printAll()
{
FILE *fp;
int i;
//student buffer;
fp=fopen("e:\\student.txt","rb");
if(count==0)
{
printf("现在还没有学生记录,即将退出");
printf("");
return ;
}
printf("该文件中一共有%d个学生记录,记录如下:",count);
printf("%-10s%-15s%-20s%-5s",putout[0],putout[1],putout[2],putout[3]);
printf("%-6s%-6s%-6s%-6s", putout[4],putout[5],putout[6],putout[7]);
for(i=0;fread(&studentArray[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("%-10s%-15s%-20s",studentArray[i].name,studentArray[i].number,studentArray[i].specialty);
printf("%-5s",studentArray[i].sex);
printf("%-6d%-6d",studentArray[i].c_score,studentArray[i].english_score);
printf("%-6d%-6d",studentArray[i].math_score,studentArray[i].total_score);
printf("");
}
}
void clear()
{
FILE *fp;
char ch;
printf("你确认删除所有学生记录吗?继续输入y活着Y");
fflush(stdin);
ch=getchar();
if(ch==''y''||ch==''Y'')
{
fp=fopen("e:\\student.txt","wb");
count=0;
}
return ;
}
//主函数
int main()
{
int choice;
printf("**************************欢迎进入学生信息管理系统******************************");
initial();
while(1)
switch(choice=menuselect())
{
case 0:
printf("************************欢迎下次再次使用*********************");
exit(0);
case 1:
addStudent();
break;
case 2:
delStudent();
break;
case 3:
modifyStudent();
break;
case 4:
searchStudent();
break;
case 5:
studentProfile();
break;
case 6:
setOrder(0);
break;
case 7:
setOrder(1);
break;
case 8:
printUnpassed();
break;
case 9:
printAll();
break;
case 10:
system("CLS");
//clrscr();
break;
case 11:
clear();
break;
}
return 0;
}
//菜单函数
int menuselect()
{
int choice;
do
{
printf("0.退出管理系统");
printf("1.添加学生信息记录");
printf("2.删除某一指定学生记录");
printf("3.修改某一给定学生信息");
printf("4.查找某一给定学生信息");
printf("5.输出学生信息总体概况");
printf("6.按照分数从低到高输出学生相关信息");
printf("7.按照分数从高到低输出学生相关信息");
printf("8.输出不及格学生的相关信息");
printf("9.输出文件中所有学生的记录");
printf("10.清屏");
printf("11.删除所有学生记录");
printf("输入你的选择:");
scanf("%d",&choice);
}while(choice<0||choice>11);
return choice;
}
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:service@bkw.cn 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。
30
人力资源管理师考试成绩有多久的有效期?:人力资源管理师考试成绩有多久的有效期?人力资源管理师考试各省组织考试的单科合格成绩只保留一年。无论几级,若有成绩不合格,则合格成绩均保留一年。如果所有成绩均不合格,或者所有成绩合格(可获得证书),都不存在考试成绩保留与否的问题。
506播放2020-06-0924
人力资源管理师考试成绩什么时候查询?:人力资源管理师考试成绩什么时候查询?人力资源管理师考试成绩一般会在考后1-2个月内公布。成绩查询方式一般为网上查询或者电话查询,考生可根据当地实际情况选择适合自己的查询方式。
887播放2020-06-0918
人力资源管理师考试成绩可以申请复查吗?:人力资源管理师考试成绩可以申请复查吗?可以的。考生可在“某某省职业技能鉴定成绩查询平台”输入姓名、准考证号、身份证号码进行查询。
665播放2020-06-09
用visualstudio软件开发一个学生成绩管理系统用C语言编写程序
chapaizeng·2019-12-08谁有C语言程序设计“学生成绩管理系统”实践报告
acengmi·2019-05-15用C语言编程图书管理系统设计
白云被你染成了腥红色·2019-05-14C语言程序设计学生成绩管理系统包括流程图,
biaohaozhei·2019-05-14C语言学生成绩管理系统代码急
changsunbao·2019-05-14C语言编写图书管理系统,已有框架
bianjiaoyan·2019-05-14学生成绩管理系统c语言实验报告
censuoer·2019-05-14C语言学生成绩管理系统
biaodiagou·2019-05-14急求用C语言编写的图书管理系统源代码
街头浪猫·2019-05-14用visualstudio软件开发一个学生成绩管理系统用C语言编写程序
cafengjin·2019-05-14
是不是必须要培训机构的结业证书才能报考人力资源管理师
chaniuduan·2021-03-26人力资源管理师考试会查证件吗
baomilao·2021-03-26考人力资源管理师是需要什么学历呢
cangxiangji·2021-03-26零基础怎么报考人力资源管理师
benruifei·2021-03-26没有毕业证能考人力资源管理师吗
chaniuduan·2021-03-26人力资源管理师主要考些什么内容?
canghuixu·2021-03-26没有工作可以报考人力资源管理师吗
chaiyangcu·2021-03-26二级人力资源管理师考试报名信息在国家哪个官网查
anmangma·2021-03-26人力资源管理师三级报名一般多少钱
chaniuduan·2021-03-26人力资源管理师考试改革了吗
chaniuduan·2021-03-26
全国人力资源管理师(二级)考试大纲:第三章培训与开发
帮考网校·2022-01-06全国人力资源管理师(二级)考试大纲:第二章招聘与配置
帮考网校·2022-01-06人力资源管理师(四级)真题
帮考网校·2022-01-06高级人力资源管理师考试真题4
帮考网校·2022-01-07高级人力资源管理师考试真题2
帮考网校·2022-01-07高级人力资源管理师考试真题1
帮考网校·2022-01-07高级人力资源管理师考试真题3
帮考网校·2022-01-07高级人力资源管理师《理论知识》真题及答案(二)
帮考网校·2022-01-07高级人力资源管理师《理论知识》真题及答案(二)
帮考网校·2022-01-07高级人力资源管理师《理论知识》真题及答案(三)
帮考网校·2022-01-07
国际人力资源管理师可以自己报考吗?
caoyaodi·2020-06-03我不是人力资源专业的,但是工作一年后想从事人事工作,请问报考人力资源管理师有用吗?应该报考几级呢?
beilounin·2020-06-03不是本行专业该不该报考人力资源管理师?
aocadian·2020-06-03人力资源管理师在现在的中国前景如何?
望着窗外孤枕难眠·2020-06-03我是非hr专业的学生,想考人力资源管理师,请问怎么考?
chancuanmi·2020-06-03人力资源师分几级?
caijieye·2020-06-02人力资源管理师证书的含金量高吗?
bangnuanzen·2020-06-02在天津考人力资源管理师三级在北京工作承认吗?
canteinv·2020-06-02人力资源管理师一级有什么用?
浅绿少年薄荷音·2020-06-01人力资源师都是干什么的?
caizousong·2020-06-01
00:56
人力资源管理师考试对作答有什么要求吗?2020-06-08
00:39
人力资源管理师考试都有哪些题型?2020-06-08
00:51
人力资源管理师考试的通过率高吗?2020-06-08
00:32
人力资源管理师考试的鉴定方式分为哪几种?2020-06-08
00:30
人力资源管理师考试成绩有多久的有效期?2020-06-08

微信扫码关注公众号
获取更多考试热门资料