C 语言

关注公众号 jb51net

关闭
首页 > 软件编程 > C 语言 > C语言学生信息管理系统

C语言实现学生信息管理系统(文件版)

作者:CM666_

这篇文章主要为大家详细介绍了C语言实现学生信息管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C语言实现学生信息管理系统的具体代码,供大家参考,具体内容如下

下面是我自己用写的学生信息管理系统,为了增加数据的利用率,分为学生端和教师端,同时实现账号密码登录,以文件的形式将其存入。

代码如下

#include <stdio.h>
#include <string.h> 
#include <string>
#include<Windows.h>
#define USER "TOM"  // 事先定义用户名,用于登录页面,验证身份。 
#define PW "123456789" // 事先定义密码 ,作用同上。
void Level_menu();//主菜单的声明--选择学生端还是老师端。
void Level_2_menu(); //二级菜单——具体功能分化 
void Student_add_Level_3_menu();// 增添学生信息菜单功能分化 
void Student_Insert(); //添加单个学生信息 
void Student_Insert1(); /*为上面批量输入设置的函数,其代码与上面的
         单个输入相似,删减了一部分*/

void Student_Tongji_menu();//统计菜单部分
void Student_Tongji_menu2();//统计二级菜单 
void Student_Tongji_menu3();//统计 
void IO_ReadInfo();/*将学生信息从文件(student database.txt)中读出*/ 
void IO_WriteInfo();/*将学生信息写入文件(Database.txt)*/ 
void student_Delete_menu(); /*删除学生信息菜单*/
void student_menu1();/*学生查询课程信息菜单*/
void student_Kecheng_menu2();
void Student_From_high_to_low1(); /*按综合测评从高到低排序*/ 
void jiangxue_menu();/*奖学金评定办法*/ 
void Student_Display2();/*显示学生信息2在奖学金评定时使用*/


 
 
/*定义学生结构体*/ 
struct Student 
{
  char ID[20];  //学号
  char Name[20];  //姓名 
  char sushe[6];  //宿舍房间号 
 float mathA1;  //高等数学成绩 
 float EnglishA1; //大学英语成绩 
 float software;  //软件技术导论
 float china_history;//中国近代史纲要
 float junshi;  //军事教育
 float xinli;  //心理健康辅导
 float sports;  //体育*/ 
  float C_Mark;  //C语言程学设计成绩
  float pingjun;  //总学分
 float Banzhuren; //班主任评分
 float Cepingfen; //测评分 
};

/*声明学生数组及学生数量*/ 
struct Student students[1000]; 
int num=0;
int Num; 

/*通过学号返回数组下标*/ 
int Student_SearchByIndex(char id[]) 
{
 int i; 
 for (i=0;i<num;i++) 
 {
  if (strcmp(students[i].ID,id)==0) 
  {
   return i; 
  } 
 } 
 return -1; 
}

/*通过姓名返回数组下标*/
int Student_SearchByName(char name[]) 
{
 int i; 
 for (i=0;i<num;i++) 
 { 
  if (strcmp(students[i].Name,name)==0)
  { 
   return i;
  } 
 } 
 return -1; 
} 

/*通过宿舍成员返回数组下标*/
void Student_SearchBySushe()

{
 system("cls");
 system("color f0");
 int i;
 char Sushe[6] ;
 printf("请输入你想要查询的宿舍房间号: ");
 scanf("%s",&Sushe); 
 printf("%10s%10s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号","高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","总学分","班主任评分","测评分"); 
 printf("------------------------------------------------------------------------------------------------------------------------\n"); 
 
 
  
 for (i=0;i<num;i++) 
 { 
  if (strcmp(students[i].sushe,Sushe)==0)
  { 
   printf("%10s%10s%5s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[i].ID,students[i].Name,students[i].sushe,students[i].mathA1,students[i].EnglishA1,students[i].software,students[i].china_history,students[i].junshi,students[i].xinli,students[i].sports,students[i].C_Mark,students[i].pingjun,students[i].Banzhuren,students[i].Cepingfen); 
  }
  
 } 
 
 printf("数据加载完毕!"); 
 Student_Tongji_menu2();
 
} 

/*显示单条学生记录*/ 
void Student_DisplaySingle(int index) 
{
 printf("%10s%10s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号","高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分"); 
 printf("------------------------------------------------------------------------------------------------------------------------\n"); 
 printf("%10s%10s%5s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[index].ID,students[index].Name,students[index].sushe,students[index].mathA1,students[index].EnglishA1,students[index].software,students[index].china_history,students[index].junshi,students[index].xinli,students[index].sports,students[index].C_Mark,students[index].pingjun); 
} 

/*增加单条学生记录*/ 
void Student_Insert() 
{ 
 system("cls");
 system("color f0");
 float a1,a2,a3,a4,a5,a6,a7,a8;
 float j=0; 
 while(1) 
 { 
  printf("请输入学号:");
  scanf("%s",&students[num].ID); 
  getchar();
  printf("请输入姓名:"); 
  scanf("%s",&students[num].Name); 
  getchar();
 printf("请输入宿舍号:"); 
  scanf("%s",&students[num].sushe); 
  getchar();
 printf("请输入高等数学成绩:"); 
  scanf("%f",&students[num].mathA1); 
  getchar();
  if (59<students[num].mathA1 && students[num].mathA1<100) 
  
   a8= 1.5;  
  
  else
  
   a8=0;
 

 printf("请输入大学英语成绩:"); 
  scanf("%f",&students[num].EnglishA1); 
  getchar();
  if (59<students[num].EnglishA1 && students[num].EnglishA1<100) 
  
   a1= 2;  
  
   else
  
   a1=0;
 

 printf("请输入软件技术导论成绩:"); 
  scanf("%f",&students[num].software); 
  getchar();
  if (59<students[num].software && students[num].software<100) 
  
   a2= 1.5;  
  
   else
  
   a2=0;
 

 printf("请输入中国近代史纲要成绩:"); 
  scanf("%f",&students[num].china_history); 
  getchar();
  if (59<students[num].china_history && students[num].china_history<100) 
  
   a3= 2.5;  
  
   else
  
   a3=0;
 

 printf("请输入军事教育:"); 
  scanf("%f",&students[num].junshi); 
  getchar();
  if (59<students[num].junshi && students[num].junshi<100) 
  
   a4= 2;  
  
   else
  {
   a4=0;
 }

 printf("请输入心理健康教育成绩:"); 
  scanf("%f",&students[num].xinli); 
  getchar();
  if (59<students[num].xinli && students[num].xinli<100) 
  
   a5= 1.5;  
  
   else
  
   a5=0;
 
 printf("请输入体育成绩:"); 
  scanf("%f",&students[num].sports); 
  getchar();
  if (59<students[num].sports && students[num].sports<100) 
  
   a6= 2;  
  
   else
  
   a6=0;
 

 printf("请输入C语言成绩:"); 
  scanf("%f",&students[num].C_Mark); 
  getchar();
  if (59<students[num].C_Mark && students[num].C_Mark<100) 
  
   a7= 3.5;  
  
   else
  
   a7=0;
 
  
  printf("请输入班主任评分:"); 
  scanf("%f",&students[num].Banzhuren); 
  getchar();
  students[num].pingjun=a1+a2+a3+a4+a5+a6+a7+a8; //总学分 
  
  j=(students[num].pingjun*0.4)+(students[num].Banzhuren*0.6);
  students[num].Cepingfen=j;
  num++;

  printf("是否继续?(Y/N),继续请按任意键,否则输入N:"); 
  if (getchar()=='N') 
  { 
   Num=num;
   break;
  } 
  } 
}  

 
 /*批量添加学生记录*/ 
void Student_many1()
{
 { 
  system("cls");
  system("color f0");
  int i,j;
  printf("请输入你将要添加的人员数: ");
  scanf("%d",&j); 
 for(i=0;i<j;i++)
 {
 Student_Insert1();
 }
 printf("成员添加完毕,是否跳转至上一级菜单?\n");
 printf("是?,请按任意键,确认输入: \n"); 
  if (getchar()=='Y') 
  { 
   Student_add_Level_3_menu(); 
  } 
  
 }
 } 
/*为上面批量输入设置的函数,其代码与上面的
单个输入相似,删减了一部分*/ 
void Student_Insert1() 
{ 
 
 {
  printf("请输入学号:"); 
  scanf("%s",&students[num].ID); 
  getchar(); 
  printf("请输入姓名:"); 
  scanf("%s",&students[num].Name); 
  getchar();
 printf("请输入宿舍号:"); 
  scanf("%s",&students[num].sushe); 
  getchar();
 printf("请输入高等数学成绩:"); 
  scanf("%f",&students[num].mathA1); 
  getchar();
 printf("请输入大学英语成绩:"); 
  scanf("%f",&students[num].EnglishA1); 
  getchar();
 printf("请输入软件技术导论成绩:"); 
  scanf("%f",&students[num].software); 
  getchar();
 printf("请输入中国近代史纲要成绩:"); 
  scanf("%f",&students[num].china_history); 
  getchar();
 printf("请输入军事教育:"); 
  scanf("%f",&students[num].junshi); 
  getchar();
 printf("请输入心理健康教育成绩:"); 
  scanf("%f",&students[num].xinli); 
  getchar();
 printf("请输入体育成绩:"); 
  scanf("%f",&students[num].sports); 
  getchar();
 printf("请输入C语言成绩:"); 
  scanf("%f",&students[num].C_Mark); 
  getchar();
  printf("请输入班主任评分:"); 
  scanf("%f",&students[num].Banzhuren); 
  getchar();
  if (54<students[num].C_Mark && students[num].C_Mark< 60) //把55~59分之间的成绩都加上5分
  {
   students[num].C_Mark += 5;  
  }

  num++;
  } 
} 
/*修改学生信息*/ 
void Student_Modify() 
{ 
 system("cls");
 system("color f0");
 float a1,a2,a3,a4,a5,a6,a7,a8;
 float j=0; 
 while(1) 
 { 
  char id[20]; 
  int index; 
  printf("请输入要修改的学生的学号:"); 
  scanf("%s",&id); 
  getchar(); 
  index=Student_SearchByIndex(id); 
  if (index==-1) 
  { 
   printf("该学生不存在!\n"); 
   }
  else 
  { 
   printf("你要修改的学生信息为:\n"); 
   Student_DisplaySingle(index); 
   printf("-- 请输入新值--\n"); 
   /*printf("请输入学号:"); 
   scanf("%s",&students[index].ID); 
   getchar(); 
   printf("请输入姓名:"); 
   scanf("%s",&students[index].Name); 
   getchar(); 
 printf("请输入宿舍号:"); 
   scanf("%s",&students[index].sushe); 
   getchar();
  printf("请输入高等数学成绩:"); 
   scanf("%f",&students[index].mathA1); 
   getchar();
  printf("请输入大学英语成绩:"); 
   scanf("%f",&students[index].EnglishA1); 
   getchar();
  printf("请输入软件技术导论成绩:"); 
   scanf("%f",&students[index].software); 
   getchar();
  printf("请输入中国近代史纲要成绩:"); 
   scanf("%f",&students[index].china_history); 
   getchar();
  printf("请输入军事教育:"); 
   scanf("%f",&students[index].junshi); 
   getchar();
  printf("请输入心理健康教育成绩:"); 
   scanf("%f",&students[index].xinli); 
   getchar();
  printf("请输入体育成绩:"); 
   scanf("%f",&students[index].sports); 
   getchar();
   printf("请输入C语言成绩:"); 
   scanf("%f",&students[index].C_Mark); 
   getchar();
 printf("请输入班主任评分:"); 
   scanf("%f",&students[num].Banzhuren); 
   getchar();*/
 printf("请输入学号:");
  scanf("%s",&students[index].ID); 
  getchar();
  printf("请输入姓名:"); 
  scanf("%s",&students[index].Name); 
  getchar();
 printf("请输入宿舍号:"); 
  scanf("%s",&students[index].sushe); 
  getchar();
 printf("请输入高等数学成绩:"); 
  scanf("%f",&students[index].mathA1); 
  getchar();
  if (59<students[index].mathA1 && students[index].mathA1<100) 
  
   a8= 1.5;  
  
  else
  
   a8=0;
 

 printf("请输入大学英语成绩:"); 
  scanf("%f",&students[index].EnglishA1); 
  getchar();
  if (59<students[index].EnglishA1 && students[index].EnglishA1<100) 
  
   a1= 2;  
  
   else
  
   a1=0;
 

 printf("请输入软件技术导论成绩:"); 
  scanf("%f",&students[index].software); 
  getchar();
  if (59<students[index].software && students[index].software<100) 
  
   a2= 1.5;  
  
   else
  
   a2=0;
 

 printf("请输入中国近代史纲要成绩:"); 
  scanf("%f",&students[index].china_history); 
  getchar();
  if (59<students[index].china_history && students[index].china_history<100) 
  
   a3= 2.5;  
  
   else
  
   a3=0;
 

 printf("请输入军事教育:"); 
  scanf("%f",&students[index].junshi); 
  getchar();
  if (59<students[index].junshi && students[index].junshi<100) 
  
   a4= 2;  
  
   else
  {
   a4=0;
 }

 printf("请输入心理健康教育成绩:"); 
  scanf("%f",&students[index].xinli); 
  getchar();
  if (59<students[index].xinli && students[index].xinli<100) 
  
   a5= 1.5;  
  
   else
  
   a5=0;
 
 printf("请输入体育成绩:"); 
  scanf("%f",&students[index].sports); 
  getchar();
  if (59<students[index].sports && students[index].sports<100) 
  
   a6= 2;  
  
   else
  
   a6=0;
 

 printf("请输入C语言成绩:"); 
  scanf("%f",&students[index].C_Mark); 
  getchar();
  if (59<students[index].C_Mark && students[index].C_Mark<100) 
  
   a7= 3.5;  
  
   else
  
   a7=0;
 
  
  printf("请输入班主任评分:"); 
  scanf("%f",&students[index].Banzhuren); 
  getchar();
  students[index].pingjun=a1+a2+a3+a4+a5+a6+a7+a8; //总学分 
  
  j=(students[index].pingjun*0.4)+(students[index].Banzhuren*0.6);
  students[index].Cepingfen=j; 

   } 

   printf("是否继续?(Y/N),继续请按任意键,否则输入N:"); 
   if (getchar()=='N') 
   { 
   break;
   } 

  } 

} 

/*按学号删除学生信息*/ 
void Student_Delete() 
{ 
 system("cls");
 system("color f0");
 IO_ReadInfo();
 int i; 
 while(1) 
 { 
  char id[20]; 
  int index; 
  printf("请输入要删除的学生的学号:"); 
  scanf("%s",&id); 
  getchar(); 
  index=Student_SearchByIndex(id); 
  if (index==-1) 
  { 
   printf("学生不存在!\n"); 
  } 
  else 
  { 
   printf("你要删除的学生信息为:\n"); 
   Student_DisplaySingle(index); 
   printf("%d",index);
   printf("%d",num);
   { 
    for (i=index;i<num-1;i++) 
    { 
     students[i]=students[i+1];  //把后边的对象都向前移动 
    }
  
    num--; 
    } 
   printf("已删除\n");
 
    IO_WriteInfo(); 
   } 

   printf("是否继续删除?(Y/N),继续请按任意键,否则输入N:"); 
   if (getchar()=='N') 
   { 
   break;
   } 
  } 
} 

/*按姓名删除学生信息*/ 
void Student_Delete_1() 
{ 
 system("cls");
 system("color f0");
 IO_ReadInfo();
 int i; 
 while(1) 
 { 
  char name[20]; 
  int index; 
  printf("请输入要删除的学生的姓名: "); 
  scanf("%s",&name); 
  getchar(); 
  index=Student_SearchByName(name); 
  if (index==-1) 
  { 
   printf("学生不存在!\n"); 
  } 
  else 
  { 
   printf("你要删除的学生信息为:\n"); 
   Student_DisplaySingle(index); 
   { 
    for (i=index;i<num-1;i++) 
    { 
     students[i]=students[i+1];  //把后边的对象都向前移动 
    }
  
    num--; 
    } 
   printf("已删除\n");
 
    IO_WriteInfo(); 
   } 

   printf("是否继续删除?(Y/N),继续请按任意键,否则输入N:"); 
   if (getchar()=='N') 
   { 
   break;
   } 
  } 
} 


/*按姓名查询*/ 
void Student_Select_1() 
{ 
 while(1) 
 { 
  char name[20]; 
  int index; 

  printf("请输入要查询的学生的姓名:"); 
  scanf("%s",&name); 
  getchar(); 
  index=Student_SearchByName(name); 

  if (index==-1) 
  { 
   printf("学生不存在!\n"); 
  } 
  else 
  { 
   printf("你要查询的学生信息为:\n"); 
   Student_DisplaySingle(index); 
  } 

  printf("是否继续?(Y/N),继续请按任意键,否则输入N:"); 
  if (getchar()=='N') 
  { 
   break;
  } 

  }
} 
/*按学号查找*/
void Student_Select_2() 
{
 while(1)
 {
  char ID[20];
  int index;
 
  system("cls");
  system("color f0"); 
  printf("请输入要查询的学生的学号:"); 
  scanf("%s",&ID);
 getchar();
 index=Student_SearchByIndex(ID);
 
  if (index==-1) 
  { 
   printf("学生不存在!\n"); 
  } 
  else 
  { 
   printf("你要查询的学生信息为:\n"); 
   Student_DisplaySingle(index); 
  } 

  printf("是否继续?(Y/N),继续请按任意键,否则输入N:"); 
  if (getchar()=='N') 
  { 
   break;
  } 

  }
 
}

void Student_Search_menu()
{
  int choice;
   while(1) 
 {
 system("cls");
  system("color f0");
 printf("\t\t\t\t\t\t1. 按姓名查询学生记录\n"); 
   printf("\t\t\t\t\t\t2. 按学号查询学生记录\n");
   printf("\t\t\t\t\t\t3. 返回上一级菜单\n");
 printf("\t\t\t\t\t\t4. 返回主菜单\n");
 printf("\t\t\t\t\t\t请选择(1-4):");
 scanf("%d",&choice); 
   getchar();
 switch(choice)
 {
  case 1:Student_Select_1();
   break;
  
  case 2:Student_Select_2();
   break;
   
  case 3:Level_2_menu();
   break;
   
 case 4:Level_menu(); 
     break;
     
 } 
 } 
   
   
}

/*按C语言成绩从高到低排序*/ 
void Student_From_high_to_low() 
{ 
 int i,j; 
 struct Student tmp; 

 for (i=0;i<num;i++) 
 { 
  for (j=1;j<num-i;j++) 
  { 
   if (students[j-1].C_Mark<students[j].C_Mark) 
   { 
    tmp=students[j-1]; 
    students[j-1]=students[j]; 
    students[j]=tmp; 
   } 
  } 
 } 
} 

/*按C语言成绩从低到高排序*/ 
void Student_From_low_to_high()
{
  int i,j; 
 struct Student tmp; 

 for (i=0;i<num;i++) 
 { 
  for (j=1;j<num-i;j++) 
  { 
   if (students[j-1].C_Mark>students[j].C_Mark) 
   { 
    tmp=students[j-1]; 
    students[j-1]=students[j]; 
    students[j]=tmp; 
   } 
  } 
 } 
 
} 


/*按综合测评从高到低排序*/ 
void Student_From_high_to_low1() 
{ 
 int i,j,k; 
 struct Student tmp; 

 for (i=0;i<num;i++) 
 { 
  for (j=1;j<num-i;j++) 
  { 
   if (students[j-1].Cepingfen<students[j].Cepingfen) 
   { 
    tmp=students[j-1]; 
    students[j-1]=students[j]; 
    students[j]=tmp; 
   } 
  } 
 }
 
 /*system("cls");
 system("color f0");
 while(1) 
 { 
 int k; 
 printf("%10s%10s %8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号"," 高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分","班主任评分","测评分"); 
 printf("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); 
 for (k=0;k<num;k++) 
 { 
 if(59<students[k].mathA1&&students[k].mathA1<101&&59<students[k].EnglishA1&&students[k].EnglishA1<101&&59<students[k].software&&students[k].software<101&&59<students[k].china_history&&students[k].china_history<101&&59<students[k].junshi&&students[k].junshi<101&&59<students[k].xinli&&students[k].xinli<101&&59<students[k].sports&&students[k].sports<101&&59<students[k].C_Mark&&students[k].C_Mark<101); 
  {
 printf("%10s%10s %8s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[k].ID,students[k].Name,students[k].sushe,students[k].mathA1,students[k].EnglishA1,students[k].software,students[k].china_history,students[k].junshi,students[k].xinli,students[k].sports,students[k].C_Mark,students[k].pingjun,students[k].Banzhuren,students[k].Cepingfen); 
  }
 }
  printf("数据加载完毕!");
 jiangxue_menu(); 
  Student_Tongji_menu3();
  
 } */
}


/*奖学金评定办法*/
void jiangxue_menu()
{
 float i=0,j=0,k=0;
 int a,b,c;
 i=num*0.1;
 j=num*0.15;
 k=num*0.2;
 a=(int)i;
 b=(int)j;
 c=(int)k;
 printf("一等奖获得人数为:%d\n",a);
 printf("二等奖获奖人数为:%d\n",b);
 printf("三等奖获奖人数为:%d\n",c);
 
 
 
 
}
//对奖学金及格的人员筛选出来 
void jiangxue()
{
 system("cls");
 system("color f0");
 while(1) 
 { 
 int k; 
 printf("%10s%10s %8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号"," 高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分","班主任评分","测评分"); 
 printf("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); 
 for (k=0;k<num;k++) 
 { 
 if(59<students[k].mathA1&&students[k].mathA1<101&&59<students[k].EnglishA1&&students[k].EnglishA1<101&&59<students[k].software&&students[k].software<101&&59<students[k].china_history&&students[k].china_history<101&&59<students[k].junshi&&students[k].junshi<101&&59<students[k].xinli&&students[k].xinli<101&&59<students[k].sports&&students[k].sports<101&&59<students[k].C_Mark&&students[k].C_Mark<101); 
  {
 printf("%10s%10s %8s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[k].ID,students[k].Name,students[k].sushe,students[k].mathA1,students[k].EnglishA1,students[k].software,students[k].china_history,students[k].junshi,students[k].xinli,students[k].sports,students[k].C_Mark,students[k].pingjun,students[k].Banzhuren,students[k].Cepingfen); 
  }
 }
  printf("数据加载完毕!");
 jiangxue_menu(); 
  Student_Tongji_menu3();
  
 }
}

/*显示学生信息*/ 
void Student_Display() 
{ 

 system("cls");
 system("color f0");
 while(1) 
 { 
 int i; 
 printf("%10s%10s %8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号"," 高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分"); 
 printf("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); 
 for (i=0;i<num;i++) 
 { 
 printf("%10s%10s %8s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[i].ID,students[i].Name,students[i].sushe,students[i].mathA1,students[i].EnglishA1,students[i].software,students[i].china_history,students[i].junshi,students[i].xinli,students[i].sports,students[i].C_Mark,students[i].pingjun); 
 }
  printf("是否继续?(Y/N),继续请按任意键,否则输入N:"); 
  if (getchar()=='N') 
  { 
   break;
  } 
 }
  
} 

/*显示学生信息1*/ 
void Student_Display1() 
{ 

 system("cls");
 system("color f0");
 while(1) 
 { 
 int i; 
 printf("%10s%10s %8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号"," 高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分","班主任评分","测评分"); 
 printf("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); 
 for (i=0;i<num;i++) 
 { 
 printf("%10s%10s %8s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[i].ID,students[i].Name,students[i].sushe,students[i].mathA1,students[i].EnglishA1,students[i].software,students[i].china_history,students[i].junshi,students[i].xinli,students[i].sports,students[i].C_Mark,students[i].pingjun,students[i].Banzhuren,students[i].Cepingfen); 
 }
  printf("数据加载完毕!"); 
  Student_Tongji_menu3();
  
 }
  
} 

/*显示学生信息2在奖学金评定时使用*/ 
void Student_Display2() 
{ 

 system("cls");
 system("color f0");
 while(1) 
 { 
 int i; 
 printf("%10s%10s %8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s%8s\n","学号","姓名","宿舍号"," 高等数学","大学英语","软件技术导论","中国近代史","军事教育","心理健康教育","大学体育","C语言成绩","品行分","班主任评分","测评分"); 
 printf("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); 
 for (i=0;i<num;i++) 
 { 
 printf("%10s%10s %8s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",students[i].ID,students[i].Name,students[i].sushe,students[i].mathA1,students[i].EnglishA1,students[i].software,students[i].china_history,students[i].junshi,students[i].xinli,students[i].sports,students[i].C_Mark,students[i].pingjun,students[i].Banzhuren,students[i].Cepingfen); 
 }
  printf("数据加载完毕!");
 jiangxue_menu(); 
  Student_Tongji_menu3();
  
 }
  
} 
/*将学生信息从文件(student database.txt)中读出*/ 
void IO_ReadInfo() 
{ 
 FILE *fp; 
 int i; 

 if ((fp=fopen("student database.txt","rb"))==NULL) 
 { 
  printf("不能打开文件!\n"); 
  return; 
 }

 if (fread(&num,sizeof(int),1,fp)!=1) 
 { 
  num=-1; 
 } 
 else 
 { 
  for(i=0;i<num;i++) 
  { 
   fread(&students[i],sizeof(struct Student),1,fp); 
  } 
 } 

 fclose(fp); 
} 

/*将学生信息写入文件(Database.txt)*/ 
void IO_WriteInfo()
{ 
 FILE *fp; 
 int i; 
 if ((fp=fopen("student database.txt","wb"))==NULL) 
 { 
  printf("不能打开文件!\n"); 
  return; 
 } 
 if (fwrite(&num,sizeof(int),1,fp)!=1) 
 { 
  printf("写入文件错误!\n"); 
 } 
 for (i=0;i<num;i++) 
 { 
  if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1) 
  { 
   printf("写入文件错误!\n"); 
  } 
 } 
 fclose(fp); 
}
 /*一级菜单*/ 
 /*账号密码登录*/
void Level_1_menu( )
{ char account[20];
 char password[30];
 int i = 0;
 int j = 3;
 for (; i < 3; i++){
  printf("\n\n\n\n\t\t\t\t\t\t  *主菜单*\n");
 printf("\t\t\t\t\t\t******************\n");
 printf("\t\t\t\t\t\t*请输入您的账号:*\n");
 printf("\t\t\t\t\t\t******************\n");
 printf("            请输入:"); 
 scanf ("%s", account);
 printf("\t\t\t\t\t\t******************\n");
 //scanf ("%s", account);
 printf("\t\t\t\t\t\t******************\n");
 printf("\t\t\t\t\t\t*请输入您的密码:*\n"); 
 printf("\t\t\t\t\t\t******************\n");
 printf("            请输入:"); 
 scanf ("%s", password);
 if (strcmp(USER, account) == 0 && strcmp(PW, password) == 0){
 printf("登录成功!\n");
 break;
 }
 else{
 j--;
 printf("登录失败您还有%d次机会!\n", j);
 }
 }
 if (i == 3){
 printf("登录失败,退出!");
 }
 //system("pause");
 system("cls");
 system("color f0"); 
}
/*增加学生信息三级菜单模块*/ 
 
void Student_add_Level_3_menu()
 {
  int choice;
   while(1) 
 {
 system("cls");
  system("color f0");
  IO_ReadInfo();  //读取文件 
 printf("\t\t\t\t\t\t1. 单个添加学生信息\n"); 
   printf("\t\t\t\t\t\t2. 批量添加学生信息\n");
   printf("\t\t\t\t\t\t3. 返回上一级菜单\n");
 printf("\t\t\t\t\t\t4. 返回主菜单\n");
 printf("\t\t\t\t\t\t请选择(1-4):");
 scanf("%d",&choice); 
   getchar();
 switch(choice)
 {
  case 1:Student_Insert();
   IO_WriteInfo();  //写入文件 
   break;
  
  case 2:Student_many1();
   IO_WriteInfo();  //写入文件
   break;
   
  case 3:Level_2_menu();
   break;
   
 case 4:Level_menu(); 
     break;
     
 }
 IO_WriteInfo();  //写入文件 
 } 
   //Student_Insert(); 
   
 }

  /*二级菜单*/ 
  /*主菜单*/
void Level_2_menu( )
{
int choice;
 while(1) 
 { 
  /*二级菜单*/ 
  /*主菜单*/
 system("cls");
  system("color f0");
 IO_ReadInfo();  //读取文件 
  printf("\n\t\t\t\t\t\t------ 学生成绩管理系统------\n"); 
  printf("\t\t\t\t\t\t1. 增加学生记录\n"); 
  printf("\t\t\t\t\t\t2. 修改学生记录\n"); 
  printf("\t\t\t\t\t\t3. 删除学生记录\n");
 printf("\t\t\t\t\t\t4. 查询学生记录\n"); 
  printf("\t\t\t\t\t\t5. 统计学生记录\n"); 
  printf("\t\t\t\t\t\t6. 退出\n"); 
  printf("\t\t\t\t\t\t请选择(1-6):"); 

  scanf("%d",&choice); 
  getchar(); 

  switch(choice) 
  { 
  case 1:
   Student_add_Level_3_menu();
   break; 

  case 2: 
   Student_Modify(); 
   break; 

  case 3: 
   student_Delete_menu(); 
   break; 

  case 4: 
   Student_Search_menu();
   break; 

  case 5:
  Student_Tongji_menu();
 break; 
 
  case 6: 
   Level_menu(); 
   break;

  }
 IO_WriteInfo(); 
 } 
}

/*学生端成绩查询模块*/
void student_Delete_menu()
{
 int choice; 
 while(1)
 {
 system("cls");
  system("color f0");
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t************************\n");  
  printf("\t\t\t\t\t\t* 删除学生信息菜单******\n");
 printf("\t\t\t\t\t\t************************\n");
  printf("\t\t\t\t\t\t*1、按姓名删除信息  *\n");
 printf("\t\t\t\t\t\t*2、按学号删除信息  *\n");
 printf("\t\t\t\t\t\t*3、返回上一级功能菜单 *\n");
 printf("\t\t\t\t\t\t*4、返回主菜单   *\n");
 printf("\t\t\t\t\t\t************************\n");
 printf("\t\t\t\t\t\t************************\n"); 
 printf("            请选择(1-4):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1:
  system("cls");
   system("color f0");
    Student_Delete_1();
    break;
  case 2:
   system("cls");
   system("color f0");
   Student_Delete(); 
   break;
  case 3:
    Level_2_menu(); 
    break;
    
  case 4:
    Level_menu(); 
    break;  
  }
  
 IO_WriteInfo(); 
 } 
 }
 

/*学生端成绩查询模块*/
void student_menu()
{
 int choice; 
 while(1)
 {
 system("cls");
  system("color f0");
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t*******************\n");  
  printf("\t\t\t\t\t\t*  学生菜单 *\n");
 printf("\t\t\t\t\t\t*******************\n");
  printf("\t\t\t\t\t\t*1、按姓名查询成绩*\n");
 printf("\t\t\t\t\t\t*2、按学号查询成绩*\n");
 printf("\t\t\t\t\t\t*3、查询课程信息 *\n");
 printf("\t\t\t\t\t\t*4、退出   *\n");
 printf("\t\t\t\t\t\t*******************\n");
 printf("\t\t\t\t\t\t*******************\n"); 
 printf("            请选择(1-3):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1:
  system("cls");
   system("color f0");
    Student_Select_1();
    break;
  case 2:
   Student_Select_2();
   break;
   
  case 3:
    student_menu1();
  break; 
   
  case 4:
    Level_menu(); 
    break;
  }
  
 IO_WriteInfo(); 
 } 
 }

 

void student_Kecheng_menu1()
{ printf("\n\n\n\n\t\t\t\t\t\t************************************************\n");
 printf("\t\t\t\t\t\t* 课程代号  课程名称  学分 必修/选修*\n");
 printf("\t\t\t\t\t\t*B27020100 中国近现代史纲要 2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B10060111 大学英语A1   4.0  必修 *\n");
 printf("\t\t\t\t\t\t*B14010101 大学体育1   2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B06010111 高等数学A1   5.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08050101 软件技术导论  2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08010100 C语言程序设计  5.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08010201 C语言程序设计实训1 2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08056601 创新与指导实践1 1.0  必修 *\n");
 printf("\t\t\t\t\t\t*B21991100 军事教育   2.0  选修 *\n");
 printf("\t\t\t\t\t\t**************************************************\n");
 printf("\t\t\t\t\t\t**************************************************\n");
 printf("\t\t\t\t\t\t1. 返回上一级菜单\n");
 printf("\t\t\t\t\t\t2. 返回主菜单\n");
 printf("\t\t\t\t\t\t请选择(1-2):");
  int choice;
 scanf("%d",&choice);
 while(1) 
   
 switch(choice)
 
 {
 
   
  case 1:student_menu1();
   break;
   
 case 2:Level_menu(); 
     break;
     
 }
  //写入文件
}

void student_Kecheng_menu2()
{ printf("\n\n\n\n\t\t\t\t\t\t************************************************\n");
 printf("\t\t\t\t\t\t* 课程代号  课程名称  学分 必修/选修*\n");
 printf("\t\t\t\t\t\t*B27010100 思想道德修养  3.0  必修 *\n");
 printf("\t\t\t\t\t\t*B10060112 大学英语A2   4.0  必修 *\n");
 printf("\t\t\t\t\t\t*B14010102 大学体育2   2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B06010112 高等数学A2   5.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08052200 数字逻辑设计  2.0  必修 *\n");
 printf("\t\t\t\t\t\t*B06050131 大学物理C1   2.5  必修 *\n");
 printf("\t\t\t\t\t\t*B06020100 离散数学   4.0  必修 *\n");
 printf("\t\t\t\t\t\t*B08056601 创新与指导实践2 1.0  必修 *\n");
 printf("\t\t\t\t\t\t*B21991100 C语言程序设计实践2 2.0  选修 *\n");
 printf("\t\t\t\t\t\t**************************************************\n");
 printf("\t\t\t\t\t\t**************************************************\n");
 printf("\t\t\t\t\t\t1. 返回上一级菜单\n");
 printf("\t\t\t\t\t\t2. 返回主菜单\n");
 printf("\t\t\t\t\t\t请选择(1-2):");
  int choice;
 scanf("%d",&choice);
 while(1) 
   
 switch(choice)
 
 {
 
   
  case 1:student_menu1();
   break;
   
 case 2:Level_menu(); 
     break;
     
 }
  //写入文件
}
 
 
/*学生端学生课程查询模块*/
void student_menu1()
{
 int choice; 
 while(1)
 {
 system("cls");
  system("color f0");
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t*******************\n");  
  printf("\t\t\t\t\t\t*  课程信息 *\n");
 printf("\t\t\t\t\t\t*******************\n");
  printf("\t\t\t\t\t\t*1、第一学期  *\n");
 printf("\t\t\t\t\t\t*2、第二学期  *\n");
 printf("\t\t\t\t\t\t*3、第三学期  *\n");
 printf("\t\t\t\t\t\t*4、第四学期  *\n");
 printf("\t\t\t\t\t\t*5、第五学期  *\n");
 printf("\t\t\t\t\t\t*6、第六学期  *\n");
 printf("\t\t\t\t\t\t*7、第七学期  *\n");
 printf("\t\t\t\t\t\t*8、退出   *\n");
 printf("\t\t\t\t\t\t*******************\n");
 printf("\t\t\t\t\t\t*******************\n"); 
 printf("            请选择(1-3):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1:
  system("cls");
   system("color f0");
    student_Kecheng_menu1();
    break;
  case 2:
   system("cls");
   system("color f0");
   student_Kecheng_menu2();
   break;
  case 3:
    
    break;
  case 4:
    
    break;
  case 5:
     
    break;
  case 6:
     
    break;
  case 7:
     
    break;
  case 8:
    Level_menu(); 
    break;
   
  }
  
 IO_WriteInfo(); 
 } 
 }
 
/*统计菜单模块*/
void Student_Tongji_menu()
{
 int choice; 
 while(1)
 {
 system("cls");
  system("color f0");
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t******************************\n");  
  printf("\t\t\t\t\t\t*  学生统计菜单  *\n");
 printf("\t\t\t\t\t\t******************************\n");
  printf("\t\t\t\t\t\t*1、按C语言成绩从高到低排序 *\n");
 printf("\t\t\t\t\t\t*2、按C语言成绩从低到高排序 *\n");
 printf("\t\t\t\t\t\t*3、按宿舍成员进行统计  *\n");
 printf("\t\t\t\t\t\t*4、奖学金评定    *\n"); 
 printf("\t\t\t\t\t\t*5、返回功能菜单    *\n");
 printf("\t\t\t\t\t\t*6、返回主菜单    *\n");
 printf("\t\t\t\t\t\t******************************\n");
 printf("\t\t\t\t\t\t******************************\n"); 
 printf("            请选择(1-5):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1: 
   Student_From_high_to_low();
   Student_Display1();
   break;
    
  case 2:
   Student_From_low_to_high();
  Student_Display1();
  break;
  
 case 3:
   Student_SearchBySushe();
  break;
  
 case 4:
  
   Student_From_high_to_low1();
  Student_Display2(); 
    break;
     
  case 5:
   Level_2_menu( ); 
    break;
    
  case 6:
    Level_menu(); 
    break;
    
  }
  
 IO_WriteInfo(); 
 } 
 }
 
/*统计菜单模块*/
void Student_Tongji_menu2()
{
 int choice; 
 while(1)
 {
 
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t******************************\n");  
  printf("\t\t\t\t\t\t* 你目前在学生宿舍统计页面! *\n");
 printf("\t\t\t\t\t\t******************************\n");
  printf("\t\t\t\t\t\t*1、返回上一级统计菜单  *\n");
 printf("\t\t\t\t\t\t*2、返回功能选择菜单   *\n");
 printf("\t\t\t\t\t\t*3、返回主菜单    *\n");
 printf("\t\t\t\t\t\t******************************\n");
 printf("\t\t\t\t\t\t******************************\n"); 
 printf("            请选择(1-3):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1: 
    system("cls");
   system("color f0");
   Student_Tongji_menu(); 
    
  case 2:
   system("cls");
   system("color f0");
   Level_2_menu( );
  
 case 3:
   system("cls");
   system("color f0");
   Level_menu();
  }
  
 } 
 }
 
/*统计菜单模块*/
void Student_Tongji_menu3()
{
 int choice; 
 while(1)
 {
 
  IO_ReadInfo();  //读取文件
 printf("\n\n\n\n\t\t\t\t\t\t******************************\n");  
  printf("\t\t\t\t\t\t* 你目前按C语言成绩统计页面!*\n");
 printf("\t\t\t\t\t\t******************************\n");
  printf("\t\t\t\t\t\t*1、返回上一级统计菜单  *\n");
 printf("\t\t\t\t\t\t*2、返回功能选择菜单   *\n");
 printf("\t\t\t\t\t\t*3、返回主菜单    *\n");
 printf("\t\t\t\t\t\t******************************\n");
 printf("\t\t\t\t\t\t******************************\n"); 
 printf("            请选择(1-3):"); 
 scanf("%d",&choice);
 
 switch(choice) 
  { 
  case 1: 
    system("cls");
   system("color f0");
   Student_Tongji_menu(); 
    
  case 2:
   system("cls");
   system("color f0");
   Level_2_menu( );
  
 case 3:
   system("cls");
   system("color f0");
   Level_menu();
  }
  
 } 
 } 
 
 
/*第一级主菜单学生or老师的判断*/ 
void Level_menu()
{  int choice;
  while(1)
 { 
 system("cls");
  system("color f0");
  printf("\n\n\n\n\n\n\n\t\t\t\t\t\t******************\n");
 printf("\t\t\t\t\t\t*1、教师端  *\n");
 printf("\t\t\t\t\t\t*2、学生端  *\n");
 printf("\t\t\t\t\t\t*3、退出   *\n");
 printf("\t\t\t\t\t\t******************\n");
 printf("            请选择(1-3):"); 
 scanf("%d",&choice);
 switch(choice)
 {
  case 1:
   system("cls");
   system("color f0");  
     Level_1_menu(); //一级菜单,密码登录。 
     IO_ReadInfo();   //读取文件
     Level_2_menu(); //二级菜单-主菜单 
     IO_WriteInfo();
  break;
  
 case 2:
  student_menu();
  break; 
 case 3:
  exit(0); 
     break;  
 } 
 } 
 } 


 
/***********主程序*********/ 
main() 
{ 
 Level_menu();
}

关于管理系统的更多内容请点击《管理系统专题》进行学习

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文