完整代码在这里
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "ctype.h"
struct stu // 学生结构体 学号、姓名、性别、年龄、宿舍号码、电话号码
{
int id;//账号
char name[100];//姓名
int clas;//班级
char sex[6];//性别
int age;//年龄
int dor;//宿舍号码
char key[12];//密码
char phone[12];//电话号码
int score;
struct stu * next;
struct cla * cla;
}*p1,stu1;
struct tec //教师结构体
{
int id;
char name[100];
char sex[6];
char cla_name[100];
int cla_id;//课程编号
char phone[12];
char key[12];
int score;
char email[30];
struct cla * cla;
struct tec * next;
}tec1;
struct cla //学生课程结构体 课程编号、课程名称、考试成绩、平时成绩、综合成绩、学分、重修否
{
int id;//学生id
char name[100];
char stu_name[100];
float e_score;
float n_score;
float t_score;
int score;//学分
struct cla *next;
struct res *res;
struct cla *follow;
struct cla *tec;
}cla1;
struct res //重修结构体 重修学期、重修成绩,并且要考虑多次重修
{
int id;
char name[100]; //course name
int semester;
float score;
int times;
struct res * next;
struct res * follow;
}res1;
struct order // 为了学生成绩排名
{
struct cla *pointer;
struct order *next;
};
struct info //信息结构体
{
int num; // the amount of stu or cla or res
char key[11];
}in1,in2,in3,in4;
struct info2
{
char name[500];
char note[500];
int i;
struct info2 *next;
};
FILE *fp3,*fp1,*fp2,*fp4;
struct stu * head=NULL,*p1,*p2;
struct tec * head_tec=NULL;
struct cla * clap,*headc;
struct res * resp,*headr;
//definition
void apple_ID();//用户注册
void file_open();//用来打开文件和构建链表
void file_close();
void insert_stu(struct stu stu1);//学生结构体插入
void insert_tec(struct tec tec1);//教师结构体插入
struct cla * insert_cla1(struct cla cla1);//将课程插入学生
void insert_cla2(struct cla cp);//将课程插入教师
void insert_res(struct res res1);//插入重修
void input_stu();//学生录入
void input_tec();//教师录入
void input_cla();//课程录入
void input_res();//重修录入
void copy_tec(struct tec *p1,struct tec tec1);//用于复制 减少代码量
void copy_stu(struct stu *p1,struct stu stu1);// 用于复制 减少代码量
void del_stu();//删除学生信息
void del_tec();//删除教师信息
void del_res();//删除重修信息
void pfree_res(struct cla *p,struct res res1);//解锁及释放重修内存
void pfree_cla(struct stu *p_stu,struct tec *p_tec,struct cla cla1);//解锁及释放课程内存
void modify_stu(struct stu *p);// 学生修改自己信息
void modify_tec(struct tec *p);// 教师修改自己信息
void modify_stu_adm();//管理员进入某一学生系统 修改学生信息 如密码
void modify_tec_adm();//管理员进入某一教师系统 修改教师信息 如密码
void skim_stu(struct stu *head);//按ID或名字查看学生信息
void skim_tec(struct tec *head);//按id或名字查看教师
void skim_stu_all();//查看所有学生学分及不及格课程
void skim_tec_all();//查看所有教师
void skim_stu_course();// 根据课程查看学生 管理员功能
void skim_stu_class();// 根据班级查看学生 管理员功能
void skim_list_stu(struct tec * p);//教师查看所有选自己课的学生
struct order * list(struct cla *head);// 学生分数排序 返回链表头 to make a list of stu
void print_stu(struct stu p1);//输出学生
void adm_ui_1();//学生界面
void adm_ui_2();//教师界面
void stu_ui(struct stu p);//管理员界面1
void tec_ui(struct tec *p);//管理员界面2
void adm_key();//管理员密码修改
void st_key_stu(struct stu *p);//学生密码修改
void st_key_tec(struct tec *p);//教师密码修改
void key_adm();//管理员密码验证 只要密码
void key_stu();//学生ID与密码验证
void key_tec();//教师ID与密码验证
void stu_score(struct tec * p);//教师查看学生分数 按id
void tec_score(struct tec *head);//give score to someone 教师给分
int score_stu(struct stu p);// 计算学生学分
void select_n(struct stu * p);//学生选课必修
void select_s(struct stu * p);//学生选课选修
int idc(char * id);//id装换 char 到int
void key(char *key);//以星号形式接受密码并放到地址key上
struct info2 *Rfile2(struct info2 *head_note);
void Savenote(struct info2 *head_note);
struct info2 *First2(struct info2 *head_note);
void watchall(struct info2 *head_note);
struct info2 *leavenote(struct info2 *head_note);
struct info2 *notesys(struct info2 *head_note);
main()
{
int z;
system("cls");
file_open();
do
{
printf("\n\t\t\t+---------------------------+\n");
printf("\t\t\t| 欢迎使用教务信息管理系统 |\n");
printf("\t\t\t+---------------------------+\n");
printf("提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n");
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ 主菜单 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----学生登录 |\n");
printf("\t\t\t+ [2]----教师登录 |\n");
printf("\t\t\t+ [3]----管理员登陆 |\n");
printf("\t\t\t+ [4]----用户注册 |\n");
printf("\t\t\t+ [0]----退出系统 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 : break;
case 1 :key_stu();break;
case 2 :key_tec();break;
case 3 :key_adm();break;
case 4 :apple_ID();break;
default:printf("\n无效选项!");
}
}
while(z!=0);
file_close(); // to free all the pointer and input data to file
}
void file_open() //用来打开文件和构建链表 head 和 head_tec 是全局变量
{
struct stu stu1;
struct cla cla1;
struct res res1;
struct cla *cp;
int a1=0,a2=0,a3=0,a4=0;
if((fp1=fopen("stu","rb"))==NULL||(fp2=fopen("cla","rb"))==NULL||(fp3=fopen("res","rb"))==NULL||(fp4=fopen("tec","rb"))==NULL) //can't open the file
{
if((fp1=fopen("stu","wb"))==NULL||(fp2=fopen("cla","wb"))==NULL||(fp3=fopen("res","wb"))==NULL||(fp4=fopen("tec","wb"))==NULL)
printf("\nSomething Wrong!"); exit(0);
}
else // open file successfully
{
fread(&in1,sizeof(struct info),1,fp1);
fread(&in2,sizeof(struct info),1,fp2);
fread(&in3,sizeof(struct info),1,fp3);
fread(&in4,sizeof(struct info),1,fp4);
strcpy(in2.key,"19931101");
if(in1.num==0&&in2.num==0) strcpy(in1.key,"123456");
// create a linked list
// add stu struct
while(fread(&stu1,sizeof(struct stu),1,fp1))
{
insert_stu(stu1);
}
fclose(fp1);
while(fread(&tec1,sizeof(struct tec),1,fp4))
{
insert_tec(tec1);
}
fclose(fp4);
while(fread(&cla1,sizeof(struct cla),1,fp2))
{
cp=insert_cla1(cla1);
if(cp!=NULL) insert_cla2(cp);
}
fclose(fp2);
}
while(fread(&res1,sizeof(struct res),1,fp3))
{
insert_res(res1);
}
fclose(fp3);
}
void file_close() //head和head_tec是全局变量
{
struct stu *p1,*p11;
struct cla *p2,*p21;
struct res *p3,*p31;
struct tec *p4,*p41;
fp1=fopen("stu","wb");
fp2=fopen("cla","wb");
fp3=fopen("res","wb");
fp4=fopen("tec","wb");
fwrite(&in1,sizeof(struct info),1,fp1);
fwrite(&in2,sizeof(struct info),1,fp2);
fwrite(&in3,sizeof(struct info),1,fp3);
fwrite(&in4,sizeof(struct info),1,fp4);
p1=head;
while(p1!=NULL)
{
fwrite(&(*p1),sizeof(struct stu),1,fp1);
p11=p1;
p1=p1->next;
free(p11);
}
p4=head_tec;
while(p4!=NULL)
{
fwrite(&(*p4),sizeof(struct tec),1,fp4);
p41=p4;
p4=p4->next;
free(p41);
}
p2=headc;
while(p2!=NULL)
{
fwrite(&(*p2),sizeof(struct cla),1,fp2);
p21=p2;
p2=p2->follow;
free(p21);
}
p3=headr;
while(p3!=NULL)
{
fwrite(&(*p3),sizeof(struct res),1,fp3);
p31=p3;
p3=p3->follow;
free(p31);
}
printf("\nSaved!\n");
}
void apple_ID()
{
int z;
file_open();
system("cls");
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ 华南农业大学教务处欢迎您。|\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----学生注册 |\n");
printf("\t\t\t+ [2]----教师注册 |\n");
printf("\t\t\t+ [0]----返回主界面 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 : break;
case 1 :input_stu(head);break;
case 2 :input_tec(head_tec);break;
default:printf("\n无效选项!");
}
}while(z!=0);
}
void insert_stu(struct stu stu1) //学生结构体插入
{
struct stu *p2,*p3;
if(head==NULL) // empty linked list
{
p1=(struct stu *)malloc(sizeof(struct stu));
head=p1;
copy_stu(p1,stu1);
p1->next=NULL;
p1->cla=NULL;
in1.num++;
}
else
{
p2=head; p3=head;
while(p2!=NULL)
{
if(p2->id>=stu1.id) break;
p3=p2;
p2=p2->next;
}
if(p2==NULL||p2->id>stu1.id)
{
p2=(struct stu *)head;
if(p2->id>stu1.id) //insert at the head
{
p1=(struct stu *)malloc(sizeof(struct stu));
copy_stu(p1,stu1);
p1->next=head;
p1->cla=NULL;
in1.num++;
head=p1;
}
else //insert at the middle or at the end
{
while(p2->idnext!=NULL) // to find the point to insert
{
if(p2->id==stu1.id) break;
p3=p2;p2=p2->next;
}
if(p2->next==NULL&&p2->id
{
p1=(struct stu *)malloc(sizeof(struct stu));
copy_stu(p1,stu1);
p1->next=NULL;
p1->cla=NULL;
in1.num++;
p2->next=p1;
}
else //insert at the middle
{
p1=(struct stu *)malloc(sizeof(struct stu));
copy_stu(p1,stu1);
p1->next=p2;
p1->cla=NULL;
in1.num++;
p3->next=p1;
}
}
}
else printf("\n该生已存在。");
}
}
void insert_tec(struct tec tec1) //教师结构体插入
{
struct tec *p1,*p2,*p3;
if(head_tec==NULL) // empty linked list
{
p1=(struct tec *)malloc(sizeof(struct tec));
head_tec=p1;
p1->id=tec1.id;
copy_tec(p1,tec1);
p1->next=NULL;
in4.num++;
p1->cla=NULL;
}
else
{
p2=head_tec;
p3=head_tec;
while(p2!=NULL)
{
if(p2->id>=tec1.id) break;
p3=p2;
p2=p2->next;
}
if(p2==NULL||p2->id>tec1.id)
{
p2=(struct tec *)head_tec;
if(p2->id>tec1.id) //insert at the head
{
p1=(struct tec *)malloc(sizeof(struct tec));
p1->id=tec1.id;
copy_tec(p1,tec1);
p1->next=head_tec;
p1->cla=NULL;
in4.num++;
head_tec=p1;
}
else //insert at the middle or at the end
{
while(p2->idnext!=NULL) // to find the point to insert
{
p3=p2;
p2=p2->next;
}
if(p2->next==NULL&&p2->id<tec1.id) // insert at the end
{
p1=(struct tec *)malloc(sizeof(struct tec));
p1->id=tec1.id;
copy_tec(p1,tec1);
p1->next=NULL;
p1->cla=NULL;
in4.num++;
p2->next=p1;
}
else //insert at the middle
{
p1=(struct tec *)malloc(sizeof(struct tec));
p1->id=tec1.id;
copy_tec(p1,tec1);
p1->next=p2;
p1->cla=NULL;
in4.num++;
p3->next=p1;
}
}
}
else printf("\n该教师已存在。");
}
}
struct cla * insert_cla1(struct cla cla1) //将课程插入学生
{
struct cla p1,*p2,*p3;
struct stu *p;
p=(struct stu *)head;
while(p->id!=cla1.id&&p->next!=NULL&&p->id
{
p=p->next;
}
if((p->next==NULL&&p->id!=cla1.id)||p->id>cla1.id)
{
printf("\n查无此生!信息没有插入!");
}
else
{
p1=(struct cla)p->cla;
p3=(struct cla*)p->cla;
while(p1!=NULL) //p3为前一个指针 p1为当前地址
{
if(strcmp(p1->name,cla1.name)==0) break;
p3=p1; p1=p1->next;
}
if(p1!=NULL&&strcmp(p1->name,cla1.name)==0)
{
p1->e_score=cla1.e_score;
p1->n_score=cla1.n_score;
p1->t_score=cla1.t_score;
}
else
{
p2=(struct cla*)malloc(sizeof(struct cla));
p2->id=cla1.id;
strcpy(p2->name,cla1.name);
strcpy(p2->stu_name,p->name);
p2->e_score=cla1.e_score;
p2->n_score=cla1.n_score;
p2->t_score=cla1.t_score;
p2->next=NULL;
p2->res=NULL;
if(p3==NULL) p->cla=p2;
else p3->next=p2;
// to make a follow
if(in2.num==0)
{
headc=p2;
clap=p2;
p2->follow=NULL;
in2.num++;
}
else
{
clap->follow=p2;
clap=p2;
p2->follow=NULL;
in2.num++;
}
}
return p2;
}
return NULL;
}
void insert_cla2(struct cla cp)//将课程插入教师
{
struct cla *p1,*p2,*p3;
struct tec *p;
p=(struct tec *)head_tec;
while(strcmp(p->cla_name,cp->name)!=0&&p->next!=NULL)
{
p=p->next;
}
if(p->next==NULL&&strcmp(p->cla_name,cp->name)!=0)
{
printf("\n信息没有插入!");
}
else
{
p1=(struct cla)p->cla;
p3=(struct cla*)p->cla;
while(p1!=NULL)
{
if(p1->id==cp->id) break;
p3=p1;
p1=p1->tec;
}
if(p1!=NULL&&p1->id==cp->id)
{
p1->e_score=cp->e_score;
p1->n_score=cp->n_score;
p1->t_score=cp->t_score;
}
else
{
p2=cp;
p2->tec=NULL;
p2->score=p->score;
if(p3==NULL) p->cla=p2;
else p3->tec=p2;
}
}
}
void insert_res(struct res res1)//插入重修
{
struct stu p;
struct res *p1,*p2,*p4;
struct cla *p3;
p=(struct stu *)head;
while(p->id!=res1.id&&p->next!=NULL&&p->id
{
p=p->next;
}
if((p->next==NULL&&p->id!=res1.id)||p->id>res1.id)
{
printf("\n查无此生!信息没有插入!");
}
else
{
p3=(struct cla)p->cla;
if(p3==NULL)
{
printf("\n该生尚无课程信息!");
}
else
{
while(strcmp(p3->name,res1.name)!=0&&p3->next!=NULL)
{
p3=p3->next;
}
if(p3->next==NULL&&strcmp(p3->name,res1.name)!=0)
{
printf("\n该课程不存在!");
}
else
{
p1=(struct res )p3->res;
p4=(struct res *)p3->res;
while(p1!=NULL)
{
if(p1->times==res1.times) break;
p4=p1;
p1=p1->next;
}
if(p1!=NULL&&p1->times==res1.times)
{
p1->score=res1.score;
}
else
{
p2=(struct res)malloc(sizeof(struct res));
p2->id=res1.id;
strcpy(p2->name,res1.name);
p2->score=res1.score;
p2->semester=res1.semester;
p2->times=res1.times;
p2->next=NULL;
if(p4==NULL) p3->res=p2;
else p4->next=p2;
// to make a follow
if(in3.num==0)
{
headr=p2;
resp=p2;
p2->follow=NULL;
in3.num++;
}
else
{
resp->follow=p2;
resp=p2;
p2->follow=NULL;
in3.num++;
}
}
}
}
}
}
void input_stu() //学生录入
{
struct stu stu1;
printf("\n请输入学生数据,输入0结束输入.");
printf("\n请输入学生ID(8位数字):");
scanf("%d",&stu1.id);
while(stu1.id!=0)
{
//initialize and create
printf("\n请输入学生姓名:");scanf("%s",stu1.name);
printf("\n请输入学生宿舍(五位数字比如08207):");scanf("%d",&stu1.dor);
printf("\n请输入学生班级(2位数字比如01):");scanf("%d",&stu1.clas);
printf("\n请输入学生性别(男或女):");scanf("%s",stu1.sex);
printf("\n请输入学生年龄:");scanf("%d",&stu1.age);
printf("\n请输入学生电话号码(11位手机号码):");scanf("%s",stu1.phone);
printf("\n请输入学生密码:");scanf("%s",stu1.key);
stu1.next=NULL;stu1.cla=NULL;
insert_stu(stu1);
printf("\n请输入学生ID(8位数字):");scanf("%d",&stu1.id);
}
}
void input_tec() //教师录入
{
struct tec tec1;
printf("\n请输入教师数据,输入0结束输入.");
printf("\n请输入教师ID(8位数字):");scanf("%d",&tec1.id);
while(tec1.id!=0)
{
//initialize and create
printf("\n请输入教师姓名:");scanf("%s",tec1.name);
printf("\n请输入教师课程名称:");scanf("%s",tec1.cla_name);
printf("\n请输入教师课程编号:");scanf("%d",&tec1.cla_id);
printf("\n请输入教师性别(男或女):");scanf("%s",tec1.sex);
printf("\n请输入教师电话号码(11位手机号码):");scanf("%s",tec1.phone);
printf("\n请输入教师密码:");scanf("%s",tec1.key);
printf("\n请输入学分:");scanf("%d",&tec1.score);
printf("\n请输入教师email:");scanf("%s",tec1.email);
tec1.next=NULL;tec1.cla=NULL;
insert_tec(tec1);
printf("\n请输入教师ID(8位数字):");scanf("%d",&tec1.id);
}
}
void input_cla() //课程录入
{
struct cla cla1;
struct cla *cp;
printf("\n请输入学生课程数据,输入0结束输入.");
printf("\n请输入学生ID(8位数字):");scanf("%d",&cla1.id);
while(cla1.id!=0)
{
//initialize and create
printf("\n请输入课程姓名:");scanf("%s",cla1.name);
cla1.score=0;
printf("\n请输入课程学生考试成绩:");scanf("%f",&cla1.e_score);
printf("\n请输入课程学生平时成绩:");scanf("%f",&cla1.n_score);
cla1.t_score=0.5*cla1.n_score+0.5*cla1.e_score;
cla1.next=NULL;cla1.res=NULL; cla1.follow=NULL;
cp=insert_cla1(cla1);
insert_cla2(cp);
printf("\n请输入学生ID(8位数字):");scanf("%d",&cla1.id);
}
}
void input_res() //重修录入
{
struct res res1;
printf("\n请输入学生重修数据,输入0结束输入.");
printf("\n请输入学生ID(8位数字):");scanf("%d",&res1.id);
while(res1.id!=0)
{
//initialize and create
printf("\n请输入重修学期:");scanf("%d",&res1.semester);
printf("\n请输入重修课程名称:");scanf("%s",res1.name);
printf("\n请输入重修成绩:");scanf("%f",&res1.score);
printf("\n请输入重修次数:");scanf("%d",&res1.times);
res1.next=NULL;
// res1->next=NULL;
insert_res(res1);
printf("\n请输入学生ID(8位数字):");scanf("%d",&res1.id);
}
}
void copy_stu(struct stu *p1,struct stu stu1)// 用于复制 减少代码量
{
p1->age=stu1.age; p1->id=stu1.id;
p1->dor=stu1.dor;
strcpy(p1->phone,stu1.phone);
strcpy(p1->sex,stu1.sex);
strcpy(p1->key,stu1.key);
strcpy(p1->name,stu1.name);
p1->score=0;
}
void copy_tec(struct tec *p1,struct tec tec1)// 用于复制 减少代码量
{
strcpy(p1->email,tec1.email);
strcpy(p1->cla_name,tec1.cla_name);
p1->cla_id=tec1.cla_id;
strcpy(p1->phone,tec1.phone);
strcpy(p1->sex,tec1.sex);
p1->score=tec1.score;
strcpy(p1->key,tec1.key);
strcpy(p1->name,tec1.name);
}
void modify_stu(struct stu p1)// 学生修改自己信息
{
int z;
system("cls");
printf("\n\t\t\t*************************");
printf("\n\t\t\t**\t修改项目\t**");
printf("\n\t\t\t**************************");
printf("\n\t\t\t**\t(1)年龄 \t**");
printf("\n\t\t\t**\t(2)宿舍 \t**");
printf("\n\t\t\t**\t(3)电话号码\t**");
printf("\n\t\t\t**************************");
printf("\n请输入数字(输入0停止修改):");
scanf("%d",&z);
switch(z)
{
case 0: break;
case 1: printf("请输入年龄:");scanf("%d",&p1->age); fflush(stdin);break;
case 2: printf("请输入宿舍号码:");scanf("%d",&p1->dor); fflush(stdin);break;
case 3: printf("请输入电话号码:");scanf("%s",p1->phone); fflush(stdin);break;
default : printf("\n请正确输入相应数字。");fflush(stdin);break;
}
printf("\n已完成修改。按任意键返回。"); getchar(); getchar();
}
void modify_tec(struct tec *p1)// 教师修改自己信息
{
int z;
system("cls");
printf("\n\t\t\t**************************");
printf("\n\t\t\t**\t修改项目\t**");
printf("\n\t\t\t**************************");
printf("\n\t\t\t**\t(1)学分 \t**");
printf("\n\t\t\t**\t(2)email\t**");
printf("\n\t\t\t**\t(3)电话号码\t**");
printf("\n\t\t\t**************************");
printf("\n请输入数字(输入0停止修改):");
scanf("%d",&z);
switch(z)
{
case 0: break;
case 1: printf("\n请输入新的学分:"); scanf("%d",&p1->score); fflush(stdin);break;
case 2: printf("\n请输入新的email:"); scanf("%s",p1->email); fflush(stdin);break;
case 3: printf("\n请输入新的电话:"); scanf("%s",p1->phone); fflush(stdin);break;
default : printf("\n请正确输入数字。");fflush(stdin);break;
}
printf("\n已完成修改。按任意键返回。"); getchar(); getchar();
}
void modify_stu_adm()//管理员进入某一学生系统 修改学生信息 如密码
{
struct stu *p1;
int id;
int z=0;
p1=head;
system("cls");
printf("\n你好,请输入要修改学生的ID(8位id,输入0停止输入):");
scanf("%d",&id); fflush(stdin);
while(p1!=NULL)
{
if(p1->id>=id) break; //减少检索次数
p1=p1->next;
}
if(p1!=NULL)
{
if(p1->id==id) stu_ui(p1);
}
else
printf("\n学生不存在。");
}
void modify_tec_adm()//管理员进入某一教师系统 修改教师信息 如密码
{
struct tec *p1;
int id;
int z=0;
system("cls");
p1=head_tec;
printf("\n你好,请输入要修改教师的ID(8位id,输入0停止输入):");
scanf("%d",&id);
while(p1!=NULL)
{
if(p1->id>=id) break;
p1=p1->next;
}
if(p1!=NULL)
{
if(p1->id==id) tec_ui(p1);
}
else
printf("该教师不存在。");
}
void del_stu()//删除学生信息
{
struct stu *p1,*p11;
struct cla *p2,*p21,*p22;
struct tec *p3;
int id;
system("cls");
printf("\n请输入要删除学生的ID(8位学号,输入0为停止删除):");
scanf("%d",&id);fflush(stdin);
while(id!=0)
{
p1=head;
while(p1!=NULL)
{
if(p1->id==id) break;
p1=p1->next;
}
if(p1!=NULL)
{
p2=p1->cla;
while(p2!=NULL)
{
p3=head_tec;
while(p3!=NULL)
{
p21=p3->cla;
if(strcmp(p3->cla_name,p2->name)==0)
{
while(p21!=NULL)
{
if(p21->id==p2->id) break;
p21=p21->tec;
}
}
if(p21!=NULL&&p21->id==p2->id) break;
p3=p3->next;
}
p22=p2->next;
if(p3!=NULL)
{
pfree_cla(p1,p3,(*p2));
}
p2=p22;
}
printf("\n成功删除该生信息.");
}
p1=p11=head;
while(p1!=NULL) //释放stu内存
{
if(p1->id==id)
{
if(p1==p11) head=p1->next;
else
p11->next=p1->next;
free(p1);
in1.num--;
break;
}
p11=p1; p1=p1->next;
}
printf("\n请输入要删除学生的ID(8位学号,输入0为停止删除):");
scanf("%d",&id);
}
}
void del_tec()//删除教师信息
{
struct tec *p1,*p11;
struct cla *p2,*p21;
struct stu *p3;
int id;
system("cls");
printf("\n请输入要删除教师的ID(8位学号,输入0为停止删除):");
scanf("%d",&id);fflush(stdin);
while(id!=0)
{
p1=head_tec;
while(p1!=NULL)
{
if(p1->id==id) break;
p1=p1->next;
}
if(p1!=NULL)
{
p2=p1->cla;
while(p2!=NULL)
{
p3=head;
while(p3!=NULL)
{
if(p3->id==p2->id) break;
p3=p3->next;
}
p21=p2->tec;
if(p3!=NULL)
{
pfree_cla(p3,p1,(*p2));
}
p2=p21;
}
}
p1=p11=head_tec;
while(p1!=NULL)
{
if(p1->id==id)
{
if(p1==p11) head_tec=p1->next;
else p11->next=p1->next;
free(p1);
in4.num--;
break;
}
p11=p1; p1=p1->next;
}
printf("\n请输入要删除教师的ID(8位学号,输入0为停止删除):");
scanf("%d",&id);
}
}
void del_res()//删除重修信息
{
struct res res1;
struct cla *p;
system("cls");
printf("please input the id of stu");
scanf("%d",&res1.id);fflush(stdin);
printf("please input the name of course");
scanf("%s",res1.name);fflush(stdin);
printf("please input the times of res");
scanf("%d",&res1.times);fflush(stdin);
while(res1.id!=0)
{
p=headc;
while(p!=NULL)
{
if(strcmp(res1.name,p->name)==0&&p->id==res1.id)
{
pfree_res(p,res1);
break;
}
p=p->follow;
}
printf("请输入学生id");
scanf("%d",&res1.id);
printf("输入课程名称");
scanf("%s",res1.name);
printf("输入重修次数");
scanf("%d",&res1.times);
}
}
void pfree_cla(struct stu *p_stu,struct tec *p_tec,struct cla cla1)//解锁及释放课程内存
{
struct cla *p2,*p21;
struct res *p3,*p31;
p2=p21=p_stu->cla;
while(p2!=NULL)
{
if(strcmp(p2->name,cla1.name)==0)
{
p3=p2->res; // unlock res
while(p3!=NULL)
{
p31=p3->next;
pfree_res(p2,(*p3));
p3=p31;
}
if(p2==p21)
{
p_stu->cla=p2->next;
}
else
{
p21->next=p2->next;
}
break;
}
p21=p2; p2=p2->next;
}
p2=p21=p_tec->cla;
while(p2!=NULL)
{
if(p2->id==cla1.id)
{
if(p2==p21)
{
p_tec->cla=p2->tec;
}
else
{
p21->tec=p2->tec;
}
break;
}
p21=p2; p2=p2->tec;
}
p2=p21=headc;
while(p2!=NULL)
{
if(p2->id==cla1.id&&strcmp(p2->name,cla1.name)==0)
{
if(p2=p21)
{
headc=p2->follow;
}
else
{
p21->follow=p2->follow;
}
free(p2);
in2.num--;
break;
}
p21=p2; p2=p2->follow;
}
}
void pfree_res(struct cla *p,struct res res1)//解锁及释放重修内存
{
struct res *p2,*p21;
p2=p21=p->res;
while(p2!=NULL)
{
if(p2->times==res1.times)
{
if(p2==p21)
{
p->res=p2->next;
}
else
{
p21->next=p2->next;
}
break;
}
p21=p2; p2=p2->next;
}
p2=p21=headr;
while(p2!=NULL)
{
if(p2->times==res1.times&&p2->id==res1.id&&strcmp(p2->name,res1.name)==0)
{
if(p2==p21)
{
headr=p2->follow;
}
else
{
p21->follow=p2->follow;
}
free(p2);
in3.num--;
break;
}
p21=p2;p2=p2->next;
}
}
void skim_stu(struct stu *head) //按ID或名字查看学生信息
{
char id[9];
int id1;
struct stu *p1;
system("cls");
if(head==NULL)
{
printf("\n目前无学生数据,请返回录入.\n");
}
else
{
printf("\n请输入要查询的学生ID或姓名(8位数字或者汉字,输入0停止查询):");
scanf("%s",&id);
while(id[0]!='0')
{
p1=(struct stu *)head;
if(strlen(id)==8)
{
id1=idc(id);
while(p1->id!=id1&&p1->next!=NULL&&p1->id
{
p1=p1->next;
}
if((p1->next==NULL&&p1->id!=id1)||p1->id>id1)
{
printf("\n查无此生!请重新输入学生ID(8位数字,输入0停止查询):");
scanf("%s",id);
}
else
{
print_stu(p1);
printf("\n继续查询请再次输入学生ID或姓名(8位数字或者汉字,输入0停止查询):");
scanf("%s",id);
}
}
else
{
while(strcmp(id,p1->name)!=0&&p1!=NULL)
{
p1=p1->next;
}
if(strcmp(id,p1->name)==0)
{
print_stu(p1);
printf("\n继续查询请再次输入学生ID或姓名(8位数字或者汉字,输入0停止查询):");
scanf("%s",id);
}
else
{
printf("\n查无此生!请重新输入学生ID(8位数字,输入0停止查询):");
scanf("%s",id);
}
}
}
}
}
void skim_tec(struct tec *head)//按id或名字查看教师
{
int id1;
char id[9];
struct tec *p1;
system("cls");
if(head==NULL)
{
printf("\n目前无教师数据,请返回录入.\n");
}
printf("\n请输入要查询的教师ID或名字(8位数字或汉字,输入0停止查询):");
scanf("%s",id);
while(id[0]!='0')
{
p1=(struct tec *)head;
if(strlen(id)==8)
{
id1=idc(id);
while(p1->id!=id1&&p1->next!=NULL&&p1->id
{
p1=p1->next;
}
if(id1=p1->id)
{
printf("\n------------------------------------------------------------");
printf("\n名字>>>性别>课程名称>>>>>>课程编号>>>学分>>>手机号码>>>>>>>>email>>>>>>>");
printf("\n------------------------------------------------------------");
printf("\n%s %s %s %d %d %s %s",p1->name,p1->sex,p1->cla_name,p1->cla_id,p1->score,p1->phone,p1->email);
printf("\n继续查询请再次输入教师ID或名字(8位数字或汉字,输入0停止查询):");
scanf("%s",id);
}
else
{
printf("\nno data!请重新输入教师ID或名字(8位数字或汉字,输入0停止查询):");
scanf("%s",id);
}
}
else
{
while(strcmp(id,p1->name)!=0&&p1!=NULL)
{
p1=p1->next;
}
if(strcmp(id,p1->name)==0)
{
printf("\n------------------------------------------------------------");
printf("\n名字>>>性别>课程名称>>>>>>课程名称>>>学分>>>手机号码>>>>>>>>email>>>>>>>");
printf("\n------------------------------------------------------------");
printf("\n%s %s %s %d %d %s %s",p1->name,p1->sex,p1->cla_name,p1->cla_id,p1->score,p1->phone,p1->email);
printf("\n继续查询请再次输入教师ID或名字(8位数字或汉字,输入0停止查询):");
scanf("%s",id);
}
else
{
printf("\nno data!请重新输入教师ID或名字(8位数字或汉字,输入0停止查询):");
scanf("%s",id);
}
}
}
getchar(); getchar();
}
void skim_stu_all()//查看所有学生学分及不及格课程
{
struct stu *p1;
struct cla *p2;
system("cls");
p1=head;
printf("\n-----------------------------------------------------------------------");
printf("\nID>>>>>>>>>学生姓名>>>>>>>学分>>不及格课程>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
printf("\n-----------------------------------------------------------------------");
while(p1!=NULL)
{
p1->score=score_stu(p1);
printf("\n%d %s \t %d",p1->id,p1->name,p1->score);
p2=p1->cla;
while(p2!=NULL)
{
if(p2->e_score<60&&p2->e_score!=0)
printf(" %s ",p2->name);
p2=p2->next;
}
p1=p1->next;
}
getchar(); getchar();
}
void skim_tec_all()//查看所有教师
{
struct tec *p1;
system("cls");
p1=head_tec;
printf("\n-------------------------------------------------------------------");
printf("\n教师姓名>>>>>>>>>课程名称>>>>>>>>课程编号>>>>>>>>>>>>>>>>>>>>>>>>>>>");
printf("\n-------------------------------------------------------------------");
while(p1!=NULL)
{
printf("\n%-10s \t %-10s \t %-10d",p1->name,p1->cla_name,p1->cla_id);
p1=p1->next;
}
getchar(); getchar();
}
void skim_stu_course() // 根据课程查看学生 管理员功能
{
struct tec *p;
struct cla *p1;
struct res *p2;
int coursenumber;
char course[12];
int z=0;
p=head_tec;
system("cls");
printf("\n请输入课程编号+课程名称:"); // 课程名与教师一一对应
scanf("%d%s",&coursenumber,course);fflush(stdin);
while(p!=NULL)
{
if(p->cla_id==coursenumber)
{
p1=p->cla;
printf("\n---------------------------------------------------------------------");
printf("\n学生ID>>学生姓名>>考试成绩>>>>平时成绩>>>>综合成绩>>>>重修成绩>>>>>>>>>>>>>");
printf("\n---------------------------------------------------------------------");
while(p1!=NULL)
{
if(p->cla_id==coursenumber) //输出所有选同一课程的学生
{
printf("\n%d \t %s %.2f \t %.2f \t %.2f \t",p1->id,p1->stu_name,p1->e_score,p1->n_score,p1->t_score);
if(p1->res!=NULL)
{
p2=p1->res;
z=1;
while(p2!=NULL)
{
printf("(%d)%.2f ",z++,p2->score);
p2=p2->next;
}
}
else
printf("无重修");
z=1; //用来判断有无学生输出
}
p1=p1->tec;
}
}
p=p->next;
}
if(z==0)
{printf("\n无该课程信息");}
getchar(); getchar();
}
void skim_stu_class() // 根据班级查看学生 管理员功能
{
struct stu *p1;
struct cla *p2;
int id1,id2;
int n=0;
p1=head;
system("cls");
printf("\n请输入班级编号(学号后四位如0526):");
scanf("%d",&id1);fflush(stdin);
id1=(int)(id1/100);
id1=id1*100+20160000; id2=id1+100; //取学号范围确定班级
printf("\n-------------------------------------------------------------------");
printf("\n学生姓名>>>所选课程(考试成绩)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
printf("\n-------------------------------------------------------------------");
while(p1!=NULL)
{
if(p1->idid>id1) //寻找同一班级的同学
{
printf("\n%s\t",p1->name);
p2=p1->cla;
while(p2!=NULL)
{
printf(" %s(%.2f)",p2->name,p2->e_score);
p2=p2->next;
}
n=1; // 有班级存在 n作为判断数
}
p1=p1->next;
}
if(n==0)
printf("\n无该班级信息");
getchar(); getchar();
}
void skim_list_stu(struct tec * p) //教师查看所有选自己课的学生
{
struct cla *p3;
struct order *p11,*p1,*head;
struct res *p2;
int z;
p1=list(p->cla);
head=p1;
system("cls");
while(p1!=NULL)
{
p3=p1->pointer;
printf("\n---------------------------------------------------------------------");
printf("\n学生ID>>学生姓名>>考试成绩>>平时成绩>>综合成绩>>>>重修成绩>>>>>>>>>>>>>");
printf("\n---------------------------------------------------------------------");
printf("\n%d %s %.2f \t %.2f \t %.2f \t",p3->id,p3->stu_name,p3->e_score,p3->n_score,p3->t_score);
if(p3->res!=NULL)
{
p2=p3->res;
z=1;
while(p2!=NULL)
{
printf("(%d)%.2f ",z++,p2->score);
p2=p2->next;
}
}
else
printf("无重修");
p1=p1->next;
}
p1=head;
while(p1!=NULL)
{
p11=p1;
p1=p1->next;
free(p11);
}
getchar(); getchar();
}
struct order * list(struct cla head)// 学生分数排序 返回链表头 to make a list of stu
{
struct order *p1=NULL,*p2,*p3,*p4;
struct cla *p;
p=head;
while(p!=NULL)
{
if(p1==NULL)//the head
{
p2=(struct order)malloc(sizeof(struct order));
p2->pointer=p;
p2->next=NULL;
p1=p2;
}
else
{
if(p->e_score>p1->pointer->e_score)
{
p2=(struct order*)malloc(sizeof(struct order));
p2->pointer=p;
p2->next=p1;
p1=p2;
}
else
{
p3=p1;
while(p3!=NULL)
{
if(p->e_score>p3->pointer->e_score) break;
p4=p3; p3=p3->next;
}
p2=(struct order*)malloc(sizeof(struct order));
p2->pointer=p;
if(p3==NULL) p2->next=NULL;
else p2->next=p3;
p4->next=p2;
}
}
p=p->tec;
}
return p1;
}
void print_stu(struct stu* p1) //输出学生
{
struct cla p2;
struct res *p3;
printf("\n------------------------------------------------------------");
printf("\nID\t>>名字>>>性别>年龄>宿舍>>>>手机号码>>>>>>>>>");
printf("\n------------------------------------------------------------");
printf("\n%d %s %s %d %d %s",p1->id,p1->name,p1->sex,p1->age,p1->dor,p1->phone);
if(p1->cla==NULL)
{
printf("\n暂无选课信息!");
}
else
{
p2=(struct cla)p1->cla;
printf("\n------------------------------------------------------------");
printf("\n课程名称>>>学分>>考试成绩>>平时成绩>>综合成绩>>>>");
printf("\n------------------------------------------------------------");
while(p2!=NULL)
{
printf("\n%-12s %d %.2f %.2f %.2f ",p2->name,p2->score,p2->e_score,p2->n_score,p2->t_score);
if(p2->e_score
{
p2->t_score=p2->e_score;
}
else p2->t_score=(p2->e_score+p2->n_score)*0.5;
if(p2->res==NULL)
{
printf("该课程无重修.");
}
else
{
p3=(struct res *)p2->res;
while(p3!=NULL)
{
printf("\n------------------------------------------------------------");
printf("\n重修学期>>>分数>>重修次数>>>>");
printf("\n------------------------------------------------------------");
printf("\n%d %.2f %d",p3->semester,p3->score,p3->times);
p3=p3->next;
}
}
p2=p2->next;
}
}
getchar();getchar();
}
struct info2 Rfile2(struct info2 *head_note)
{
FILE *fr,*fw;
char note[500];
char name[20];
char reply[500];
char ch;
int i,replied=0;
struct info2 *p2,*p1;
fr=fopen("note.txt","r");
if(fr==NULL)
{
fw=fopen("note.txt","w");
fr=fopen("note.txt","r");
}
while((ch=fgetc(fr))!=EOF)
{
fseek(fr,-1,SEEK_CUR);
p1=(struct info2)malloc(sizeof(struct info2));
fscanf(fr,"%d%s%s\n",&i,name,note);
p1->i=i;
strcpy(p1->name,name);
strcpy(p1->note,note);
p1->next=NULL;
if(head_note==NULL) head_note=p1;
else p2->next=p1;
p2=p1;
}
return head_note;
}
void Savenote(struct info2 *head_note)
{
struct info2 *sp1=head_note;
FILE *fps;
fps=fopen("note.txt","w");
if(fps==NULL)
printf("\t\t\t\t\n保存失败!\n");
while(sp1)
{
fprintf(fps,"%d %s %s\n",sp1->i,sp1->name,sp1->note);
sp1=sp1->next;
}
printf("\t\t\t\t\n保存成功!\n\n");
}
struct info2 *First2(struct info2 *head_note)
{
struct info2 *p;
char name[20]; //使用者名称
char note[500]; //用途
printf(" \t\t\t\t请输入你的姓名:\n");
scanf("%s",name);
printf(" \t\t\t\t请输入你的留言:\n");
scanf("%s",note);
p=(struct info2*)malloc(sizeof(struct info2));
strcpy(p->name,name);
p->i=1;
strcpy(p->note,note);
p->next=NULL;
head_note=p;
Savenote(head_note);
return head_note;
}
void watchall(struct info2 *head_note)
{
struct info2 *np1=head_note;
if(np1==NULL)
{
printf(" \n\t\t\t\t没有留言信息!\n");
}
while(np1)
{
printf(" \n \t\t\t\t[%d] %s: %s\n\n",np1->i,np1->name,np1->note);
np1=np1->next;
}
printf(" \n \t\t\t\t以上是全部留言!\n");
}
struct info2 leavenote(struct info2 *head_note)
{
struct info2 *p,*p1,*p2;
char note[500];
char name[20];
int i=1;
p2=head_note;
while(p2)
{
p1=p2;
p2=p2->next;
i++;
}
printf("\n\t\t\t\t请输入你的姓名:");
scanf("%s",name);
printf("\n\t\t\t\t请输入你的留言:");
scanf("%s",note);
p=(struct info2)malloc(sizeof(struct info2));
p->i=i;
strcpy(p->note,note);
strcpy(p->name,name);
p1->next=p;
p->next=NULL;
Savenote(head_note);
}
struct info2 *notesys(struct info2 *head_note)
{
int flag=1;
struct info2 *np1;
np1=head_note;
int choice=0;
system("cls");
while(flag)
{
printf("\t\t\t\t ┏━━━━━━━━┳━━━━━━━━┓\n");
printf("\t\t\t\t ┃[1]查看全部信息 ┃[2]留言 ┃\n");
printf("\t\t\t\t ┣━━━━━━━━╋━━━━━━━━┫\n");
printf("\t\t\t\t ┃ [0]退出留言系统 ┃\n");
printf("\t\t\t\t ┗━━━━━━━━┻━━━━━━━━┛\n\n");
printf("\t\t\t\t 请输入操作编号:");
scanf("%d",&choice);
switch(choice)
{
case 1:
watchall(head_note);
break;
case 2:
{
if(head_note==NULL)
head_note=First2(head_note);
else
leavenote(head_note);
break;
}
case 0:
flag=0;
break;
default:
printf("\n\t\t\t\t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
printf("\n\t\t\t\t┃请输入正确编号!┃\n");
printf("\n\t\t\t\t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
break;
}
}
}
void stu_ui(struct stu *p)//学生界面
{
int z;
system("cls");
struct info2 *head_note=NULL;
head_note=Rfile2(head_note);
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ %s,欢迎你 |\n",p->name);
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----修改个人信息 |\n");
printf("\t\t\t+ [2]----选 课 |\n");
printf("\t\t\t+ [3]----查询课程信息 |\n");
printf("\t\t\t+ [4]----修改密码 |\n");
printf("\t\t\t+ [5]----留言 |\n");
printf("\t\t\t+ [0]----返回主界面 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 :break;
case 1 :modify_stu(p);break;
case 2 :select_s(p);break;
case 3 :print_stu(p);break;
case 4 :st_key_stu(p);break;
case 5 :notesys(head_note);break;
default:printf("\n无效选项!");
}
}while(z!=0);
}
void tec_ui(struct tec *p)//教师界面
{
int z;
system("cls");
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ %s,欢迎您。 |\n",p->name);
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----修改个人信息 |\n");
printf("\t\t\t+ [2]----登记学生分数 |\n");
printf("\t\t\t+ [3]----查看所有学生 |\n");
printf("\t\t\t+ [4]----按学号查看学生 |\n");
printf("\t\t\t+ [5]----修改密码 |\n");
printf("\t\t\t+ [0]----返回主界面 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 : break;
case 1 :modify_tec(p);break;
case 2 :tec_score(p);break;
case 3 :skim_list_stu(p);break;
case 4 :stu_score(p); break;
case 5 :st_key_tec(p); break;
default:printf("\n无效选项!");
}
}while(z!=0);
}
void adm_ui_1()//管理员界面1
{
int z;
system("cls");
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ 管理员 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----录入学生信息 |\n");
printf("\t\t\t+ [2]----录入教师信息 |\n");
printf("\t\t\t+ [3]----录入选课信息 |\n");
printf("\t\t\t+ [4]----录入重修信息 |\n");
printf("\t\t\t+ [5]----查询学生信息 |\n");
printf("\t\t\t+ [6]----查询教师信息 |\n");
printf("\t\t\t+ [7]----删除学生信息 |\n");
printf("\t\t\t+ [8]----删除教师信息 |\n");
printf("\t\t\t+ [9]----下一页 |\n");
printf("\t\t\t+ [0]----退出系统 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 : break;
case 1 :input_stu();break;
case 2 :input_tec();break;
case 3 :input_cla();break;
case 4 :input_res(); break;
case 5 :skim_stu(head); break;
case 6 :skim_tec(head_tec); break;
case 7 :del_stu(); break;
case 8 :del_tec();break;
case 9 :adm_ui_2();break;
default:printf("\n无效选项!");
}
}
while(z!=0);
}
void adm_ui_2()//管理员界面2
{
int z;
system("cls");
do
{
printf("\n\t\t\t--------------------------------\n");
printf("\t\t\t+ 管理员 |\n");
printf("\t\t\t--------------------------------\n");
printf("\t\t\t+ [1]----删除重修信息 |\n");
printf("\t\t\t+ [2]----修改学生信息 |\n");
printf("\t\t\t+ [3]----修改教师信息 |\n");
printf("\t\t\t+ [4]----按课程查看学生 |\n");
printf("\t\t\t+ [5]----按班统计学生 |\n");
printf("\t\t\t+ [6]----统计所有学生信息 |\n");
printf("\t\t\t+ [7]----统计所有教师信息 |\n");
printf("\t\t\t+ [8]----管理员密码修改 |\n");
printf("\t\t\t+ [0]---- 上一页 |\n");
printf("\t\t\t--------------------------------\n");
printf("请输入您的选择:");
scanf("%d", &z);
switch(z)
{
case 0 : break;
case 1 :del_res();break;
case 2 :modify_stu_adm(); break;
case 3 :modify_tec_adm(); break;
case 4 :skim_stu_course(); break;
case 5 :skim_stu_class(); break;
case 6 :skim_stu_all(); break;
case 7 :skim_tec_all();break;
case 8 :adm_key();break;
default:printf("\n无效选项!");
}
}
while(z!=0);
}
void key_stu()//学生ID与密码验证
{
int z=0;
z<=2;
char key1[11];
int id;
struct stu p;
do
{
printf("\n\t\t\t|&|************学生登录*************|&|");
printf("\n\t\t\t|&|----------------------------------|&|");
printf("\n\t\t\t|&| .--. |&|");
printf("\n\t\t\t|&| /.-. '--------------. |&|");
printf("\n\t\t\t|&| \'-' .--''--'' -''-' |&|");
printf("\n\t\t\t|&| '--' |&|");
printf("\n\t\t\t|&|----------------------------------|&|");
printf("\n请输入学生ID(8位数字):");
scanf("%d",&id); fflush(stdin);
printf("\n请输入密码(10位以内):");
key(key1);fflush(stdin);
p=head;
while(p!=NULL)
{
if(p->id>=id) break;
p=p->next;
}
if(p!=NULL)
{
if(strcmp(p->key,key1)==0)
{
stu_ui(p); break;
}
else
{
z++;
printf("\n账号或密码有误,请重新输入(你还有%d次机会):",2-z);
printf("\n请输入密码(10位以内):");
key(key1);fflush(stdin);
if(strcmp(p->key,key1)==0)
{
stu_ui(p); break;
}
}
}
else
{
printf("该生不存在。"); break;
}
}while(z!=2);
}
void key_tec()//教师ID与密码验证
{
int z=0;
z<=2;
char key1[11];
int id;
struct tec p;
system("cls");
do
{
printf("\n\t\t\t|&|************教师登录*************|&|\t");
printf("\n\t\t\t|&|----------------------------------|&|\t");
printf("\n\t\t\t|&| .--. |&|\t");
printf("\n\t\t\t|&| /.-. '--------------. |&|\t");
printf("\n\t\t\t|&| \'-' .--''--'' -''-' |&|\t");
printf("\n\t\t\t|&| '--' |&|\t");
printf("\n\t\t\t|&|----------------------------------|&|\t");
printf("\n请输入教师ID(8位数字):");
scanf("%d",&id); fflush(stdin);
printf("\n请输入密码(10位以内):");
key(key1);fflush(stdin);
p=head_tec;
while(p!=NULL)
{
if(p->id>=id) break;
p=p->next;
}
if(p!=NULL)
{
if(strcmp(p->key,key1)==0)
{
tec_ui(p); break;
}
else
{
z++;
printf("\n账号或密码有误,请重新输入(你还有%d次机会):",2-z);
printf("\n请输入密码(10位以内):");
key(key1);fflush(stdin);
if(strcmp(p->key,key1)==0)
{
tec_ui(p); break;
}
}
}
else
{
printf("\n对不起,该ID不存在,请查证后再输入。");
break;
}
}while(z!=2);
}
void key_adm()//管理员密码验证 只要密码
{
int z=0;
char key1[11];
system("cls");
do
{
printf("\n\t\t\t|&|*************管理员登录***********|&|\t");
printf("\n\t\t\t|&|----------------------------------|&|\t");
printf("\n\t\t\t|&| .--. |&|\t");
printf("\n\t\t\t|&| /.-. '--------------. |&|\t");
printf("\n\t\t\t|&| \'-' .--''--'' -''-' |&|\t");
printf("\n\t\t\t|&| '--' |&|\t");
printf("\n\t\t\t|&|----------------------------------|&|\t");
printf("\n请输入密码(10位以内):");
key(key1);
if(strcmp(in1.key,key1)==0||strcmp(in2.key,key1)==0)
{
adm_ui_1(); break;
}
else
{
z++;
printf("\n密码错误请重新输入(你还有%d次机会):",2-z);
}
}while(z!=2);
}
void st_key_stu(struct stu *p)//学生密码修改
{
char key1[11],key2[11];
int z=1;
system("cls");
do
{
printf("\n请输入新密码:");
key(key1); fflush(stdin);
printf("\n请再次输入新密码:");
key(key2); fflush(stdin);
if(strcmp(key1,key2)==0)
{
strcpy(p->key,key1); printf("\n密码修改成功!");break;
}
else
{
printf("\n两次密码不一致,请重新输入,不再修改请输入0,继续修改请输入任何其余值.");
scanf("%d",&z); fflush(stdin);
}
}while(z!=0);
}
void st_key_tec(struct tec *p)// 教师密码修改
{
char key1[11],key2[11];
int z=1;
system("cls");
do
{
printf("\n请输入新密码:");
key(key1); fflush(stdin);
printf("\n请再次输入新密码:");
key(key2); fflush(stdin);
if(strcmp(key1,key2)==0)
{
strcpy(p->key,key1); printf("\n密码修改成功!"); break;
}
else
{
printf("\n两次密码不一致,请重新输入,不再修改请输入0,继续修改请输入任何其余值.");
scanf("%d",&z); fflush(stdin);
}
}while(z!=0);
}
void adm_key()//管理员密码修改
{
int z=0;
char key0[11],key1[11],key2[11];
system("cls");
do
{
printf("\n请输入原密码(10位以内):");
key(key0); fflush(stdin);
if(strcmp(in1.key,key0)==0||strcmp(in2.key,key0)==0)
{
break;
}
else
{
z++;
printf("\n密码错误请重新输入(你还有%d次机会).",5-z);
}
}while(z!=5);
if(z!=5)
{
do
{
printf("\n请输入新密码:");
key(key1); fflush(stdin);
printf("\n请再次输入新密码:");
key(key2); fflush(stdin);
if(strcmp(key1,key2)==0)
{
strcpy(in1.key,key1); break;
}
else
{
printf("\n两次密码不一致,请重新输入,不再修改请输入0,继续修改请输入1.");
scanf("%d",&z);
}
}while(z!=0);
}else exit(0);
}
void key(char *key)//以星号形式接受密码并放到地址key上
{
int i=0,j=0;
char c;
for(;;)
{
c=getch();
if(j==0)
{
if((int)c==13)
{
printf("\n哦,不,你必须输入密码,这是规则!");
printf("\n请输入密码:");
}
else if((int)c==8) *key='\0';
else
{
j=1;*key=c;key++;i++;
printf("*");
}
}
else
{
if(i>=29 && (int)c!=13 && (int)c != 8 )
{
*key='\0';
}
else if((int)c==8)
{
if(i>0)
{
i--;
key--;
*key='\0';
printf("\b");printf(" ");printf("\b");
}
else
{
j=0;
*key='\0';
}
}
else if((int)c==13)
{
break;
}
else
{
*key=c;
key ++;
i++;
printf("*");
}
}
}
*key='\0';
printf("\n");
}
void stu_score(struct tec * p) //教师查看学生分数 按id
{
struct cla *p1;
struct res *p2;
int id;
int z=1;
system("cls");
printf("\n请输入学生ID:");
scanf("%d",&id);fflush(stdin);
do
{
p1=p->cla;
while(p1!=NULL)
{
if(p1->id==id) break;
p1=p1->tec;
}
if(p1!=NULL)
{
printf("\n---------------------------------------------------------------------");
printf("\n学生ID>>>>学生姓名>>考试成绩>>>>平时成绩>>>>综合成绩>>>>重修成绩>>>>>>");
printf("\n---------------------------------------------------------------------");
printf("\n%d %s %.2f \t %.2f \t %.2f \t %.2f \t",p1->id,p1->stu_name,p1->e_score,p1->n_score,p1->t_score);
p2=p1->res;
while(p2!=NULL)
{
printf("(%d)%d ",p2->times,p2->score);
p2=p2->next;
}
z=0;
getchar();
}
else
{
printf("\n找不到该学生!请重新输入ID(或者输入0结束查询):");
scanf("%d",&id);
}
}while(id!=0&&z!=0);
}
void tec_score(struct tec * head) //give score to someone 教师给分
{
struct cla *p;
int id;
p=head->cla;
system("cls");
if(p==NULL)
{
printf("\n还没有学生选择你的课程。");
}
else
{
skim_list_stu(head);
do
{
printf("\n请输入学生的ID:");
scanf("%d",&id);
while(id!=0)
{
while(p!=NULL)
{
if(p->id!=id)
{p=p->tec; continue;}
else
{
printf("\n请输入学生的分数(考试成绩 平时成绩):");
scanf("%f",&p->e_score);
scanf("%f",&p->n_score);
if(p->e_score
{
p->t_score=p->e_score;
}
else
{
p->t_score=0.5*p->n_score+0.5*p->e_score;
}
printf("\n成功登记分数。");
break;
}
}
printf("\n请输入学生的ID(不再登记请输入0):");
scanf("%d",&id);
}
}while(id!=0);
}
}
int score_stu(struct stu* p) // 计算学生学分
{
int z=0;
struct cla *p1;
struct res *p2;
p1=p->cla;
while(p1!=NULL)
{
if(p1->e_score>=60)
z+=p1->score;
else
{
p2=p1->res;
if(p2!=NULL)
{
while(p2!=NULL)
{
if(p2->score>=60)
z=z+p1->score;
p2=p2->next;
}
}
}
p1=p1->next;
}
return z;
}
void select_s(struct stu * p) //学生选课选修
{
struct tec p1;
struct cla cla1;
struct cla *cp;
p1=head_tec;
system("cls");
printf("\n\t\t\t------------------------------------------");
printf("\n\t\t\t**************课程列表*******************");
printf("\n\t\t\t------------------------------------------");
printf("\n\t\t\t教师>>>>学分>>>>>课程名称>>>>>>>课程编号>>");
printf("\n\t\t\t------------------------------------------");
while(p1!=NULL)
{
printf("\n\t\t\t%s \t%d\t%-10s\t%-10d",p1->name,p1->score,p1->cla_name,p1->cla_id);
p1=p1->next;
}
printf("\n\t\t\t------------------------------------------");
printf("\n请输入你要选的课程编号+课程名称(输入0返回学生主页):");
scanf("%d%s",&cla1.id,cla1.name);
if(cla1.name[0]!='0'&&cla1.id!=0)
{
cla1.id=p->id;
cla1.e_score=0;
cla1.n_score=0;
cla1.t_score=0;
cla1.score=0;
cp=insert_cla1(cla1);
insert_cla2(cp);
printf("\n选课成功!");
}
getchar();
}
int idc(char id) //id装换 char 到int
{
int z=0;
int i=0;
int l,n=1;
l=strlen(id);
for(i=0;i<l;i++)
{
n=10;
}
i=0;
n/=10;
while(id[i]!='\0')
{
z=z+((int)id[i]-48)*n;
i++;
n/=10;
}
return z;
}