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

所属分类: 软件编程 / C 语言 阅读数: 85
收藏 0 赞 0 分享

本文实例为大家分享了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++实现string与各种类型之间的转换

这个类在头文件中定义, < sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。另外,每个类都有一个对应的宽字符集版本
收藏 0 赞 0 分享

C++如何通过ostringstream实现任意类型转string

再使用整型转string的时候感觉有点棘手,因为itoa不是标准C里面的,而且即便是有itoa,其他类型转string不是很方便。后来去网上找了一下,发现有一个好方法
收藏 0 赞 0 分享

C/C++指针小结

要搞清一个指针需要搞清指针的四方面的内容:指针的类型,指针所指向的类型,指针的值或者叫指针所指向的内存区,还有指针本身所占据的内存区
收藏 0 赞 0 分享

C++ 类的静态成员深入解析

在C++中类的静态成员变量和静态成员函数是个容易出错的地方,本文先通过几个例子来总结静态成员变量和成员函数使用规则,再给出一个实例来加深印象
收藏 0 赞 0 分享

C++类的静态成员初始化详细讲解

通常静态数据成员在类声明中声明,在包含类方法的文件中初始化.初始化时使用作用域操作符来指出静态成员所属的类.但如果静态成员是整型或是枚举型const,则可以在类声明中初始化
收藏 0 赞 0 分享

C++类静态成员与类静态成员函数详解

静态成员不可在类体内进行赋值,因为它是被所有该类的对象所共享的。你在一个对象里给它赋值,其他对象里的该成员也会发生变化。为了避免混乱,所以不可在类体内进行赋值
收藏 0 赞 0 分享

C++中的friend友元函数详细解析

友元可以是一个函数,该函数被称为友元函数;友元也可以是一个类,该类被称为友元类。友元函数的特点是能够访问类中的私有成员的非成员函数。友元函数从语法上看,它与普通函数一样,即在定义上和调用上与普通函数一样
收藏 0 赞 0 分享

static全局变量与普通的全局变量的区别详细解析

以下是对static全局变量与普通的全局变量的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助
收藏 0 赞 0 分享

C++ explicit关键字的应用方法详细讲解

C++ explicit关键字用来修饰类的构造函数,表明该构造函数是显式的,既然有"显式"那么必然就有"隐式",那么什么是显示而什么又是隐式的呢?下面就让我们一起来看看这方面的知识吧
收藏 0 赞 0 分享

教你5分钟轻松搞定内存字节对齐

随便google一下,人家就可以跟你解释的,一大堆的道理,我们没怎么多时间,讨论为何要对齐.直入主题,怎么判断内存对齐规则,sizeof的结果怎么来的,请牢记以下3条原则
收藏 0 赞 0 分享
查看更多