栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言实现学生学籍管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言实现学生学籍管理系统

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

#include 
#include 
#include 
#include 
#include 
 
 
//**********************************结构体************************************* 
struct score 
{ 
 char class_num[10]; 
 char person_num[10]; 
 char name[15]; 
 char sex; 
 int num; 
}stu; 


//******************************输出******************************************* 
void print1()     //输出科目函数 
{ 
printf("班级  学号  姓名    性别  分数n"); 
} 

//*****************************菜单******************************************** 
int menu()      //菜单函数 
{ 
 
 char i; 
 printf("nnnn"); 
 puts("tt**********************主菜单******************tn"); 
 puts("tttt1.学生信息输入 n"); 
 puts("tttt2.学生信息浏览 n"); 
 puts("tttt3.学生信息检索 n"); 
 puts("tttt4.学生信息修改 n"); 
 puts("tttt5.学生信息删除 n"); 
 puts("tttt6. 退 出 系 统 n"); 
 puts("tt**********************************************tn"); 
 printf("ttt 请选择(1-6):[ ]bb"); 
 i=getchar(); 
 system("cls"); 
 return i; 
} 

//**********************输入函数******************************************* 
void Enter() 
{ 
 
 FILE *fp; 
 char ch; 
 if((fp=fopen("f:\zimou.txt","a+"))==NULL) 
 { 
  printf("nCannot open file!n"); 
  getch(); 
  exit(1); 
 } 
 do 
 { 
  printf("请输入班级:");scanf("%s",stu.class_num);getchar(); 
  printf("n"); 
  printf("请输入学号:");gets(stu.person_num); 
  printf("n"); 
  printf("请输入姓名:");gets(stu.name); 
  printf("n"); 
  printf("性  别(m/f):");scanf("%c",&stu.sex);getchar(); 
  printf("n"); 
  printf("分  数:");scanf("%d",&stu.num);getchar(); 
  printf("n"); 
  fwrite(&stu,sizeof(stu),1,fp); 
  printf("继续(y/n)?[ ]bb"); 
  ch=getchar(); getchar(); 
 }while(ch=='y'||ch=='Y'); 
 fclose(fp); 
 system("cls"); 
} 
 
 
 
//*****************浏览函数********************************************** 
void Browse() 
{ 
 
FILE *fp; 
int total=0; 
if((fp=fopen("f:\zimou.txt","a+"))==NULL) 
{ 
 printf("tCan not open the inform file!"); 
 getch(); 
 exit(1); 
} 
while(fread(&stu,sizeof(stu),1,fp)==1) 
{ 
 total++; 
 if(total==1) 
 print1(); 
 printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name); 
 printf("%-8c",stu.sex); 
 printf("%-4d ",stu.num); 
 printf("n"); 
} 
fclose(fp); 
printf("nnt共有 %d 条记录!n",total); 
printf("tpress any key to continue!"); 
getchar(); 
getchar(); 
system("cls"); 
 
} 
 
 
//*******************查询函数********************************************* 
void Query() 
{ 
 FILE * fp; 
 char num1[10]; 
 char ch; 
if((fp=fopen("f:\zimou.txt","a+"))==NULL) 
{ 
 printf("tCan not open the inform file!"); 
 getch(); 
 exit(1); 
} 
do 
{ 
 getchar(); 
 rewind(fp); 
 printf("n请输入学号查询:"); 
 gets(num1); 
 while(fread(&stu,sizeof(stu),1,fp)==1) 
  if(strcmp(num1,stu.person_num)==0) 
  { 
   print1(); 
   printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name); 
   printf("%-8c",stu.sex); 
   printf("%-4d ",stu.num); 
   printf("n"); 
   break; 
  } 
  puts("n"); 
 printf("继续查询?(Y/N):[ ]bb"); 
 ch=getchar(); 
}while(ch=='Y'||ch=='y'); 
fclose(fp); 
system("cls"); 
} 
 
 
//**********************学生成绩修改函数*********************************** 
 
void Recopose() 
{ 
  FILE * fp1,* fp2; 
  char num1[10]; 
  char ch; 
  getchar(); 
 do 
 { 
  if((fp1=fopen("f:\zimou.txt","a+"))==NULL) 
  { 
  printf("tCan not open the infom file!"); 
  getch(); 
  exit(1); 
  } 
  if((fp2=fopen("f:\ziye.txt","a+"))==NULL) 
  { 
  printf("tCan not creat the temp file!"); 
  getch(); 
  exit(1); 
  } 
  printf("请输入想要修改的学号:"); 
  gets(num1); 
while(fread(&stu, sizeof(stu),1,fp1)==1) 
{ 
  if(strcmp(num1,stu.person_num)==0) 
  { 
   print1(); 
   printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name); 
   printf("%-8c",stu.sex); 
   printf("%-4d ",stu.num); 
   printf("n"); 
   printf("nnPlease input the new information:n"); 
   printf("t班级代号:");gets(stu.class_num); 
   printf("t学生学号:");gets(stu.person_num); 
   printf("t学生姓名:"); gets(stu.name); 
   printf("t学生性别:");gets(&stu.sex); 
   printf("t学生成绩:");scanf("%d",&stu.num); getchar(); 
  } 
 fwrite(&stu,sizeof(stu),1,fp2); 
 } 
 fclose(fp1); 
 fclose(fp2); 
 printf("修改成功!n"); 
 remove("f:\zimou.txt"); 
 rename("f:\ziye.txt","f:\zimou.txt"); 
 printf("继续修改?(Y/N):[ ]bb"); 
 ch=getchar(); getchar(); 
}while(ch=='Y'||ch=='y'); 
 system("cls"); 
} 
 
 
//*********************删除函数****************************************** 
void Delete() 
{ 
  FILE * fp1,* fp2; 
  int flag; 
  char num1[10]; 
  char ch; 
  getchar(); 
  do 
  { 
  if((fp1=fopen("f:\zimou.txt","a+"))==NULL) 
  { 
   printf("tCan not open the inform file!"); 
   getch(); 
   exit(1); 
  } 
  if((fp2=fopen("f:\ziye.txt","a+"))==NULL) 
  { 
   printf("tCan not creat the temp file!"); 
   getch(); 
   exit(1); 
  } 
  printf("请输入你要删除的学生的学号:"); 
  gets(num1); 
  flag=0; 
  while(fread(&stu,sizeof(stu),1,fp1)==1) 
  { 
   if(strcmp(num1,stu.person_num)==0) 
   { 
    print1(); 
    printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name); 
    printf("%-8c",stu.sex); 
    printf("%-4d ",stu.num); 
    printf("n"); 
    flag=1; 
   } 
   else 
    fwrite(&stu,sizeof(stu),1,fp2); 
  } 
  fclose(fp1); 
  fclose(fp2); 
  if(flag==1) 
  { 
   remove("f:\zimou.txt"); 
   rename("f:\ziye.txt","f:\zimou.txt"); 
  } 
  else 
   printf("Can not find this record!n"); 
  printf("继续删除?(Y/N):[ ]bb"); 
  ch=getchar(); getchar(); 
  }while(ch=='Y'||ch=='y'); 
  system("cls"); 
} 
 
 
//***********************************退出************************************** 
void Exit() 
{ 
 puts("ntttt感谢使用本系统!!nntttt有任何问题请联系:1005483758@qq.com n"); 
 exit(0); 
} 
 
//******************欢迎界面********************************** 
void Welcome() 
{ 
  printf("nn"); 
 printf(" t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓n"); 
 printf(" t┃**********************************************************┃n"); 
 printf(" t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃n"); 
 printf(" t┃***┃************************************************┃***┃n"); 
 printf(" t┃***┃***    ****┃***┃n"); 
 printf(" t┃***┃***  欢迎使用学生成绩管理系统   ****┃***┃n"); 
 printf(" t┃***┃***    ****┃***┃n"); 
 printf(" t┃***┃***    ****┃***┃n"); 
 printf(" t┃***┃***     制作人:XXY   ****┃***┃n"); 
 printf(" t┃***┃***    ****┃***┃n"); 
 printf(" t┃***┃***      2013.6.20  ****┃***┃n"); 
 printf(" t┃***┃***    ****┃***┃n"); 
 printf(" t┃***┃************************************************┃***┃n"); 
 printf(" t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃n"); 
 printf(" t┃**********************************************************┃n"); 
 printf(" t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛n"); 
 puts(" nt      ① 管理员登陆!n"); 
 puts(" nt      ② 游客 登陆!n"); 
 printf("n请选择登陆(1 or 2):[ ]bb"); / /左移一位“b ” 
} 
 
//*****************************主函数**************************************** 
int main() 
{ 
  int i,k=0; 
  char username[15],pwd[7],c; 
  system("color 5e");//颜色 
  Welcome(); 
   c=getchar();getchar(); 
  if (c=='1') 
  { 
   system("cls");//跳转页面。 
   puts("nnnnnnntttt管 理 员 登 陆!nnnnntttt 请 登 陆!"); 
   getchar(); 
   for(i=0;i<3;i++) 
    { 
      printf("n请输入用户名:"); 
     gets(username); 
     printf("n请输入6位密码:"); 
     gets(pwd); 
     //判断条件 
     if((strcmp(username,"xiaxianyun")==0)&&(strcmp(pwd,"123456")==0)) 
     { 
      printf("n您已经成功登录n"); 
      k=1; 
      for(i=0;i<20;i++) 
      { 
 printf("."); 
 Sleep(100); 
      } 
     system("cls"); 
  
      while(1) 
      switch(menu()) 
      { 
case '1':Enter();break; 
case '2':Browse();break; 
case '3':Query();break; 
case '4':Recopose();break; 
case '5':Delete();break; 
case '6':Exit();break; 
      } 
      break; 
     } 
    else 
     printf("n用户名或密码无效 请重新输入:n"); 
     continue; 
    } 
     if(k==0) 
    printf("n连续输入错误3次 将退出程序n"); 
  Sleep(2000); 
  exit(1); 
  } 
  else if(c=='2')//游客登录 
  { 
   system("cls");//跳转页面。 
   puts("nnnnnnntttt欢 迎 游 客 进 入!nnnnntttt 请 确 定!"); 
   getchar(); 
   system("cls"); 
   while(1) 
    switch(menu()) 
    { 
     case '1':Enter();break; 
     case '2':Browse();break; 
     case '3':Query();break; 
     case '4':system("cls");getchar(); 
     puts("nntt对不起你没有权限修改!nn"); 
     printf("ttpress any key to continue!");getchar();system("cls");break; 
     case '5':system("cls");getchar(); 
     puts("nntt对不起你没有权限删除!nn"); 
     printf("ttpress any key to continue!");getchar();system("cls");break; 
     case '6':Exit();break; 
    } 
  }  
 return 0; 
} 

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/63030.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号