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

 更新时间:2022年07月22日 09:08:32   作者:xiaoyuyyun  
这篇文章主要为大家详细介绍了C语言实现学生学籍管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

#include<stdio.h> 
#include<conio.h> 
#include<stdlib.h> 
#include<string.h> 
#include<windows.h> 
 
 
//**********************************结构体************************************* 
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("\n\n\n\n"); 
 puts("\t\t**********************主菜单******************\t\n"); 
 puts("\t\t\t\t1.学生信息输入        \n"); 
 puts("\t\t\t\t2.学生信息浏览        \n"); 
 puts("\t\t\t\t3.学生信息检索        \n"); 
 puts("\t\t\t\t4.学生信息修改        \n"); 
 puts("\t\t\t\t5.学生信息删除        \n"); 
 puts("\t\t\t\t6. 退 出 系 统        \n"); 
 puts("\t\t**********************************************\t\n"); 
 printf("\t\t\t 请选择(1-6):[ ]\b\b"); 
 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)?[ ]\b\b"); 
  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("\n\n\t共有 %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):[ ]\b\b"); 
 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("\n\nPlease 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):[ ]\b\b"); 
 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):[ ]\b\b"); 
  ch=getchar(); getchar(); 
  }while(ch=='Y'||ch=='y'); 
  system("cls"); 
} 
 
 
//***********************************退出************************************** 
void Exit() 
{ 
 puts("\n\t\t\t\t感谢使用本系统!!\n\n\t\t\t\t有任何问题请联系:1005483758@qq.com \n"); 
 exit(0); 
} 
 
//******************欢迎界面********************************** 
void Welcome() 
{ 
  printf("\n\n"); 
 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(" \n\t      ① 管理员登陆!       \n"); 
 puts(" \n\t      ② 游客 登陆!       \n"); 
 printf("\n请选择登陆(1 or 2):[ ]\b\b"); / /左移一位“\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("\n\n\n\n\n\n\n\t\t\t\t管 理 员 登 陆!\n\n\n\n\n\t\t\t\t 请 登 陆!"); 
   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("\n\n\n\n\n\n\n\t\t\t\t欢 迎 游 客 进 入!\n\n\n\n\n\t\t\t\t 请 确 定!"); 
   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("\n\n\t\t对不起你没有权限修改!\n\n"); 
     printf("\t\tpress any key to continue!");getchar();system("cls");break; 
     case '5':system("cls");getchar(); 
     puts("\n\n\t\t对不起你没有权限删除!\n\n"); 
     printf("\t\tpress any key to continue!");getchar();system("cls");break; 
     case '6':Exit();break; 
    } 
  }  
 return 0; 
} 

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

相关文章

  • C++ std::chrono库使用示例(实现C++ 获取日期,时间戳,计时等功能)

    C++ std::chrono库使用示例(实现C++ 获取日期,时间戳,计时等功能)

    std::chrono是C++标准库中的一个组件,用于表示和处理时间,这篇文章主要介绍了C++ std::chrono库使用指南(实现C++ 获取日期,时间戳,计时等功能),需要的朋友可以参考下
    2023-06-06
  • STL常用容器详细解析

    STL常用容器详细解析

    这里我们不涉及容器的基本操作之类,只是要讨论一下各个容器其各自的特点STL中的常用容器包括:顺序性容器(vector、deque、list)、关联容器(map、set)、容器适配器(queue、stac)
    2013-09-09
  • C语言不用链表完成学生管理系统(完整代码)

    C语言不用链表完成学生管理系统(完整代码)

    这篇文章主要介绍了C语言不用链表完成学生管理系统(完整代码),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-04-04
  • C++语言实现线性表之数组实例

    C++语言实现线性表之数组实例

    这篇文章主要介绍了C++语言实现线性表之数组,实例分析了C++实现数组形式线性表的原理与方法,需要的朋友可以参考下
    2015-04-04
  • C语言多种获取字符串长度的方法

    C语言多种获取字符串长度的方法

    这篇文章主要介绍了C语言多种获取字符串长度的方法,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
    2021-07-07
  • C语言通过栈实现小人走迷宫

    C语言通过栈实现小人走迷宫

    这篇文章主要为大家详细介绍了C语言通过栈实现小人走迷宫,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • 解析VScode在Windows环境下c_cpp_properties.json文件配置问题(推荐)

    解析VScode在Windows环境下c_cpp_properties.json文件配置问题(推荐)

    这篇文章主要介绍了解析VScode在Windows环境下c_cpp_properties.json文件配置问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-05-05
  • QT中线程池QThreadPool类概念和使用方法详解

    QT中线程池QThreadPool类概念和使用方法详解

    这篇文章主要为大家介绍了QT中线程池QThreadPool类概念和使用方法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-09-09
  • 讲解C语言编程中指针赋值的入门实例

    讲解C语言编程中指针赋值的入门实例

    这篇文章主要介绍了讲解C语言编程中指针赋值的入门实例,通过const int i与int *const pi这样两个例子来分析指针的赋值和地址指向,需要的朋友可以参考下
    2015-12-12
  • C语言版停车位管理系统

    C语言版停车位管理系统

    这篇文章主要为大家详细介绍了C语言版停车位管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03

最新评论