目录
一、需求与分析
1. 项目概述
1.1 教师信息处理
1.2 教师工作量数据处理:
1.3 教师综合信息输出
2. 需求分析
3. 模块设计
3.1 功能模块
3.2 所有功能模块的流程图
二、设计与实现
1. 程序设计
1.1 教师工作量管理系统
1.2 登录系统
1.3 主函数
2. 程序实现
2.1 登录系统
2.2 教师工作量管理系统
一、需求与分析
1. 项目概述
计算每个老师在一个学期中所教课程的总工作量。(教师单个教学任务的信息为:教师号、姓名、性别、职称、认教课程、班级、班级数目、理论课时、实验课时、单个教学任务总课时)
1.1 教师信息处理
(1) 输入教师授课教学信息,包括教师号、姓名、性别、职称、认教课程、班级、班级数目、理论课时、实验课时。
(2) 插入(修改)教师授课教学信息:
(3) 删除教师授课教学信息:
(4) 浏览教师授课教学信息:
1.2 教师工作量数据处理:
(1) 计算单个教学任务总课时。计算原则如下表:
班级数目 | 单个教学任务总课时 |
2 | 1.5*(理论课时+实验课时) |
3 | 2*(理论课时+实验课时) |
>=4 | 2.5*(理论课时+实验课时) |
(2) 计算一个教师一个学期总的教学工作量。总的教学工作量=所有单个教学任务总课时之和。
(3)教师数据查询:
提示:输入教师号或其他信息,即读出所有数据信息,并显示出来。
1.3 教师综合信息输出
提示:输出教师信息到屏幕
2. 需求分析
高校教师工作量管理系统可以促进高校教学管理工作的顺利进行,推动教学质量的提升。该程序的主要功能包括教师号、姓名、性别、职称、课程、班级、班级数目、理论课时、实验课时的增删改查。
3. 模块设计
3.1 功能模块
根据课程设计题目的功能要求,各个功能模块的组成框图如下:
3.2 所有功能模块的流程图
二、设计与实现
1. 程序设计
1.1 教师工作量管理系统
teacher结构体数组主要用于储存教师单节课程的主要信息包含教师号、姓名、性别、职称、认教课程、班级、班级数目、理论课时、实验课时、单个教学任务总课时;
struct teacher {
char name[20];//教师姓名
char sex[20];//教师性别
char num[20];//教师号
char flag[20];//教师职称
char course[20];//教师所教课程
char classes[100];//教师所教班级
int classnum;//教师所教班级数量
int lilun;//理论课时
int shiyan;//实验课时
double all;//单个教学任务总课时
}teacher;
names结构体数组主要用于储存不重复的教师姓名、教师总工作量以及教师人数
struct names {
char na[20];
double sum;
int num;
}names;
User结构体,用于储存注册者的姓名,id,性别以及密码
typedef struct User
{
char id[15];
char paw[20];
char name[15];
char sex[5];
}Users;
以下是一些用到的函数:
int Login();//普通用户登录
int Regist();//普通用户注册
int Change();//普通用户更改密码
int found();//普通用户找回密码
int Logins();//管理员登录
int Regists();//管理员注册
int Changes();//管理员更改密码
int founds();//管理员找回密码
int change();//更改教师信息
int put();//增加教师信息
int find();//查找教师信息
int cut();//删除教师信息
void show();//展示所有教师信息
/*结构体初始化*/
void init(struct teacher* tc)
{
memset(tc->name, '\0', sizeof tc->name); //memset以字节单位将结构体初始化,在这里将结构体都初始化为空字节
memset(tc->sex, '\0', sizeof tc->sex); //memset函数属于string.h头文件
memset(tc->num, '\0', sizeof tc->num);
memset(tc->flag, '\0', sizeof tc->flag);
memset(tc->course, '\0', sizeof tc->course);
memset(tc->classes, '\0', sizeof tc->classes);
}
/*将文件中的信息传入结构体数组*/
struct teacher* load()
{
FILE* fp;
if ((fp = fopen("jiaoshi.dat", "r")) == NULL){ //fopen函数 "r"以只读方式打开文件 fopen属于stdio.h头文件
printf("ERROR!\n");
return NULL;
}
fseek(fp, 0, 2);
int m = ftell(fp);
fseek(fp, 0, 0);
n = (int)(m / sizeof(struct teacher));
if (!n){
printf("没有老师信息!\n");
return NULL;
}
struct teacher* tc = (struct teacher*)malloc(m);
for (int i = 0;i < n;i++){
init(tc + i);
fread(tc + i, sizeof(struct teacher), 1, fp);
}
fclose(fp);
return tc;
}
/*计算单个教学任务总课时*/
double times(int a, int b, int c){//实践课时,理论课时,上课班级数目
system("cls");
if (c==2){
return 1.5*(a+b);
}else if(c==3){
return 2*(a+b);
}else if(c>=4){
return 2.5*(a+b);
}
else printf("该教师无课时");
return 0;
}
/*录入与添加目录*/
void mu(struct teacher* tc, int k){
init(tc);
system("cls");
if (k) printf("请输入第%d位教师的信息:\n", k);
printf("请输入教师姓名:");
rewind(stdin); gets(tc->name); //rewind(stdin)清空缓冲区 rewind函数属于stdio.h头文件
printf("请输入教师性别:");
rewind(stdin); gets(tc->sex);
printf("请输入教师教师号:");
rewind(stdin); gets(tc->num);
printf("请输入教师职称:");
rewind(stdin); gets(tc->flag);
printf("请输入教师任课课程:");
rewind(stdin); gets(tc->course);
printf("请输入教师任课班级:");
rewind(stdin); gets(tc->classes);
printf("请输入教师所教班级数目:");
rewind(stdin); scanf("%d", &tc->classnum);
printf("请输入理论课时:");
rewind(stdin); scanf("%d", &tc->lilun);
printf("请输入实践课时:");
rewind(stdin); scanf("%d", &tc->shiyan);
tc->all = times(tc->lilun, tc->shiyan, tc->classnum);
}
/*所有老师姓名*/
struct names* nam(){
struct teacher* tc = load();
if (tc == NULL) return NULL;
struct names* end = (struct names*)malloc(n * sizeof(struct names));
for (int i = 0;i < n;i++){
memset((end + i)->na, '\0', sizeof (end + i)->na);
(end + i)->sum = 0.0;
(end + i)->num = 0;
}
int flg, g = 0;
for (int i = 0;i < n;i++) {
flg = 1;
for (int j = i + 1;j < n;j++) {
if (!strcmp((i + tc)->name, (j + tc)->name)){
flg = 0;
break;
}
}
if (flg || (i == n - 1)){
strcpy((g + end)->na, (i + tc)->name);
g++;
}
}
end->num = g;
return end;
}
/*将信息保存到文件中*/
int save(struct teacher* tc, int m, int flag){
FILE* fp;
if (flag) fp = fopen("jiaoshi.dat", "a");
else fp = fopen("jiaoshi.dat", "w");
for (int i = 0;i < m;i++)
fwrite(tc + i, sizeof(struct teacher), 1, fp);
free(tc);
tc = NULL;
fclose(fp);
return 1;
}
/*教师信息录入*/
int put(){
system("cls");
printf("请输入要录入的教师人数:");
int m;
rewind(stdin); scanf("%d", &m);
struct teacher* tc = (struct teacher*)malloc(m * sizeof(struct teacher));
if (tc == NULL) {
printf("动态内存分配失败,数组创建失败!\n");
exit(1);
}
for (int i = 0; i < m; i++) mu(tc + i, i + 1);
n += m;
if (!save(tc, m, 1)) return 0;
return 1;
}
/*教师信息修改*/
int change(){
system("cls");
char ch[20], course[20];
int a = 0, i = 0;
struct teacher* tc = load();
printf("请输入要更改的教师姓名:");
rewind(stdin); gets(ch);
printf("请输入要更改的课程名称:");
rewind(stdin); gets(course);
for (i = 0;i < n;i++) {
if (!strcmp((tc + i)->name, ch) && !strcmp((tc + i)->course, course)){
system("cls");
printf("1.教师姓名\n2.教师性别\n3.教师号\n4.教师职称\n5.教师任课课程\n6.教师任课班级\n7.教师任课班级数目\n8.理论课时\n9.实践课时\n10.全部修改 \n");
printf("请输入想要修改的教师信息编号:");
rewind(stdin); scanf("%d", &a);
switch (a) {
case 1:
printf("请输入新的教师姓名:");
rewind(stdin); gets((tc + i)->name); break;
case 2:
printf("请输入教师性别:");
rewind(stdin); gets((tc + i)->sex ); break;
case 3:
printf("请输入教师教师号:");
rewind(stdin); gets((tc + i)->num ); break;
case 4:
printf("请输入教师职称:");
rewind(stdin); gets((tc + i)->flag); break;
case 5:
printf("请输入教师任课课程:");
rewind(stdin); gets((tc + i)->course ); break;
case 6:
printf("请输入教师任课班级:");
rewind(stdin); gets((tc + i)->classes ); break;
case 7:
printf("请输入教师所教班级数目:");
rewind(stdin); scanf("%d", &(tc + i)->classnum ); break;
case 8:
printf("请输入理论课时:");
rewind(stdin); scanf("%d", &(tc + i)->lilun); break;
case 9:
printf("请输入实践课时:");
rewind(stdin); scanf("%d", &(tc + i)->shiyan ); break;
case 10:
mu(tc + i, 0); break;
default: break;
}
break;
}
}
if (i == n) return 0;
if (a == 7 || a == 8 || a == 9)
(tc + i)->all = times((i + tc)->lilun, (i + tc)->shiyan, (tc + i)->classnum);
if (!save(tc,n,0))return 0;
return 1;
}
/*删除教师授课教学信息*/
int cut(){
system("cls");
char ch[20], s[20];
int flag = n;
struct teacher* tc = load();
printf("请输入你要删除的教师的姓名:");
rewind(stdin); gets(ch);
printf("请输入该教师的课程名称:");
rewind(stdin); gets(s);
for (int i = 0;i < n;i++){
if (!strcmp((tc + i)->name, ch) && !strcmp((tc + i)->course, s)){
if(i<n-1){
strcpy((tc + i)->name, (tc + n - 1)->name);
strcpy((tc + i)->flag, (tc + n - 1)->flag);
strcpy((tc + i)->sex, (tc + n - 1)->sex);
strcpy((tc + i)->num, (tc + n - 1)->num);
strcpy((tc + i)->course, (tc + n - 1)->course);
strcpy((tc + i)->classes, (tc + n - 1)->classes);
(tc + i)->classnum = (tc + n - 1)->classnum;
(tc + i)->lilun = (tc + n - 1)->lilun;
(tc + i)->shiyan = (tc + n - 1)->shiyan;
(tc + i)->all = (tc + n - 1)->all;
n--; i--;
}
if(i=n-1){
strcpy((tc + i)->name, (tc)->name);
strcpy((tc + i)->flag, (tc)->flag);
strcpy((tc + i)->sex, (tc)->sex);
strcpy((tc + i)->num, (tc)->num);
strcpy((tc + i)->course, (tc)->course);
strcpy((tc + i)->classes, (tc)->classes);
(tc + i)->classnum = (tc)->classnum;
(tc + i)->lilun = (tc)->lilun;
(tc + i)->shiyan = (tc)->shiyan;
(tc + i)->all = (tc)->all;
n--; i--;
}
}
}
if (n == flag) return 0;
if (!save(tc, n, 0)) return 0;
return 1;
}/*查询教师授课信息*/
int find()
{
struct teacher* tc = load();
if (tc == NULL) return 0;
char n1[20];
int i = 0;
printf("请输入要查询的教师号:");
rewind(stdin); gets(n1);
for (;i < n;i++)
if (!strcmp((tc + i)->num, n1)){
printf("姓名:%s\n性别:%s\n教师号:%s\n职称:%s\n所任课程:%s\n任课班级:%s\n任课班级数目:%d\n理论课时:%d\n实践课时:%d\n单个课程工作量:%lf\n",(i+tc)->name,(i+tc)->sex,(i+tc)->num,(i+tc)->flag,(i+tc)->course,(i+tc)->classes,(i+tc)->classnum, (i+tc)->lilun,(i+tc)->shiyan,(tc+i)->all);
}
printf("无此教师信息!");
}
/*一个教师总教学工作量*/
void maxtime(struct names* end){
struct teacher* tc = load();
if (tc == NULL) return;
for (int i = 0;i < n;i++)
if (!strcmp(end->na, (i + tc)->name))
end->sum += (i + tc)->all;
}
/*所有教师总工作量汇总*/
struct names* collection()
{
struct names* end = nam();
for (int i = 0;i < end->num;i++)
maxtime(end + i);
return end;
}
/*输出全部教师的综合信息*/
void show(){
system("cls");
int i = 0;
struct teacher* tc = load();
if (tc == NULL) return;
struct names* end = collection();
if (n != 0) {
for (;i < n;i++)
printf("姓名:%s\n性别:%s\n教师号:%s\n职称:%s\n所任课程:%s\n任课班级:%s\n任课班级数目:%d\n理论课时:%d\n实践课时:%d\n单节课程工作量:%lf\n\n",(i+tc)->name,(i+tc)->sex,(i+tc)->num,(i+tc)->flag,(i+tc)->course,(i+tc)->classes,(i+tc)->classnum,(i+tc)->lilun,(i+tc)->shiyan,(tc+i)->all);
printf("全体教职工的总工作量输出:\n");
for (int j = 0;j < end->num;j++)
printf("教师姓名:%s\n教师总工作量:%lf\n\n", (end + j)->na, (end + j)->sum);
}
}
1.2 登录系统
/*教师注册*/
int Regist()
{
Users a={0},b={0};
char tmp[20]={-1};
FILE *pf=NULL;
pf=fopen("D:\\users.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉,注册时打开文件失败\n");
return 0;
}
printf("\t\t\t欢迎来到注册界面!\n");
printf("\t\t\t请输入想要注册的账号:(账号长度不超过10位)\n\t\t\t");
do{
scanf("%s",a.id);
if(strlen(a.id)>10)
printf("\t\t\t输入错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
fread(&b, sizeof(Users), 1, pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0 )
fread(&b,sizeof(Users),1,pf);
else
{
printf("\t\t\t账号未注册过,即将跳转到注册界面\n\t\t\t");
system("pause");
break;
}
}
else
{
printf("\t\t\t该账号已注册过,请输入新的账号!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
printf("\t\t\t请输入姓名:");
scanf("%s",a.name);
printf("\t\t\t请输入性别(man/woman):");
do{
getchar();
scanf("%s",a.sex);
if(strcmp(a.sex, "man")!=0&&strcmp(a.sex, "woman")!=0)
printf("\t\t\t输入错误,请重新输入:");
else
break;
}while(1);
printf("\t\t\t请输入密码:(密码长度不超过10位)\n\t\t\t");
do{
scanf("%s",a.paw);
if(strlen(a.paw)>10)
printf("\t\t\t输入错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请再输入一次密码:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.paw)!=0)
printf("\t\t\t两次输入密码不一致,请再输入一次密码:\n\t\t\t");
else
break;
}while(1);
fclose(pf); pf=NULL;
pf=fopen("D:\\users.txt","a");
fwrite(&a,sizeof(Users),1,pf);
printf("\t\t\t[ 恭喜你注册成功! ]\n");
fclose(pf);
pf=NULL;
return 0;
}
/*教师登录*/
int Login()
{
Users a={0},b={0};
int h=0;
FILE *pf=fopen("D:\\users.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎来到登录界面!\n");
printf("\t\t\t请输入你的账号:\n\t\t\t");
scanf("%s",a.id);
fscanf(pf,"%*[^\n]%*c");
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入密码:\n\t\t\t");
do{
scanf("%s",a.paw);
if(strcmp(a.paw, b.paw)!=0 )
printf("\t\t\t密码错误,请重新输入:\n\t\t\t");
else
break;
h++;
printf("还剩%d次机会!:,3-h");
if(h==3){
printf("次数用完请重新登录!");
return 0;
}
}while(1);
printf("\t\t\t[ 恭喜你登录成功! ]\n");
fclose(pf); pf=NULL;
return 1;
}
/*教师修改密码*/
int Change(){
char tmp[20]={-1};
Users a={0},b={0};
int h;
FILE *pf=fopen("D:\\users.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎你来到修改密码的界面!\n");
printf("\t\t\t请输入需要修改密码的账号:\n\t\t\t");
scanf("%s",a.id);
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入原密码:\n\t\t\t");
do{
scanf("%s",a.paw);
if(strcmp(a.paw, b.paw)!=0 )
printf("\t\t\t原密码错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请输入新密码:\n\t\t\t");
scanf("%s",a.paw);
printf("\t\t\t请再输入一次密码:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.paw)!=0)
printf("\t\t\t两次输入密码不一致,请重新输入一次密码:\n\t\t\t");
else
break;
h++;
printf("还剩%d次机会!:",3-h);
if(h==3){
printf("次数用完请重新登录!");
return 0;
}
}while(1);
fclose(pf); pf=NULL;
pf=fopen("D:\\users.txt","w");
fwrite(&a,sizeof(Users),1,pf);
printf("\t\t\t[ 恭喜你修改密码成功! ]\n");
fclose(pf);
pf=NULL;
return 0;
}
/*普通成员找回密码*/
int found(){
char tmp[20];
Users a={0},b={0};
FILE *pf=fopen("D:\\users.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎你来到找回密码的界面!\n");
printf("\t\t\t请输入需要找回密码的账号:\n\t\t\t");
scanf("%s",a.id);
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入原账号:\n\t\t\t");
do{
scanf("%s",a.id);
if(strcmp(a.id, b.id)!=0 )
printf("\t\t\t原账号错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请输入原账号姓名:\n\t\t\t");
scanf("%s",a.name);
printf("\t\t\t请再输入一次姓名:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.name)!=0)
printf("\t\t\t两次输入不一致,请重新输入一次:\n\t\t\t");
else
printf("恭喜你找回密码成功!你的密码为:%s",b.paw);
break;
}while(1);
fclose(pf); pf=NULL;
pf=NULL;
return 0;
}
/*管理员注册*/
int Regists()
{
int x,y,i=0,t,k=0;
x=123456;
Users a={0},b={0};
char tmp[20]={-1};
FILE *pf=NULL;
pf=fopen("D:\\guanli.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉,注册时打开文件失败\n");
return 0;
}
printf("请输入管理员密匙:");
scanf("%d",&y);
if(y==x){
printf("\t\t\t欢迎来到注册界面!\n");
printf("\t\t\t请输入想要注册的账号:(账号长度不超过10位的字母)\n\t\t\t");
do{
scanf("%s",a.id);
t=strlen(a.id);
if(t<10){
do{
if(isalpha(a.id[i])){
i++;
}else{
printf("\t\t\t输入错误!\n\t\t\t");
system("pause");
return 0;
}
}while(i!=t);
break;
}else{
printf("\t\t\t输入错误!\n\t\t\t");
system("pause");
return 0;
}
}while(1);
fread(&b, sizeof(Users), 1, pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0 )
fread(&b,sizeof(Users),1,pf);
else
{
printf("\t\t\t账号未注册过,即将跳转到注册界面\n\t\t\t");
system("pause");
break;
}
}
else
{
printf("\t\t\t该账号已注册过,请输入新的账号!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
printf("\t\t\t请输入姓名:");
scanf("%s",a.name);
printf("\t\t\t请输入性别(man/woman):");
do{
getchar();
scanf("%s",a.sex);
if(strcmp(a.sex, "man")!=0&&strcmp(a.sex, "woman")!=0)
printf("\t\t\t输入错误,请重新输入:");
else
break;
}while(1);
printf("\t\t\t请输入密码:(密码长度不超过10位)\n\t\t\t");
do{
scanf("%s",a.paw);
if(strlen(a.paw)>10)
printf("\t\t\t输入错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请再输入一次密码:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.paw)!=0)
printf("\t\t\t两次输入密码不一致,请再输入一次密码:\n\t\t\t");
else
break;
}while(1);
fclose(pf); pf=NULL;
pf=fopen("D:\\guanli.txt","a");
fprintf(pf,"账号 密码 姓名 性别\r\n");
fwrite(&a,sizeof(Users),1,pf);
fwrite("\r\n",2,1,pf);
printf("\t\t\t[ 恭喜你注册成功! ]\n");
fclose(pf);
pf=NULL;
}else{
printf("密匙错误,无法注册管理员!");
}
return 0;
}/*管理员登录*/
int Logins()
{
Users a={0},b={0};
int h=0;
FILE *pf=fopen("D:\\guanli.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎来到管理员登录界面!\n");
printf("\t\t\t请输入你的账号:\n\t\t\t");
scanf("%s",a.id);
fscanf(pf,"%*[^\n]%*c");
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入密码:\n\t\t\t");
do{
scanf("%s",a.paw);
if(strcmp(a.paw, b.paw)!=0 )
printf("\t\t\t密码错误,请重新输入:\n\t\t\t");
else
break;
h++;
printf("密码输入错误,还剩%d次机会!",3-h);
if(h==3){
printf("请重新登录!");
break;
return 0;
}
}while(1);
printf("\t\t\t[ 恭喜你登录成功! ]\n");
fclose(pf); pf=NULL;
return 2;
}
/*管理员修改密码*/
int Changes(){
char tmp[20]={-1};
Users a={0},b={0};
int h;
FILE *pf=fopen("D:\\guanli.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎你来到管理员修改密码的界面!\n");
printf("\t\t\t请输入需要修改密码的账号:\n\t\t\t");
scanf("%s",a.id);
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入原密码:\n\t\t\t");
do{
scanf("%s",a.paw);
if(strcmp(a.paw, b.paw)!=0 )
printf("\t\t\t原密码错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请输入新密码:\n\t\t\t");
scanf("%s",a.paw);
printf("\t\t\t请再输入一次密码:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.paw)!=0)
printf("\t\t\t两次输入密码不一致,请重新输入一次密码:\n\t\t\t");
else
break;
h++;
printf("还剩%d次机会!:,3-h");
if(h==3){
printf("次数用完请重新登录!");
return 0;
}
}while(1);
fclose(pf); pf=NULL;
pf=fopen("D:\\guanli.txt","w");
fwrite(&a,sizeof(Users),1,pf);
printf("\t\t\t[ 恭喜你修改密码成功! ]\n");
fclose(pf);
pf=NULL;
return 0;
}
/*管理员找回密码*/
int founds(){
char tmp[20];
Users a={0},b={0};
FILE *pf=fopen("D:\\guanli.txt","r");
if(pf==NULL)
{
printf("\t\t\t很抱歉登录时文件打开失败\n");
return 0;
}
printf("\t\t\t欢迎你来到找回密码的界面!\n");
printf("\t\t\t请输入需要找回密码的账号:\n\t\t\t");
scanf("%s",a.id);
fread(&b,sizeof(Users),1,pf);
while(1)
{
if(strcmp(a.id, b.id)!=0 )
{
if(feof(pf)==0)
{
fread(&b,sizeof(Users),1,pf);
}
else
{
printf("\t\t\t该账号不存在,请先注册!\n");
fclose(pf);
pf=NULL;
return 0;
}
}
else
{
break;
}
}
printf("\t\t\t请输入原账号:\n\t\t\t");
do{
scanf("%s",a.id);
if(strcmp(a.id, b.id)!=0 )
printf("\t\t\t原账号错误,请重新输入:\n\t\t\t");
else
break;
}while(1);
printf("\t\t\t请输入原账号姓名:\n\t\t\t");
scanf("%s",a.name);
printf("\t\t\t请再输入一次姓名:\n\t\t\t");
do{
scanf("%s",tmp);
if(strcmp(tmp,a.name)!=0)
printf("\t\t\t两次输入不一致,请重新输入一次:\n\t\t\t");
else
printf("恭喜你找回密码成功!你的密码为:%s",b.paw);
break;
}while(1);
fclose(pf); pf=NULL;
pf=NULL;
return 0;
}
1.3 主函数
/*主函数*/
int main()
{
system("color 70");
int input=-1;
int t,a;
do{
printf("\t\t\t-----------------------------------------\n");
printf("\t\t\t| 1.普通用户登录 5.管理员登录 |\n");
printf("\t\t\t| 2.普通用户注册 6.管理员注册 |\n");
printf("\t\t\t| 3.普通用户修改密码 7.管理员修改密码 |\n");
printf("\t\t\t| 4.普通用户找回密码 8.管理员找回密码 |\n");
printf("\t\t\t| 0.退出 |\n");
printf("\t\t\t-----------------------------------------\n");
printf("\t\t\t <请选择功能>:");
scanf("%d",&input);
switch(input)
{
case 1:t=Login();Sleep(2000);break;
case 2:Regist();Sleep(2000);break;
case 3:Change();Sleep(2000);break;
case 4:t=Logins();Sleep(2000);break;
case 5:Regists();Sleep(2000);break;
case 6:Changes();Sleep(2000);break;
case 0:puts("\n\t\t\t退出成功!欢迎下次使用!");return 0;
}
if(t==1||t==2)
break;
system("cls");
}while(input);
if(t==2){
while (1) {
system("cls");
printf("\t\t\t******************************\t\t\t\n");
printf("\t\t\t**欢迎来到教师工作量管理系统**\t\t\t\n");
printf("\t\t\t *以下是功能目录 \n");
printf("\t\t 1.教师信息录入 2.教师信息修改\n");
printf("\t\t 3.教师信息删除 4.教师信息查询\n");
printf("\t\t 5.教师综合信息输出 6.退出当前系统\n");
int i = 0;
rewind(stdin);
printf("请输入你要进行的内容序号:");
scanf("%d", &i);
switch (i) {
case 1:if (!put())
return 0;
nam();
printf("教师信息录入成功!\n");
break;
case 2:if (!change()) {
printf("查无信息!"); break;
}
printf("教师信息修改成功!\n");
break;
case 3:if (!cut()) { printf("找不到对象!");break; }
printf("教师信息删除成功!\n");
break;
case 4:find();break;
case 5:show();break;
case 6:exit(1);
default: printf("未知操作请重新输入!\n");break;
}
system("pause");
}
}
if(t==1){
while(1){
system("cls");
printf("\t\t\t**欢迎来到教师工作量查询系统**\t\t\t\n");
printf("\t\t\t 以下是功能目录:\n");
printf("\t\t\t1.教师信息查询\n");
printf("\t\t\t2.教师信息输出\n");
printf("\t\t\t3.退出\n");
rewind(stdin);
printf("请选择你要进行的内容:");
scanf("%d",&a);
switch(a){
case 1:find();break;
case 2:show();break;
case 3:exit(1);
default:printf("未知操作请重新输入!\n");break;
}
system("pause");
}
}
return 0;
2. 程序实现
2.1 登录系统
2.2 教师工作量管理系统