学生信息管理系统

实现功能
文件加密
学生:

姓名 性别 学号 密码 语文 数学 英语
1、第一次登录强制修改密码。    //结构体里加一个flag位,初始化为false,第一次登陆后设置为true 
2、查询成绩
    排名 不显示姓名和学号。  
    平均分
    最高分
    最低分
3、修改密码
4、查看个人信息
5、三次密码错误锁定帐号,由教师解锁

教师:

姓名 性别 工号 密码
1、第一次登录强制修改密码。
2、添加学生(学生的学号自动生成)
    单个添加
    批量导入
3、删除学生
	输入两人次学号确定
    删除的学生要记录保存在已退学的文件中
4、查找学生
    按姓名查找  模糊查找 
    按学号查找
5、修改学生信息
    修改学生基础信息
    修改学生成绩
6、录入学生成绩
    单个录入
    批量导入
7、重置学生密码
8、显示所有在校学生信息
9、显示所有退出学生信息
10、三次密码错误锁定帐号,由校长解锁
11、解锁学生账号(密码还能继续使用)

校长:

admin 
1、第一次登录强制修改密码。
2、能重置自己的密码
3、能重置教师密码
4、添加教师
5、删除教师
6、显示所有在职教师
7、显示所有离职教师

以下关于函数的声明以及文件的打开略过。

学生函数student.c

#include <stdio.h>
#include "student.h"
#include "list.h"
#include "tools.h"
#include <stdlib.h>
#include <getch.h>
#include <string.h>

extern List* list1,*list2,*list3,*list4;
extern int num1,num2,num3,num4;


void first_signin_stu(int n)
{
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	if (stu->flag == 0)
	{
		printf("请输入您的新密码:");
		scanf("%d",&stu->password);
		stu->flag = 1;
	}
}

void modify_stu(int n)
{
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	printf("请输入您的新密码:");
	scanf("%d",&stu->password);
}

void see_stu(int n)
{
	if (n > num1) return;
	Student* stu = malloc(sizeof(Student));
	int m=num1-num2;
	for(int i=1;i<=m;i++)
	{
		for(Node* node = list1->head;node != NULL;node = node ->next)
		{
			stu =node->ptr;
			if (stu->id == (m+i)/2) break;
		}
		if (stu->id == n) break;
		if (stu->id < n) 
		{
			i=(m+i)/2;
		}
		else 
		{
			m=(m+i)/2;
		}
	}
	printf("id:%d\n",stu->id);
	printf("姓名:%s\n",stu->name);
	printf("性别:%c\n",stu->sex);
	printf("语文:%lf\n",stu->chinese);
	printf("数学:%lf\n",stu->math);
	printf("英语:%lf\n",stu->english);
}

bool signin_stu(int n)
{
	int pass=0;
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	if (stu->lock == 1) 
	{
		printf("账号已被锁,请联系老师\n");
		return false;
	}
	for(int i=0;i<3;i++)
	{
		printf("请输入您的密码:");
		scanf("%d",&pass);
		if (stu->password == pass)
		{
			printf("登录成功\n");
			return true;
		}
	}
	printf("账号已被锁,请联系老师\n");
	stu->lock = 1;
	return false;
}

void query_stu(int n)
{
	double max=0,min=400,average=0,self=0;
	int p=1;
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	self = stu->score;
	for(Node* node=list1->head; node!=NULL; node=node->next)
	{
		stu = node->ptr;
		if (max < stu->score) 
		{
			max = stu->score;
		}
		if (min > stu->score) 
		{
			min = stu->score;
		}
		average+= stu->score;
		if (self < stu->score) 
		{
			p++;
		}
	}
	printf("最高分:%lf\n",max);
	printf("最低分:%lf\n",min);
	printf("平均分:%lf\n",average/(num1-num2));
	printf("你的排名:%d\n",p);
}

教师函数teacher.c

#include <stdio.h>
#include <stdlib.h>
#include <getch.h>
#include <string.h>
#include "student.h"
#include "list.h"
#include "tools.h"
#include "teacher.h"

extern List* list1,*list2,*list3,*list4;
extern int num1,num2,num3,num4;


bool signin_tea(int n)
{
	int pass=0;
	Teacher* tea = malloc(sizeof(Teacher));
	for(Node* node = list3->head;node != NULL;node = node->next)
	{
		tea =node->ptr;
		if (tea->id == n) break;
	}
	if (tea->lock == 1) 
	{
		printf("账号已被锁,请联系老师\n");
		return false;
	}
	for(int i=0;i<3;i++)
	{
		printf("请输入您的密码:");
		scanf("%d",&pass);
		if (tea->password == pass)
		{
			printf("登录成功\n");
			return true;
		}
	}
	printf("账号已被锁,请联系老师\n");
	tea->lock = 1;
	return false;
}
void first_signin_tea(int n)
{
	Teacher* tea = malloc(sizeof(Teacher));
	for(Node* node = list3->head;node != NULL;node = node->next)
	{
		tea =node->ptr;
		if (tea->id == n) break;
	}
	if (tea->flag == 0)
	{
		printf("请输入您的新密码:");
		scanf("%d",&tea->password);
		tea->flag =1;
	}
}
void add_stu(void)
{
	Student* stu = malloc(sizeof(Student));
	printf("请输入学生的姓名和性别");
	stu->id = ++num1;
	stu->chinese = 0;
	stu->math = 0;
	stu->english = 0;
	stu->lock = 0;
	stu->flag = 0;
	stu->password = 123456;
	scanf("%s %c",stu->name,&stu->sex);
	stu->score = stu->chinese+stu->math+stu->english;
	tail_add_list(list1,stu);
}
bool del_stu(void)
{
	size_t id1=0,id2=0;
	printf("请输入要删除的学号:");
	scanf("%u",&id1);
	printf("请再次输入要删除的学号:");
	scanf("%u",&id2);
	if (id1 == id2)
	{
		Student* stu = malloc(sizeof(Student));
		for(Node* node = list1->head;node != NULL;node = node->next)
		{
			stu =node->ptr;
			if (stu->id == id1) break;
		}
		tail_add_list(list2,stu);
		int  cmp(const void* ptr1,const void* ptr2)
		{
			const Student* stu = ptr1;
			const size_t* id = ptr2;
			if (stu->id > *id) return 1;
			else if (stu->id < *id) return -1;
			else return 0;
		}
		if (delete_value_list(list1,&id1,cmp)) 
		{
			
			printf("删除成功\n");
			num2++;
			return true;
		}
		else 
		{
			printf("删除失败\n");
			return false;
		}
	}
	else 
	{
		printf("删除失败\n");
		return false;
	}
	
}
void search_stu_tea()
{
	printf("1、按姓名查找\n");
	printf("2、按学号查找\n");
	printf("3、返回上一级\n");
	switch(get_cmd('1','3')-'0')
	{
		case 1:
		{
			char name[20]={};
			int n=0;
			printf("请输入姓名:");
			gets(name);
			for(Node* node=list1->head; node!=NULL; node=node->next)
			{
				_search_stu(node,name);
			}
			printf("请输入查找的学号:");
			scanf("%d",&n);
			see_stu(n);
			break;
		}
		case 2:
		{
			printf("请输入要查找的学生学号:");
			int n=0;
			scanf("%d",&n);
			see_stu(n);
			break;
		}
		case 3:return ;
	}
}
void _search_stu(Node* node,char *p)
{
	int i=0;
	Student* stu = malloc(sizeof(Student));
	stu = node->ptr;
	while(*p)
	{
		if (*p != stu->name[i]) return;
		p++;
	}
	printf("%d  %s\n",stu->id,stu->name);		
}
void modify_stu_tea()
{
	int n=0;
	printf("请输入你要修改信息的学号\n");
	scanf("%d",&n);
	Student* stu = malloc(sizeof(Student));
	printf("1、修改学生基础信息\n");
	printf("2、修改学生成绩\n");
	printf("3、返回上一层\n");
	switch(get_cmd('1','3')-'0')
		{       
    	    case 1:
    	    {
				for(Node* node = list1->head;node != NULL;node = node->next)
				{
					stu =node->ptr;
					if (stu->id == n) break;
				}
    	    	printf("请输入新的学生的姓名:");
    	    	gets(stu->name);
    	    	printf("请输入新的学生的性别:");
    	    	scanf("%c",&stu->sex);
    	    	break;
    	    }
    	    case 2:
    	    {
    	    	for(Node* node = list1->head;node != NULL;node = node->next)
				{
					stu =node->ptr;
					if (stu->id == n) break;
				}
    	    	printf("请输入新的学生的语文成绩:");
    	    	scanf("%lf",&stu->chinese);
    	    	printf("请输入新的学生的数学成绩:");
    	    	scanf("%lf",&stu->math);
    	    	printf("请输入新的学生的英语成绩:");
    	    	scanf("%lf",&stu->english);
    	    	stu->score = stu->chinese+stu->math+stu->english;
    	    	break;
    	    }
    		case 3:return ;
    	}	
	
}
void input_stu_tea()
{
	printf("1、单个录入\n");
	printf("2、批量录入\n");
	printf("3、返回上一层\n");
	switch(get_cmd('1','3')-'0')
		{       
    	    case 1:
    	    {
    	    	int n=0;
    	    	printf("请输入你要修改信息的学号\n");
				scanf("%d",&n);
				Student* stu = malloc(sizeof(Student));
				for(Node* node = list1->head;node != NULL;node = node->next)
				{
					stu =node->ptr;
					if (stu->id == n) break;
				}
    	    	printf("请输入该学生的语文成绩:");
    	    	scanf("%lf",&stu->chinese);
    	    	printf("请输入该学生的数学成绩:");
    	    	scanf("%lf",&stu->math);
    	    	printf("请输入该学生的英语成绩:");
    	    	scanf("%lf",&stu->english);
    	    	stu->score = stu->chinese+stu->math+stu->english;
    	    	break;
    	    }
    	    case 2:
    	    {
    	    	char frp[20]={};
    	    	printf("请输入要打开的文件");
    	    	gets(frp);
    	    	FILE *fp = fopen(frp,"r");
    	    	Student* stu = malloc(sizeof(Student));
    	    	for (Node* node=list1->head; node!=NULL; node=node->next)
    	    	{
    	    		stu = node->ptr;
    	    		fscanf(fp,"%lf %lf %lf ",&stu->chinese,&stu->math,&stu->english);
    	    		stu->score = stu->chinese+stu->math+stu->english;
    	    	}
    	    	break;
    	    }
    		case 3:return ;
    	}	
}
void reset_stu_tea()
{
	int n=0;
	printf("请输入你要修改密码的学号");
	scanf("%d",&n);
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	printf("请输入该学生的新密码");
	scanf("%d",&stu->password);
}
void show_instu(void)
{
	void show(const void* ptr)
	{
		const Student *stu =ptr;
		printf("%u %s %c %lf %lf %lf \n",stu->id,stu->name,stu->sex,stu->chinese,stu->math,stu->english);
	}
	show_list(list1,show);
}
void show_outstu(void)
{
	void show(const void* ptr)
	{
		const Student *stu =ptr;
		printf("%u %s %c %lf %lf %lf \n",stu->id,stu->name,stu->sex,stu->chinese,stu->math,stu->english);
	}
	show_list(list2,show);
}
void unlock_stu_tea()
{
	int n=0;
	printf("请输入你要解锁的学号");
	scanf("%d",&n);
	Student* stu = malloc(sizeof(Student));
	for(Node* node = list1->head;node != NULL;node = node->next)
	{
		stu =node->ptr;
		if (stu->id == n) break;
	}
	stu->lock = 0;
	
}

void sort_stu(void)
{
	puts("1、按姓名排序");
	puts("2、按学号排序");
	puts("3、按成绩排序");
	puts("4、返回上一级");
	switch(get_cmd('1','4')-'0')
    	{
           case 1:
           {
           		char* arr[num1-num2];
           		int i=0;
           		Student* stu = malloc(sizeof(Student));
           		for(Node* node1 = list1->head;node1 != NULL;node1 = node1->next)
           		{
           			stu = node1->ptr;
           			arr[i++] = stu->name;
           		}
           		quick1_sort(arr,num1-num2);
           		for(int j=0;j<i;j++)
           		{
           			for(Node* node2 = list1->head;node2 != NULL;node2 = node2->next)
         			{
         				stu = node2 ->ptr;
           				if (arr[j] == stu->name)
           				{
           					printf("第%d名:%d %s %lf\n",j+1,stu->id,stu->name,stu->score);
           					break;
           				}
           			}
           		}
           		break;
           }
           case 2:
           {
           		show_instu();
           		break;
           }
           case 3:
           {	
           		double arr[num1-num2];
           		int i=0;
           		Student* stu = malloc(sizeof(Student));
           		for(Node* node1 = list1->head;node1 != NULL;node1 = node1->next)
           		{
           			stu = node1->ptr;
           			arr[i++] = stu ->score;
           		}
           		quick_sort(arr,num1-num2);
           		i=0;
           		
           		for(Node* node1 = list1->head;node1 != NULL;node1 = node1->next)
           		{
           			for(Node* node2 = list1->head;node2 != NULL;node2 = node2->next)
         			{
         				int n=i+1;
         				stu = node2 ->ptr;
           				if (arr[i] == stu->score)
           				{
           					printf("第%d名:%d %s %lf\n",n,stu->id,stu->name,arr[i++]);
           					break;
           				}
           			}
           		}
           }
           case 4:return;
        }
}

校长函数principal.c

#include <stdio.h>
#include "principal.h"
#include "list.h"
#include "tools.h"
#include <stdlib.h>
#include <getch.h>
#include <string.h>
#include "teacher.h"

extern List* list1,*list2,*list3,*list4;
extern int num1,num2,num3,num4;


bool signin_boss(void)
{
	if (boss.lock == 1) 
	{
		printf("已被锁定\n");
		return false;
	}
	int pass=0;
	for(int i=0;i<3;i++)
	{
		printf("请输入您的密码:");
		scanf("%d",&pass);
		if (pass == boss.password) 
		{
			printf("登录成功\n");
			return true;
		}
	}
	printf("账号已被锁\n");
	boss.lock = 1;
	return false;	
}
void unlock_boss(void)
{
	if (boss.lock == 1)
	{
		printf("账号被锁,请输入secret:");
		int n=0;
		scanf("%d",&n);
		clean_stdin();
		if (n == boss.secret)
		{
			printf("密码重置为123456\n");
			boss.lock = 0;
			boss.password = 123456;
			
		}
		else 
		{
			printf("secret错误\n");
		}
	}
}
void first_signin_boss(void)
{
	if (!boss.flag)
	{
		printf("请输入您的新密码");
		scanf("%d",&boss.password);
		boss.flag = 1;
	}
}
void add_tea(void)
{
	Teacher* tea = malloc(sizeof(Teacher));
	printf("请输入教师的姓名和性别");
	tea->id = ++num3;
	tea->lock = 0;
	tea->flag = 0;
	tea->password = 123456;
	scanf("%s %c",tea->name,&tea->sex);
	tail_add_list(list3,tea);
}
bool del_tea(void)
{
	size_t id1=0,id2=0;
	printf("请输入要删除的教师的工号:");
	scanf("%u",&id1);
	printf("请再次输入要删除的教师的工号:");
	scanf("%u",&id2);
	if (id1 == id2)
	{
		Node* node = list1->head;
		Teacher* tea = malloc(sizeof(Teacher));
		for(int i=0;i<id1-1;i++)
		{
			node = node->next;
		}
		tea =node->ptr;
		tail_add_list(list4,tea);
		int  cmp(const void* ptr1,const void* ptr2)
		{
			const Teacher* tea = ptr1;
			const size_t* id = ptr2;
			if (tea->id > *id) return 1;
			else if (tea->id < *id) return -1;
			else return 0;
		}
		if (delete_value_list(list3,&id1,cmp)) 
		{
			
			printf("删除成功\n");
			num4++;
			return true;
		}
		else 
		{
			printf("删除失败\n");
			return false;
		}
	}
	else 
	{
		printf("删除失败\n");
		return false;
	}
	
}
void reset_boss_boss(void)
{
	printf("请输入您的新密码");
	scanf("%d",&boss.password);
}
void reset_tea_boss(void)
{
	int n=0;
	printf("请输入你要修改密码的工号");
	scanf("%d",&n);
	Node* node = list3->head;
	Teacher* tea = malloc(sizeof(Teacher));
	for(int i=0;i<n-1;i++)
	{
		node = node->next;
	}
	tea =node->ptr;
	printf("请输入该教师的新密码");
	scanf("%d",&tea->password);
	
}
void show_intea(void)
{
	void show(const void* ptr)
	{
		const Teacher* tea =ptr;
		printf("%u %s %c \n",tea->id,tea->name,tea->sex);
	}
	show_list(list3,show);
}
void show_outtea(void)
{
	void show(const void* ptr)
	{
		const Teacher* tea =ptr;
		printf("%u %s %c \n",tea->id,tea->name,tea->sex);
	}
	show_list(list4,show);
}


void modify_tea_boss(void)
{
	int n=0;
	printf("请输入你要修改信息的工号\n");
	scanf("%d",&n);
	Teacher* tea = malloc(sizeof(Teacher));
	printf("1、修改教师基础信息\n");
	printf("2、返回上一层\n");
	switch(get_cmd('1','2')-'0')
		{       
    	    case 1:
    	    {
				for(Node* node = list3->head;node != NULL;node = node->next)
				{
					tea =node->ptr;
					if (tea->id == n) break;
				}
    	    	printf("请输入新的教师的姓名:");
    	    	gets(tea->name);
    	    	printf("请输入新的教师的性别:");
    	    	scanf("%c",&tea->sex);
    	    	break;
    	    }
    	    case 2:return;
    	}	
	
}

文件加密

static bool de_code(const char* path)
{
	FILE* frp = fopen(path,"r");
	if(NULL == frp) return false;
	size_t len = strlen(PASSWORD) , i = 0;
	uint8_t data = 0;
	
	FILE* fwp = fopen(TEMP_PATH,"w");
	
	while(fread(&data,1,1,frp))
	{
		data ^= PASSWORD[i++%len];
		fwrite(&data,1,1,fwp);
	}
	
	fclose(frp); frp = NULL;
	fclose(fwp); fwp = NULL;
	
	remove(path);
	rename(TEMP_PATH,path);
	return true;
}

快速排序

void _quick1_sort(char* arr[],size_t left,size_t right)
{
	if(left >= right) return;
	int pi = (left+right)/2;
	char* pv = arr[pi];
	
	int l = left , r = right;
	while(l < r)
	{	
		while(l<pi && (1 == strcmp(arr[l],pv) || 0 == strcmp(arr[l],pv))) l++;
		if(l<pi) 
		{
			arr[pi] = arr[l];
			pi = l;
		}
		while(pi<r && (1 == strcmp(pv,arr[r]) || 0 == strcmp(pv,arr[r]))) r--;
		if(pi<r) 
		{
			arr[pi] = arr[r];
			pi = r;
		}
	}
	arr[pi] = pv;
	if(pi-left > 1) _quick1_sort(arr,left,pi-1);
	if(right-pi > 1) _quick1_sort(arr,pi+1,right);
}

void quick1_sort(char* a[],size_t len)
{
	_quick1_sort(a,0,len-1);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值