C语言学生成绩管理系统(简易版)

 #include<stdio.h>
#include<stdlib.h>
#include<string.h> int readstudents(struct students stu[]); //读取学生信息
int readsexcode(struct sexcode sex[]); //读取性别代码
int readcollegecode(struct collegecode colle[]); //读取学院代码
void transform(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c); //录入
void namesort(struct students stu[],int a); //按照姓名排序
void averagesort(struct students stu[],int a); //平均分排序
void searchcollege(struct students stu[],int a); //按学院搜索学生
void namesearch(struct students stu[],int a); //按名字搜索
void printstudent(struct students stu[],struct sexcode sex[],struct collegecode colle[],int a,int b,int c); //输出
void change(struct students stu[],int a);
int passwordfun();
void passwordchange();
void averagefun(struct students stu[],int a); struct students{
int num;
char name[];
int sexnum;
char sex[];
int collegenum;
char college[];
int score[];
float average;
};
struct sexcode{
int sexnum;
char sex[];
};
struct collegecode{
int collegenum;
char college[];
}; int main()
{
int a,b,c;
int choice;
struct students stu[];
struct sexcode sexy[];
struct collegecode colle[];
int t = passwordfun();
if(t == ){
printf("请使用正确密码重新登陆程序!\n");
return ;
}
while(){
system("cls");
printf("***********学生成绩系统菜单************ \n* 1. 原始文件读取 *\n* 2. 按姓名排序,输出 *\n* 3. 按平均成绩排序,输出 *\n* 4. 输出给定学院学生 *\n* 5. 修改给定学生成绩信息 *\n* 6. 按姓名查询学生,输出 *\n* 7. 修改系统密码 *\n* 0. 返回上一级菜单 *\n***************************************\n");
scanf("%d",&choice);
switch(choice){
case : system("cls");
a = readstudents(stu);
b = readsexcode(sexy);
c = readcollegecode(colle);
transform(stu,sexy,colle,a,b,c);
averagefun(stu,a);
printf("原始文件读取完毕!\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
namesort(stu,a);
printstudent(stu,sexy,colle,a,b,c);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
averagesort(stu,a);
printstudent(stu,sexy,colle,a,b,c);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
searchcollege(stu,a);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
change(stu,a);
printf("修改成功!\n");
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
namesearch(stu,a);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
passwordchange();
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
printf("欢迎使用,下次再见!\n");
system("pause");
exit();
}
}
return ;
}
int readstudents(struct students stu[]) //读取学生信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\Student_Info.txt","r+");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&stu[i].num);
while(!feof(fp)){
fscanf(fp,"%s%d%d",stu[i].name,&stu[i].sexnum,&stu[i].collegenum);
for(int j = ;j < ; j++ ){
fscanf(fp,"%d",&stu[i].score[j]);
}
i++;
fscanf(fp,"%d",&stu[i].num);
}
fclose(fp);
return i;
}
int readsexcode(struct sexcode sexy[]) //读取学生性别信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\S_Info.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&sexy[i].sexnum);
while(!feof(fp)){
fscanf(fp,"%s",sexy[i].sex);
i++;
fscanf(fp,"%d",&sexy[i].sexnum);
}
fclose(fp);
return i;
}
int readcollegecode(struct collegecode colle[]) //读取学生学院信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\C_Info.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&colle[i].collegenum);
while(!feof(fp)){
fscanf(fp,"%s",colle[i].college);
i++;
fscanf(fp,"%d",&colle[i].collegenum);
}
fclose(fp);
return i;
}
void averagefun(struct students stu[],int a) //平均分
{
for(int i = ; i < a; i++){
int sum = ;
for(int j = ; j < ; j++){
sum = sum + stu[i].score[j];
}
stu[i].average = 1.0 * sum / ;
}
return ;
}
void namesort(struct students stu[],int a) //按姓名排序
{
for(int i = ; i < a-; i++){
for(int j = i+; j < a ; j++){
if(strcmp(stu[i].name,stu[j].name) < ){
struct students temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
return ;
}
void averagesort(struct students stu[],int a) // 按平均分排序
{
for(int i = ; i < a-; i++){
for(int j = i+; j < a ; j++){
if(stu[i].average < stu[j].average){
struct students temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
return ;
}
void printstudent(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c) //输出信息
{
for(int i = ;i < a; i++){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < c; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
return ;
}
void transform(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c) //修改信息
{
for(int i = ; i < a; i++){
for(int j = ; j < b; j++){
if(stu[i].sexnum == sexy[j].sexnum){
strcpy(stu[i].sex,sexy[j].sex);
break;
}
}
for(int j = ; j < c; j++){
if(stu[i].collegenum == (colle[j].collegenum - )){
strcpy(stu[i].college,colle[j].college);
break;
}
}
}
} void searchcollege(struct students stu[],int a) //查找学院并输出
{
char collegename[];
printf("请输入需要查找的学院的名称:\n") ;
scanf("%s",collegename);
for(int i = ;i < a; i++){
if(strcmp(stu[i].college,collegename) == ){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < ; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
}
return ;
}
void namesearch(struct students stu[],int a) //按姓名查找
{
printf("请输入需要查找的学生的姓名:\n");
char name[];
scanf("%s",name);
for(int i = ;i < a; i++){
if(strcmp(stu[i].name,name) == ){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < ; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
}
return ;
}
void change(struct students stu[],int a) //按名字搜索修改分数
{
char name[];
printf("请输入需要修改成绩的学生的姓名:\n");
scanf("%s",name);
printf("请输入改学生各科成绩,不需要修改的按原样输入:\n");
for(int i = ;i < a; i++){
if(strcmp(stu[i].name,name) == ){
for(int j = ; j <= ; j++){
printf("第%d门成绩: ",j);
scanf("%d",&stu[i].score[j-]);
printf("\n");
}
}
}
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\Student_Info.txt","w");
if(fp == ){
printf("can not open this file\n");
exit ();
}
while(i<){
fprintf(fp,"%d %s %d %d",stu[i].num,stu[i].name,stu[i].sexnum,stu[i].collegenum);
for(int j = ;j < ; j++ ){
fprintf(fp," %d",stu[i].score[j]);
if(j == ){
fprintf(fp,"\n");
}
}
i++;
}
fclose(fp);
return ;
}
int passwordfun() //密码
{
char password_1[],password_2[],password_3[];
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\password.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%s",password_2);
fclose(fp);
if(password_2[i] == '\0'){ //当检测到密码文本为空时
printf("欢迎使用学生成绩管理系统!\n首次使用系统,您可以直接进入主菜单,进入主菜单后请及时修改密码!\n");
system("pause");
return ;
}
else
{
printf("请输入系统密码:\n"); //保存输入的密码
char s[];
int t,n_,x;
for(x=;x<;x++){
s[x]=getch();
if(s[x]=='\r') break;
printf("*");
}
s[x]='\0';
for(t=;t<;t++){ //将输入的密码存放在password_1中
password_1[t]=s[t];
}
for(i = ; password_2[i] != '\0'; i++){
if(password_2[i] <= && password_2[i] >= ){ //password_2为真实密码
password_3[i] = password_2[i] - ; //密码密文加密(+3)
}else{
password_3[i] = - password_3[i];
} //password_3为按算法处理后的真实密码
}
password_3[i] = '\0';
if(strcmp(password_1,password_3) == ){
return ;
}else{
printf("密码错误!\n程序结束!请使用正确密码重新登入程序!\n");
system("pause");
return ;
}
}
}
void passwordchange() //密码修改
{
FILE *fp;
char newpassword_1[];
char newpassword_2[];
int i = ;
printf("请输入新的密码:\n");
scanf("%s",newpassword_1);
for(i = ; newpassword_1[i] != '\0'; i++){
if(newpassword_1[i] + <= ){
newpassword_2[i] = newpassword_1[i] + ;
}else{
newpassword_2[i] = newpassword_1[i] + -;
}
}
newpassword_2[i] = '\0';
fp = fopen("D:\\abc\\password.txt","w");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fprintf(fp,"%s",newpassword_2);
fclose(fp);
printf("密码修改成功!\n");
return ;
}
上一篇:解决ViewPage中嵌套有ListView或者滑动手势等造成滑动的冲突


下一篇:ASP中Utf-8与Gb2312编码转换乱码问题的解决方法 页面编码声明