请假管理系统源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define select int
typedef struct //账户信息{
char name[20]; //
char pw[20]; //User.pw
} User;
typedef struct
{
char Num[20];
char n1[20];
char Class[20];
char time[100];
char reason[100];
char instructor[100];
} Leave;
typedef struct
{
char n1[20];
char Num[20];
// char name[20];
char Class[20];
char time[100];
char reason[100];
char instructor[100];
char suggest[100];
} TEACHER;
int check (char name[20])
{
int i=0;
User ru;
FILE *f =fopen("data.dat","rb");
rewind(f);
for(i=0; !feof(f); i++)
{
int d=i*sizeof(User);
fseek(f,d,SEEK_SET);
fread(&ru,sizeof(User),1,f);
if(strcmp(name,)==0)
return 1;
}
return -1;
}
int login(char name[20],char pw[20])
{
User us;
FILE *f =fopen("data.dat","rb");
while(!feof(f))
{
fread(&us,sizeof(User),1,f);
if(strcmp(name,)==0)
{
if(strcmp(pw,us.pw)==0)return 1;
}
}
return -1;
}
int main()
{
char n[20];
char plog[20];
char nlog[20];
int c;
User u;
FILE *f =fopen("data.dat","ab");
if(f!=NULL)
{
fwrite(&u,sizeof(User),1,f);
}
fclose(f);
Login:
system("color F0");
system("cls");
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|-----------------------------学生请假系统-----------------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
printf("\n");
Sleep(1000);
printf("\n");
printf("请输入帐号:");
scanf("%s",nlog);
c=check(nlog);
if(c==1)//如果账户存在
{
strcpy(n,nlog);//复制登录帐号
if(strlen(n)==9)//如果是学生
{
int a,i;
select s=0;
printf("\n");
printf("请输入密码:");//直接输入密码
scanf("%s",plog);
for(a=2,i=0; i<4; i++,a--)
{
if(login(nlog,plog)==-1)//密码错误
{
system("color F0");
char plog[20]= {}; //登录数组初始化
system("cls");
printf("\n");
printf("************************************************************************\ n");
printf("* 密码错误! *\n");
printf("************************************************************************\ n");
printf("\n\n");
if(a>0)
{
printf("请重新输入密码(你还有%d次机会):",a);
printf("\n\n");
scanf("%s",plog);
if(login(nlog,plog)==1)
goto success2;
}
else
return 0;
}
}
if(login(nlog,plog)==1)
{
success2: system("color F0");
printf("\n\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\登陆成功///////////////////////\n");
Sleep(1000);
system("cls");
}
LEAVESYSTEM:
printf("\n\n");
printf("========================================================================\ n");
printf("|1.提交请假申请|\n");
printf("|2.查询请假批准状态
|\n");
printf("| 如无需操作,可直接关闭程序|\n");
printf("========================================================================\ n");
printf("\n\n");
Sleep(1000);
printf("请输入您要执行的选项:");
scanf("%d",&s);
Sleep(1000);
while(s!=1&&s!=2)
{
if(s!=1&&s!=2)
{ system("color 0c");
printf("选项不存在,请重新输入(1/2):");
s=0;
scanf("%d",&s);
}
}
if(s==1)//写入请假
{
system("color F0");
system("cls");
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|------------------------------提交请假申请----------------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
printf("\n\n");
Leave a;
Sleep(1000);
printf("请输入班级:\n");
scanf("%s",a.Class);
printf("请输入姓名:\n");
scanf("%s",a.n1);
printf("请详细输入请假时间:\n");
scanf("%s",a.time);
printf("请详细输入请假原因:\n");
scanf("%s",a.reason);
strcpy(nlog,a.Num);
strcpy(a.instructor,"0");
FILE *t=fopen("leave.dat","ab");
fwrite(&a,sizeof(Leave),1,t);//讲以变量u的地址开始的内存区域的一个数据写到f指向的文件中,每个数据占sizeof(User)
fclose(t);
fflush(t);
// Sleep(1000);
printf("\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\保存成功///////////////////////\n");
printf(" 请不定时来查询你的假条申请状态!\n\n\n");
system("pause");
system("cls");
goto LEAVESYSTEM;
}
if(s==2)//学生查询状态代码
{
system("color F0");
system("cls");
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|----------------------------查询请假批准状态--------------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
Sleep(1000);
TEACHER b;
FILE *t=fopen("read.dat","rb");
while(1)
{
if(!(fread(&b,sizeof(TEACHER),1,t)))
break;
if((strcmp(nlog,b.Num))==0)
{
printf("---------------------------------------------------------------\n");
printf("|学生%s请假申请反馈信息:\n",b.n1);
printf("|班级:%s\n \n",b.Class);
printf("|姓名:%s\n \n",b.n1);
printf("|请假时间:%s\n \n",b.time);
printf("|请假原因:%s\n \n",b.reason);
printf("---------------------------------------------------------------\n");
Sleep(1000);
printf("\n");
printf(" -------------------------------------------------------------\n");
printf(" 申请状态:%s\n",b.instructor);
printf(" 辅导员意见:%s\n",b.suggest);
printf(" -------------------------------------------------------------\n");
system("pause");
Sleep(1000);
system("cls");
goto LEAVESYSTEM;
}
}
}
if(s==3)
{
goto Login;
}
}//身份学生
if(strlen(n)==4)//如果是辅导员
{
int a,i;
select s;
printf("\n");
printf("请输入密码:");//直接输入密码
for(a=2,i=0; i<4; i++,a--)
{
if(login(nlog,plog)==-1)//密码错误
{
system("color 0c");
char plog[20]= {}; //登录数组初始化
system("cls");
printf("\n");
printf("************************************************************************\ n");
printf("* 密码错误! *\n");
printf("************************************************************************\ n");
printf("\n\n");
if(a>0)
{
printf("请重新输入密码(你还有%d次机会):",a);
printf("\n\n");
scanf("%s",plog);
if(login(nlog,plog)==1)
goto success3;
}
else
return 0;
}
}
if(login(nlog,plog)==1)
{
success3: system("color F0");
printf("\n\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\登陆成功///////////////////////\n");
Sleep(1000);
}
//Approvalsystem:
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|-------------------------学生请假系统(辅导员端)-----------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
printf("\n");
Sleep(1000);
printf("========================================================================\ n");
printf("|1.查看学生请假申请|\n");
printf("|2.返回登陆界面|\n");
printf("| 如无需操作,可直接关闭程序|\n");
printf("========================================================================\ n");
printf("\n\n");
Sleep(1000);
printf("请输入您要执行的选项:");
scanf("%d",&s);
while(s!=1&&s!=2)
{
if(s!=1&&s!=2)
{
printf("选项不存在,请重新输入(1/2):");
scanf("%d",&s);
}
}
if(s==1)//辅导员读
{
system("cls");
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|----------------------------查看学生请假申请--------------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
printf("\n\n");
Sleep(1000);
Leave a;
FILE *t=fopen("leave.dat","rb");
while(1)
{
int ch;
if(!(fread(&a,sizeof(Leave),1,t)))
break;
{
printf("-------------------------------------------------------------\n");
printf("|学生信息如下:\n");
printf("|班级:%s\n",a.Class);
printf("|姓名:%s\n",a.n1);
printf("|学号:%s\n",a.Num);
printf("|请假时间:%s\n",a.time);
printf("|请假原因:%s\n",a.reason);
printf("-------------------------------------------------------------\n");
Sleep(1000);
printf("\n\n\n");
printf("
\n");
printf(" 是否批准学生请假申请\n");
printf(" ----------------------------------------------------------- \n");
printf(" ----------------------------------------------------------- \n");
printf(" 1.批准学生请假申请\n");
printf(" 2.不批准学生请假申请\n");
printf("\n\n\n");
printf("请输入您要执行的选项:");
scanf("%d",&ch);
while(ch!=1&&ch!=2)
{
if(ch!=1&&ch!=2)
{
printf("选项不存在,请重新输入(1/2):");
scanf("%d",&ch);
}
}
if(ch==1)
{
printf("\n\n");
printf("-------------------------------------------------------------\n");
printf("执行中....\n");
printf("-------------------------------------------------------------\n");
Sleep(1000);
TEACHER b;
FILE *F=fopen("read.dat","ab");
strcpy(b.instructor,"您的请假申请已被批准!");
printf("\n");
printf("辅导员意见:");
scanf("%s",b.suggest);
strcpy(b.Class,a.Class);
strcpy(b.n1,a.n1);
strcpy(b.time,a.time);
strcpy(b.reason,a.reason);
strcpy(b.Num,a.Num);
// FILE *f3=fopen("leave.dat","ab");
fwrite(&b,sizeof(TEACHER),1,F);
fclose(F);
fflush(F);
Sleep(1000);
printf("\n\n\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\操作成功///////////////////////\n");
system("pause");
printf("\n\n\n\n\n");
continue;
}
if(ch==2)
{
printf("-------------------------------------------------------------\n");
printf("执行中....\n");
printf("-------------------------------------------------------------\n");
Sleep(1000);
TEACHER b;
FILE *F=fopen("read.dat","ab");
strcpy(b.instructor,"您的请假申请没有被批准,请按时上课!");
printf("\n");
printf("辅导员意见:");
scanf("%s",b.suggest);
strcpy(b.Class,a.Class);
strcpy(b.n1,a.n1);
strcpy(b.time,a.time);
strcpy(b.reason,a.reason);
strcpy(b.Num,a.Num);
fwrite(&b,sizeof(TEACHER),1,F);
fclose(F);
fflush(F);
Sleep(1000);
printf("\n\n\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\操作成功///////////////////////\n");
system("pause");
printf("\n\n\n\n\n");
continue;
}
}
}
}
if(s==2)
{
system("cls");
goto Login; //修改学生请假申请状态反回
}
}//如果是辅导员
if(strlen(n)==5)//如果是老师
{
int a,i;
printf("\n");
printf("请输入密码:");//直接输入密码
scanf("%s",plog);
for(a=2,i=0; i<4; i++,a--)
{
if(login(nlog,plog)==-1)//密码错误
{
system("color 0c");
char plog[20]= {}; //登录数组初始化
system("cls");
printf("\n");
printf("************************************************************************\ n");
printf("* 密码错误! *\n");
printf("************************************************************************\ n");
printf("\n\n");
if(a>0)
{
printf("请重新输入密码(你还有%d次机会):",a);
printf("\n\n");
scanf("%s",plog);
if(login(nlog,plog)==1)
goto success1;
}
else
return 0;
}
}
if(login(nlog,plog)==1)
{
success1: system("color F0");
printf("\n\n");
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\登陆成功///////////////////////\n");
Sleep(1000);
system("cls");
}
system("cls");
printf("\n\n");
printf("========================================================================\ n");
printf("|
|\n");
printf("|---------------------------学生请假系统(老师端)-----------------------|\n");
printf("|
|\n");
printf("========================================================================\ n");
Sleep(1000);
printf("\n\n");
printf(" -------------------------------------------------------------\n");
printf(" 学生请假加载中...\n");
printf(" -------------------------------------------------------------\n");
Sleep(1000);
// int i=0;
TEACHER b;
FILE *t=fopen("read.dat","rb");
// rewind(t);
while(1)
{
if(!(fread(&b,sizeof(TEACHER),1,t)))
break;
// long d=i*sizeof(TEACHER);
// fseek(t,d,SEEK_SET);
// fread(&b,sizeof(TEACHER),1,t);
printf("---------------------------------------------------------------\n");
printf("|学生学号%s请假申请反馈信息:\n",b.Num);
printf("|班级:%s\n",b.Class);
printf("|姓名:%s\n",b.n1);
printf("|请假时间:%s\n",b.time);
printf("|请假原因:%s\n",b.reason);
printf("|申请状态:%s\n",b.instructor);
printf("---------------------------------------------------------------\n");
printf("\n\n");
}
system("pause");
}
}
if(c==-1)//账户不存在
{
system("color F0");
system("cls");
char n[20];
char p[20];
strcpy(n,nlog);//复制帐号
if(strlen(n)==9)//完成注册,存入data.dat文档
{
User u;
printf("************************************************************************\ n");
printf("* 同学!第一次登录请完成注册*\n");
printf("************************************************************************\ n");
printf("\n\n");
printf(" ----------------------------------------------------------------------\n");
printf(" 请输入新密码\n");
printf(" ----------------------------------------------------------------------\n");
scanf("%s",p);
strcpy(,n);
strcpy(u.pw,p);
FILE *f =fopen("data.dat","ab");//打开文件让指针f指向打开的文件
fwrite(&u,sizeof(User),1,f);//讲以变量u的地址开始的内存区域的一个数据写到f指向的文件中,每个数据占sizeof(User)
fclose(f);
fflush(f);
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\注册成功///////////////////////\n\n\n");
system("pause");
system("cls");
}
if(strlen(n)==5)
{
User u;
printf("************************************************************************\ n");
printf("* 老师!第一次登录请完成注册*\n");
printf("************************************************************************\ n");
printf("\n\n");
printf(" ----------------------------------------------------------------------\n");
printf(" 请输入新密码\n");
printf(" ----------------------------------------------------------------------\n");
scanf("%s",p);
strcpy(,n);
strcpy(u.pw,p);
FILE *f =fopen("data.dat","ab");//打开文件让指针f指向打开的文件
fwrite(&u,sizeof(User),1,f);//讲以变量u的地址开始的内存区域的一个数据写到f指向的文件中,每个数据占sizeof(User)
fclose(f);
fflush(f);
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\注册成功///////////////////////\n\n\n");
system("pause");
system("cls");
}
if(strlen(n)==4)
{
User u;
printf("************************************************************************\ n");
printf("* 辅导员!第一次登录请完成注册*\n");
printf("************************************************************************\ n");
printf("\n\n");
printf(" ----------------------------------------------------------------------\n");
printf(" 请输入新密码
\n");
printf(" ----------------------------------------------------------------------\n");
scanf("%s",p);
strcpy(,n);
strcpy(u.pw,p);
FILE *f =fopen("data.dat","ab");//打开文件让指针f指向打开的文件
fwrite(&u,sizeof(User),1,f);//讲以变量u的地址开始的内存区域的一个数据写到f指向的文件中,每个数据占sizeof(User)
fclose(f);
fflush(f);
printf(" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\注册成功///////////////////////\n\n\n");
system("pause");
system("cls");
}
goto Login;
}
return 0;
}。

相关文档
最新文档