📄 xueshengshujukuguanli.c
字号:
#include <stdio.h>
#include <bios.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <mem.h>
#include <ctype.h>
#include <alloc.h>
#define N 3 /*定义常数*/
/*****************************************数据库**********************************************/
typedef struct z1 /*学生数据库*/
{
char num[11];
char name[15];
char sexy[6];
char jiguan[10];
char birthday[12];
char adress[25];
char telephone[12];
char email[20];
char jiangfa[100];
char kecheng[N][10];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;
typedef struct z2 /*课程数据库*/
{
char num[4];
char name[15];
char mark[2];
char time[30];
char address[25];
char teacher[12];
char collage[20];
char stunum[100][11];
int stutotal;
struct z2 *next;
}CLASS;
typedef struct PW /*密码数据库*/
{
char num[11]; /*用户名*/
char psw[15]; /*密码*/
struct PW *next;
}PASSWORD;
/**************************************以下是子函数原型****************************************/
/**************************************登陆界面************************************************/
int loader(char *s,char *p);
/**************************************数据库下载**********************************************/
STUDENT *load_stu(); /*学生数据库下载*/
CLASS *load_cla(); /*课程数据库下载*/
PASSWORD *load_pw(); /*密码数据库下载*/
/**************************************数据库生成**********************************************/
STUDENT *create_stu(); /*创建学生数据库*/
CLASS *create_cla(); /*创建课程数据库*/
PASSWORD *create_pw(); /*创建密码数据库*/
/***************************************数据库保存*********************************************/
void save_stu(STUDENT *h); /*学生数据库保存*/
void save_cla(CLASS *h); /*课程数据库保存*/
void save_pw(PASSWORD *h); /*密码数据库保存*/
/***************************************数据库删除********************************************/
STUDENT *delete_stu(STUDENT *h); /*学生数据库删除*/
PASSWORD *delete_pw(PASSWORD *h); /*密码数据库删除*/
/***************************************数据库添加*******************************************/
STUDENT *insert_stu(STUDENT *h); /*添加学生数据库*/
PASSWORD *insert_pw(PASSWORD *h); /*添加密码数据库*/
/***************************************修改数据库*******************************************/
PASSWORD *modify_pw_sig(PASSWORD *h);/*本人密码修改*/
PASSWORD *modify_pw(PASSWORD *h); /*数据库密码修改*/
void print(STUDENT *h); /* 显示学生数据库所有记录*/
void print1(CLASS *h); /*显示课程数据库所有记录*/
void search11(STUDENT *h,char s[11]);/*查找个人信息*/
void search12(STUDENT *h,char s[11]);
void search(STUDENT *h); /*查找个人信息*/
void search1(STUDENT *h); /*查找个人成绩*/
void computer(STUDENT *h); /*计算所有学生总分和每个学生的总均分*/
void computer1(STUDENT *h); /*统计某门课程的平均分和总成绩*/
STUDENT *sort(STUDENT *h); /*排序*/
void total(STUDENT *h); /*分类合计*/
STUDENT *sort(STUDENT *h); /*学生数据库排序*/
void select_course(char *stu_num,CLASS *h1,STUDENT *h2);/*选课*/
void print2(char stu_num[11],CLASS *h1,STUDENT *h2); /*打印课程表*/
void delet_course(char stu_num[11],CLASS *h1,STUDENT *h2);/*选课删除*/
int menu_select(); /*管理员主菜单*/
int menu_select1(); /*管理员查询菜单*/
int menu_select2(); /*管理员录入菜单*/
int menu_select3(); /*管理员统计菜单*/
int menu_select4(); /*管理员修改菜单*/
int menu_select11(); /*管理员修改所有密码*/
int menu_select5(); /*老师菜单*/
int menu_select6(); /*老师查询菜单*/
int menu_select7(); /*老师统计菜单*/
int menu_select8(); /*学生主菜单*/
int menu_select9(); /*学生查询菜单*/
int menu_select10(); /*学生选课菜单*/
/**********************************************主函数*******************************************/
main()
{
STUDENT *head_stu=NULL; /*学生数据库链表定义头指针*/
CLASS *head_cla=NULL; /*课程数据库链表定义指针*/
PASSWORD *head_pw=NULL; /*密码数据库链表定义指针*/
zhu:
head_stu=load_stu();
head_cla=load_cla();
head_pw=load_pw();
clrscr(); /*清屏*/
for(;;)
{
char s[11],p[15];
textbackground(WHITE);
textcolor(BLACK);
window(1,1,80,25);
clrscr();
gotoxy(10,2);
cprintf("enter your num and code please!\n");
gotoxy(10,3);
cprintf("CODE:");
scanf("%s",s);
if(s[0]=='@')exit(1);
gotoxy(10,4);
cprintf("enter your passward please!\n");
gotoxy(10,5);
cprintf("PASSWORD:");
scanf("%s",p);
clrscr();
switch(loader(s,p))
{
case 0:for(;;) /*管理员登陆界面*/
{
adzhu: switch(menu_select())
{
case 0:for(;;) /*密码修改*/
{
switch(menu_select11())
{
case 0:modify_pw_sig(head_pw);break; /*本身密码修改*/
case 1:head_pw=modify_pw(head_pw);break; /*学生密码修改*/
case 2:goto adzhu; /*返回管理员登陆界面*/
}
}
case 1:for(;;) /*查询*/
{
switch(menu_select1())
{
case 0:search(head_stu);break; /*基本信息查询*/
case 1:search1(head_stu);break; /*单科成绩查询*/
case 2:goto adzhu; /*返回管理员登陆界面*/
}
}
case 2:for(;;) /*录入*/
{
switch(menu_select2())
{
case 0:head_stu=create_stu();break; /*录入学生数据库*/
case 1:head_cla=create_cla(); break; /*录入课程数据库*/
case 2:head_pw=create_pw();break; /*录入密码数据库*/
case 3:goto adzhu; /*返回管理员登陆界面*/
}
}
case 3:for(;;) /*统计*/
{
switch(menu_select3())
{
case 0:computer(head_stu);break; /*计算所有学生总分和每个学生的总均分*/
case 1:computer1(head_stu);break; /*统计某门课程的平均分和总成绩*/
case 2:goto adzhu; /*返回管理员登陆界面*/
}
}
case 4: sort(head_stu);/*按成绩排序*/
head_stu=load_stu();
break;
case 5:for(;;) /*修改*/
{
switch(menu_select4())
{
case 0:head_stu=insert_stu(head_stu);break; /*学生数据库插入自动保存*/
case 1:head_stu=delete_stu(head_stu);break; /*学生数据库删除自动保存*/
case 2:head_pw=insert_pw(head_pw);break;/*密码数据库添加自动保存*/
case 3:head_pw=delete_pw(head_pw);break;/*密码数据库删除自动保存*/
case 4:goto adzhu;
}
}
case 6:goto zhu; /*返回登陆界面*/
}
}
case 1: for(;;) /*老师登陆界面*/
{
tzhu: switch(menu_select5())
{
case 0:modify_pw_sig(head_pw);break; /*密码修改*/
case 1:for(;;) /*查询*/
{
switch(menu_select6())
{
case 0:search(head_stu);break; /*基本信息*/
case 1:search1(head_stu);break; /*成绩*/
case 2:goto tzhu; /*返回老师登陆界面*/
}
}
case 2:for(;;) /*统计*/
{
switch(menu_select7())
{
case 0:break; /*选课人数*/
case 1:total(head_stu);break; /*分数段*/
case 2:goto tzhu; /*返回老师登陆界面*/
}
}
case 3:goto zhu; /*返回登陆界面*/
}
};
case 2:for(;;) /*学生登陆界面*/
{
szhu: switch(menu_select8())
{
case 0:modify_pw_sig(head_pw);break; /*密码修改*/
case 1:for(;;) /*查询*/
{
switch(menu_select9())
{
case 0:search11(head_stu,s);break; /*基本休息查询*/
case 1:print2(s,head_cla,head_stu);break; /*课表查询*/
case 2:search12(head_stu,s);break; /*成绩查询*/
case 3:goto szhu; /*返回学生登陆界面*/
}
}
case 2:for(;;) /*选课*/
{
switch(menu_select10())
{
case 0:print1(head_cla);select_course(s,head_cla,head_stu);break; /*选课*/
case 1:delet_course(s,head_cla,head_stu);break; /*退课*/
case 2:goto szhu; /*返回学生登陆界面*/
}
}
case 3:goto zhu; /*返回登陆界面*/
}
}
default:printf("\n CODE OR PASSWORD EORROR\n"); /*密码或用户名错误*/
getch();
break;
}
}
}
/**********************************************子函数部分***************************************/
/*密码登陆界面*/
int loader(char s[],char p1[])
{
char ch;
int fdback=3,Get;
char fnum[]="0011";
char fpsw[]="0011";
PASSWORD *p,*q,*q1,*h=NULL;
FILE *fp; /* 定义指向文件的指针*/
char infile[20]="f:\\te.txt"; /*保存文件名*/
if(strcmp(fnum,s)==0&&strcmp(fpsw,p1)==0)
{
clrscr();
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n SUCCESE\n");
return(0);
}
else
{
if((fp=fopen(infile,"rb"))==NULL) /*打开一个二进制文件,为读方式*/
{
printf("can not open file\n"); /*如不能打开,则结束程序*/
exit(1);
}
p=(PASSWORD *)malloc(sizeof(PASSWORD)); /*申请空间*/
if(!p)
{
printf("out of memory!\n"); /*如没有申请到,则内存溢出*/
}
h=p; /*申请到空间,将其作为头指针*/
while(!feof(fp)) /*循环读数据直到文件尾结束*/
{
if(1!=fread(p,sizeof(PASSWORD),1,fp))
break; /*如果没读到数据,跳出循环*/
p->next=(PASSWORD *)malloc(sizeof(PASSWORD)); /*为下一个结点申请空间*/
if(!p->next)
{
printf("out of memory!\n"); /*如没有申请到,则内存溢出*/
}
q=p; /*保存当前结点的指针,作为下一结点的前驱*/
p=p->next; /*指针后移,新读入数据链到当前表尾*/
}
q->next=NULL; /*最后一个结点的后继指针为空*/
fclose(fp);
p=h;
while(strcmp(p->num,s)&&p!=NULL)
{
p=p->next;
}
if(p==NULL)
{
return(fdback);
}
else if(strcmp(p->psw,p1)==0)
{
fdback=s[0]-48;
p=h;
do
{
q1=p;
free(q1);
p=p->next;
}while(p!=NULL);
return(fdback);
}
else return(fdback);
}
}
/*******************************************数据库下载子函数*************************************/
/*学生数据库下载*/
STUDENT *load_stu()
{
STUDENT *p,*q,*h=NULL;
FILE *fp;
char infile[15]="f:\\f1\\te.txt";
/*printf("Enter infile name,for example c:\\f1\\te.txt:\n"); scanf("%s",infile);*/
if((fp=fopen(infile,"rb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("\n -----Loading file!-----\n");
p=(STUDENT *)malloc(sizeof(STUDENT));
if(!p)
{
printf("out of memory!\n");
return h;
}
h=p;
while(!feof(fp))
{
if(1!=fread(p,sizeof(STUDENT),1,fp))
break;
p->next=(STUDENT *)malloc(sizeof(STUDENT));
if(!p->next)
{
printf("out of memory!\n");
return h;
}
q=p;
p=p->next;
}
q->next=NULL;
fclose(fp);
printf("---You have success read data from file!!!---\n");
return h;
}
/*课程数据库下载*/
CLASS *load_cla()
{
CLASS *p,*q,*h=NULL; /*定义记录指针变量*/
FILE *fp; /* 定义指向文件的指针*/
char infile[15]="f:\\f2\\te.txt"; /*保存文件名*/
if((fp=fopen(infile,"rb"))==NULL) /*打开一个二进制文件,为读方式*/
{
printf("can not open file\n"); /*如不能打开,则结束程序*/
exit(1);
}
printf("\n -----Loading file!-----\n");
p=(CLASS *)malloc(sizeof(CLASS)); /*申请空间*/
if(!p)
{
printf("out of memory!\n"); /*如没有申请到,则内存溢出*/
return h; /*返回空头指针*/
}
h=p; /*申请到空间,将其作为头指针*/
while(!feof(fp)) /*循环读数据直到文件尾结束*/
{
if(1!=fread(p,sizeof(CLASS),1,fp))
break; /*如果没读到数据,跳出循环*/
p->next=(CLASS *)malloc(sizeof(CLASS)); /*为下一个结点申请空间*/
if(!p->next)
{
printf("out of memory!\n"); /*如没有申请到,则内存溢出*/
return h;
}
q=p; /*保存当前结点的指针,作为下一结点的前驱*/
p=p->next; /*指针后移,新读入数据链到当前表尾*/
}
q->next=NULL; /*最后一个结点的后继指针为空*/
fclose(fp); /*关闭文件*/
printf("---You have success read data from file!!!---\n");
return h; /*返回头指针*/
}
/*密码数据库的下载*/
PASSWORD *load_pw()
{
PASSWORD *p,*q,*h=NULL;
FILE *fp;
char infile[20]={"f:\\te.txt"};
if((fp=fopen(infile,"rb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("\n -----Loading file!-----\n");
p=(PASSWORD *)malloc(sizeof(PASSWORD));
if(!p)
{
printf("out of memory!\n");
return h;
}
h=p;
while(!feof(fp))
{
if(1!=fread(p,sizeof(PASSWORD),1,fp))
break;
p->next=(PASSWORD *)malloc(sizeof(PASSWORD));
if(!p->next)
{
printf("out of memory!\n");
return h;
}
q=p;
p=p->next;
}
q->next=NULL;
fclose(fp);
return h;
}
/*******************************************数据库创建子函数***********************************/
/*创建学生数据库*/
STUDENT *create_stu()
{
int i;
STUDENT *h=NULL,*info;
for(;;)
{
int s=0;
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\nout of memory");
return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -