BJFU 2020大一计导课设 教务系统

本代码为2020年北京林业大学计算机专业大一大作业,教师信息管理系统
发布于此仅供学习交流使用,当中可能存在部分bug,欢迎指正。
请勿用于个人作业抄袭,当中存在本人刻意留下的bug,后果自负

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int over = 1;
char restrictcollege[20][20] = {"计算机学院", "通信学院", "电子学院", "经济学院", "园林学院", "社会学院", "电气学院", "船舶学院", "自动化学院", "理学院", "法学院", "医学院"};
char restricttitle[5][20] = {"教授", "副教授", "讲师", "助教"};
struct Basic
{
	char number[20];
	char name[20];
	char college[20];
	char title[20];
};
struct Salary
{
	char number[20];
	int month[12];
	int base[12];
	int allowance[12];
	int deduct[12];
	int predict[12];
	int fact[12];
};
void prompt();
void prompt0();
void prompt1();
void prompt2();
void prompt3();
void prompt4();
void prompt5();
void logbasic(int);
void savebasic(int, struct Basic[]);
void changebasic(struct Basic[]);
int judgebasic(int, struct Basic[]);
void logsalary(int);
void savesalary(int, struct Salary[]);
void changesalary();
int judgesalary(int, struct Salary[]);
int judgemonth(int, int, struct Salary[]);
int judgecollege(char[]);
int judgetitle(char[]);
void show1();
void show2(int);
void show3(char[], int);
void show4(char *, int);
void show5(char *);
void show6(char *);
void show7();
void change1();
void change2();
void change3();
void count1();
void count2();
void item();
void item1();
void item2();
void item3();
void item4();
void item5();
void prompt()
{
	printf("请选择执行操作\n");
	printf("【1】.录入教师数据\n");
	printf("【2】.修改教师数据\n");
	printf("【3】.查询教师数据\n");
	printf("【4】.统计教师数据\n");
	printf("【5】.退出系统\n");
}
void prompt0()
{
	printf("欢迎使用教师信息管理系统\n");
}
void prompt1()
{
	printf("【1】.录入教师基本信息\n");
	printf("【2】.录入教师工资信息\n");
	printf("【3】.返回主菜单\n");
}
void prompt2()
{
	printf("【1】.输入教师工号修改信息\n");
	printf("【2】.输入教师姓名修改信息\n");
	printf("【3】.删除教师信息\n");
	printf("【4】.返回主菜单\n");
}
void prompt3()
{
	printf("【1】.显示所有教师基本信息\n");
	printf("【2】.显示该月所有教师工资信息\n");
	printf("【3】.输入工号查询信息\n");
	printf("【4】.输入姓名查询信息\n");
	printf("【5】.显示所有教师所有信息\n");
	printf("【6】.返回主菜单\n");
}
void prompt4()
{
	printf("【1】.统计学院教师平均应发工资和平均实发工资\n");
	printf("【2】.统计职称教师平均应发工资和平均实发工资\n");
	printf("【3】.返回主菜单\n");
}
void prompt5()
{
	printf("确定要退出系统吗?\n");
	printf("y/s\n");
}
void item()
{
	int choice;
	while (over)
	{
		prompt();
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:
			item1();
			break;
		case 2:
			item2();
			break;
		case 3:
			item3();
			break;
		case 4:
			item4();
			break;
		case 5:
			item5();
			break;
		default:
			printf("wrong input!\n");
			item();
			break;
		}

		if (!over)
			break;
	}
}
void item1()
{
	prompt1();
	int choice1, n;
	scanf("%d", &choice1);
	while (choice1 != 3)
	{
		if (choice1 == 1)
		{
			printf("请输入教师数量");
			scanf("%d", &n);
			logbasic(n);
		}
		else if (choice1 == 2)
		{
			printf("请输入教师数量:");
			scanf("%d", &n);
			logsalary(n);
		}
		else
			printf("请输入正确数字\n");
		prompt1();
		scanf("%d", &choice1);
	}
}
void item2()
{
	int choice2;
	struct Basic te[1000];
	struct Salary se[1000];
	char number[20];
	prompt2();
	scanf("%d", &choice2);
	while (choice2 != 4)
	{
		if (choice2 == 1)
		{
			printf("请输入工号:\n");
			//scanf("%s",number);
			change1();
			//show5(te,number);
			//show6(se,number);
		}
		else if (choice2 == 2)
		{
			printf("请输入姓名:\n");
			change2();
		}
		else if (choice2 == 3)
		{
			printf("请输入工号:\n");
			change3();
		}
		else
			printf("请输入正确数字\n");
		prompt2();
		scanf("%d", &choice2);
	}
}
void item3()
{
	int choice3;
	int month;
	char name[20];
	char number[20];
	struct Basic te[1000];
	struct Salary se[1000];
	prompt3();
	scanf("%d", &choice3);
	while (choice3 != 6)
	{
		if (choice3 == 1)
			show1();
		else if (choice3 == 2)
		{
			printf("请输入月份:\n");
			scanf("%d", &month);
			show2(month);
		}
		else if (choice3 == 3)
		{
			printf("请输入工号:\n");
			scanf("%s", number);
			printf("请输入月份:\n");
			scanf("%d", &month);
			show3(number, month);
		}
		else if (choice3 == 4)
		{
			printf("请输入姓名:\n");
			scanf("%s", name);
			printf("请输入月份:\n");
			scanf("%d", &month);
			show4(name, month);
		}
		else if (choice3 == 5)
			show7();
		prompt3();
		scanf("%d", &choice3);
	}
}
void item4()
{
	int choice4;
	prompt4();
	scanf("%d", &choice4);
	while (choice4 != 3)
	{
		if (choice4 == 1)
		{
			printf("请输入月份:\n");
			count1();
		}
		else if (choice4 == 2)
		{
			printf("请输入月份:\n");
			count2();
		}
		else
			printf("请输入正确数字\n");
		prompt4();
		scanf("%d", &choice4);
	}
}
void item5()
{
	prompt5();
	char choice5;
	getchar();
	scanf("%c", &choice5);
	if (choice5 == 'y')
		over = 0;
	else
		over = 1;
}
void logbasic(int n)
{
	int i, a = 0, b, c, d;
	struct Basic te[1000];
	for (i = 0; i < n; i++)
	{
		printf("请输入工号:");
		scanf("%s", te[i].number);
		a = judgebasic(i, te);
		if (a)
		{
			printf("wrong date!\n");
			te[i].number[0] = '\0';
			i--;
			printf("继续请输入1,退出请输入0\n");
			scanf("%d", &b);
			if (!b)
				break;
		}
		else
		{
			printf("请输入姓名:\n");
			scanf("%s", te[i].name);
			printf("请输入学院:\n");
			scanf("%s", te[i].college);
			c = judgecollege(te[i].college);
			if (c)
			{
				printf("学院不存在!\n");
				strcpy(te[i].number, "");
				strcpy(te[i].name, "");
				strcpy(te[i].college, "");
				strcpy(te[i].title, "");
			}
			else
			{
				printf("请输入职称:\n");
				scanf("%s", te[i].title);
				d = judgetitle(te[i].title);
				if (d)
				{
					printf("职称不存在!\n");
					strcpy(te[i].number, "");
					strcpy(te[i].name, "");
					strcpy(te[i].college, "");
					strcpy(te[i].title, "");
				}
			}
		}
	}
	savebasic(n, te);
	changebasic(te);
}
int judgebasic(int n, struct Basic te[])
{
	FILE *fp;
	struct Basic sum[1000], a;
	int i, j, m = 0;
	int b = 0;
	if ((fp = fopen("basic", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sum[i], sizeof(struct Basic), 1, fp) == 1; i++)
		m++;
	for (i = 0; i < m; i++)
	{
		if (strcmp(sum[i].number, te[n].number) == 0)
		{
			b = 1;
			break;
		}
	}
	for (i = 0; i < n; i++)
	{
		if (strcmp(te[i].number, te[n].number) == 0)
		{
			b = 1;
			break;
		}
	}
	fclose(fp);
	return b;
}
void savebasic(int n, struct Basic te[])
{
	FILE *fp = NULL;
	struct Basic sum[1000];
	int i, flag = 0, count = 0;
	if ((fp = fopen("basic", "a+")) == NULL)
		printf("Cannot open the file!\n");
	//for(i=0;fscanf(fp,"%s%s%s%s",sum[i].number,sum[i].name,sum[i].college,sum[i].title)!=EOF;i++);
	fseek(fp, 0L, 2);
	for (i = 0; i < n; i++)
	{
		if (strcmp(te[i].number, "") != 0)
			if (fwrite(&te[i], sizeof(struct Basic), 1, fp) != 1)
				printf("error write\n");
	}
	fclose(fp);
}
void changebasic(struct Basic te[])
{
	FILE *fp = NULL;
	struct Basic sum[1000], a;
	int i, j, n = 0;
	if ((fp = fopen("basic", "r+")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sum[i], sizeof(struct Basic), 1, fp) == 1; i++)
	{
		n++;
	}
	for (i = 0; i < n - 1; i++)
		for (j = 0; j < n - i - 1; j++)
		{
			if (strcmp(sum[j].number, sum[j + 1].number) > 0)
			{
				a = sum[j];
				sum[j] = sum[j + 1];
				sum[j + 1] = a;
			}
		}
	fseek(fp, 0L, 0);
	fwrite(sum, sizeof(struct Basic), n, fp);
	fclose(fp);
}
void logsalary(int n)
{
	show1();
	struct Salary te[1000], se[1000];
	int i = 0;
	int a, b, x, j;
	for (i = 0; i < n; i++)
	{
		printf("请输入工号:");
		scanf("%s", te[i].number);
		a = judgesalary(i, te);
		if (a)
		{
			printf("请输入月份:\n");
			scanf("%d", &x);
			te[i].month[x - 1] = x;
			b = judgemonth(x - 1, i, te);
			if (b)
			{
				printf("请输入基本工资:\n");
				scanf("%d", &te[i].base[x - 1]);
				printf("请输入业绩津贴:\n");
				scanf("%d", &te[i].allowance[x - 1]);
				printf("请输入扣除费用:\n");
				scanf("%d", &te[i].deduct[x - 1]);
				te[i].predict[x - 1] = te[i].base[x - 1] + te[i].allowance[x - 1];
				printf("应发工资:%d\n", te[i].predict[x - 1]);
				te[i].fact[x - 1] = te[i].predict[x - 1] - te[i].deduct[x - 1];
				printf("实发工资:%d\n", te[i].fact[x - 1]);
			}
			else
			{
				printf("wrong month!\n");
				strcpy(te[i].number, "");
			}
		}
		else
			printf("wrong number!\n");
	}
	savesalary(n, te);
	changesalary();
	for (j = 0; j < i; j++)
		te[j] = se[j];
}
int judgesalary(int n, struct Salary te[])
{
	FILE *fp;
	struct Basic sum1[1000], a;
	int i, j, m = 0;
	int b = 0;
	if ((fp = fopen("basic", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sum1[i], sizeof(struct Basic), 1, fp) == 1; i++)
		m++;
	for (i = 0; i < m; i++)
	{
		if (strcmp(sum1[i].number, te[n].number) == 0)
		{
			b = 1;
			break;
		}
	}
	fclose(fp);
	return b;
}
int judgemonth(int month, int n, struct Salary te[])
{
	FILE *fp;
	struct Salary sum1[1000], a;
	int i, j, m = 0;
	int b = 1;
	if ((fp = fopen("salary", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sum1[i], sizeof(struct Salary), 1, fp) == 1; i++)
		m++;
	for (i = 0; i < m; i++)
	{
		if (sum1[i].month[month] == month + 1 && strcmp(sum1[i].number, te[n].number) == 0)
		{
			b = 0;
			break;
		}
	}
	for (i = 0; i < n; i++)
	{
		if (te[i].month[month] == te[n].month[month] && strcmp(te[i].number, te[n].number) == 0)
			b = 0;
	}
	if (month > 11 || month < 0)
		b = 0;
	fclose(fp);
	return b;
}
void savesalary(int n, struct Salary te[])
{
	FILE *fp1, *fp2;
	int m, p, q, i, j, k = 0;
	int month;
	int a[100];
	for (i = 0; i < 100; i++)
		a[i] = -1;
	struct Salary sum[1000], sums[1000];
	if ((fp1 = fopen("salary", "r")) == NULL)
		printf("Cannot open the file!\n");
	if ((fp2 = fopen("salary1", "w")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; i < n - 1; i++)
		for (j = i + 1; j < n; j++)
		{
			if (strcmp(te[i].number, te[j].number) == 0)
				for (month = 1; month <= 12; month++)
					if (month == te[j].month[month - 1])
					{
						te[i].month[month - 1] = te[j].month[month - 1];
						te[i].base[month - 1] = te[j].base[month - 1];
						te[i].allowance[month - 1] = te[j].allowance[month - 1];
						te[i].deduct[month - 1] = te[j].deduct[month - 1];
						te[i].predict[month - 1] = te[j].predict[month - 1];
						te[i].fact[month - 1] = te[j].fact[month - 1];
						te[j].number[0] = '\0';
						a[k] = j;
						k++;
						break;
					}
			if (te[i].number[0] == '\0')
				break;
		}
	m = 0;
	for (i = 0; fread(&sum[i], sizeof(struct Salary), 1, fp1) == 1; i++)
		m = i;
	m = i;
	for (j = 0; j < n; j++)
		for (i = 0; i < m; i++)
		{
			if (strcmp(sum[i].number, te[j].number) == 0)
			{

				for (month = 1; month <= 12; month++)
					if (month == te[j].month[month - 1])
					{
						sum[i].month[month - 1] = te[j].month[month - 1];
						sum[i].base[month - 1] = te[j].base[month - 1];
						sum[i].allowance[month - 1] = te[j].allowance[month - 1];
						sum[i].deduct[month - 1] = te[j].deduct[month - 1];
						sum[i].predict[month - 1] = te[j].predict[month - 1];
						sum[i].fact[month - 1] = te[j].fact[month - 1];
					}
				a[k] = j;
				k++;
				break;
			}
			if (strcmp(te[j].number, "") == 0)
			{
				a[k] = j;
				k++;
			}
		}
	//fseek(fp2,0L*sizeof(struct Salary),0);
	fwrite(sum, sizeof(struct Salary), m, fp2);
	fseek(fp2, 0L * sizeof(struct Salary), 1);
	for (i = 0; i < n; i++)
	{
		p = 1;
		for (k = 0; a[k] != -1; k++)
		{
			if (a[k] == i)
			{
				p = 0;
				break;
			}
		}
		if (p)
			if (fwrite(&te[i], sizeof(struct Salary), 1, fp2) != 1)
				printf("error write\n");
	}
	fclose(fp1);
	fclose(fp2);
	fp1 = fopen("salary", "w");
	fp2 = fopen("salary1", "r");
	for (i = 0; fread(&sums[i], sizeof(struct Salary), 1, fp2) == 1; i++)
		fwrite(&sums[i], sizeof(struct Salary), 1, fp1);
	fclose(fp1);
	fclose(fp2);
}
void changesalary()
{
	FILE *fp;
	struct Salary sum1[1000], sum2[1000], a;
	int i, j, x, y, n = 0;
	if ((fp = fopen("salary", "r+")) == NULL)
		printf("Cannot open the file!\n");
	x = 1;
	for (i = 0; fread(&sum1[i], sizeof(struct Salary), 1, fp) == 1; i++)
		n++;
	/*while(x<12)
	{	
	     for(i=0;sum1;i++)
	     if(sum1[i].month[0]==x)
	     {
             sum2[j]=sum1[i];
	         j++;
	     }
		x++;
	}*/
	for (i = 0; i < n - 1; i++)
		for (j = 0; j < n - i - 1; j++)
		{
			if (strcmp(sum1[j].number, sum1[j + 1].number) > 0)
			{
				a = sum1[j];
				sum1[j] = sum1[j + 1];
				sum1[j + 1] = a;
			}
		}
	fseek(fp, 0L, 0);
	fwrite(sum1, sizeof(struct Salary), n, fp);
	fclose(fp);
}
void change1()
{
	FILE *fpb, *fps;
	char number[20];
	struct Basic sumb[1000];
	struct Salary sums[1000];
	int i, j, x, a = 0;
	int b, c;
	scanf("%s", number);
	show5(number);
	show6(number);
	if ((fpb = fopen("basic", "r+")) == NULL)
		printf("Cannot open the basicfile!");
	if ((fps = fopen("salary", "r+")) == NULL)
		printf("Cannot open the salaryfile!");
	for (i = 0; fread(&sumb[i], sizeof(struct Basic), 1, fpb) == 1; i++)
		if (strcmp(sumb[i].number, number) == 0)
		{
			fseek(fpb, -1L * sizeof(struct Basic), 1);
			a = 1;
			break;
		}
	if (a)
	{
		printf("请输入姓名:\n");
		scanf("%s", sumb[i].name);
		printf("请输入学院:\n");
		scanf("%s", sumb[i].college);
		b = judgecollege(sumb[i].college);
		if (b)
		{
			printf("学院不存在!\n");
			strcpy(sumb[i].number, "");
			strcpy(sumb[i].name, "");
			strcpy(sumb[i].college, "");
			strcpy(sumb[i].title, "");
		}
		else
		{
			printf("请输入职称:\n");
			scanf("%s", sumb[i].title);
			c = judgetitle(sumb[i].title);
			if (c)
			{
				printf("职称不存在!\n");
				strcpy(sumb[i].number, "");
				strcpy(sumb[i].name, "");
				strcpy(sumb[i].college, "");
				strcpy(sumb[i].title, "");
			}
		}
		if (b == 0 && c == 0)
		{
			fwrite(&sumb[i], sizeof(struct Basic), 1, fpb);
			for (i = 0; fread(&sums[i], sizeof(struct Salary), 1, fps); i++)
				if (strcmp(sums[i].number, number) == 0)
				{
					fseek(fps, -1L * sizeof(struct Salary), 1);
					break;
				}
			printf("请输入月份(退出请输入0):\n");
			scanf("%d", &x);
			while (x)
			{
				if (sums[i].month[x - 1] != x)
					printf("wrong month!\n");
				else
				{
					printf("请输入基本工资:\n");
					scanf("%d", &sums[i].base[x - 1]);
					printf("请输入业绩津贴:\n");
					scanf("%d", &sums[i].allowance[x - 1]);
					printf("请输入扣除费用:\n");
					scanf("%d", &sums[i].deduct[x - 1]);
					sums[i].predict[x - 1] = sums[i].base[x - 1] + sums[i].allowance[x - 1];
					printf("应发工资:%d\n", sums[i].predict[x - 1]);
					sums[i].fact[x - 1] = sums[i].predict[x - 1] - sums[i].deduct[x - 1];
					printf("实发工资:%d\n", sums[i].fact[x - 1]);
				}
				printf("请输入月份(退出请输入0):\n");
				scanf("%d", &x);
			}
			//else
			// printf("wrong number!\n");
			fwrite(&sums[i], sizeof(struct Salary), 1, fps);
		}
	}
	fclose(fps);
	fclose(fpb);
}
void change2()
{
	FILE *fpb, *fps;
	char name[20];
	char number[20];
	scanf("%s", name);
	struct Basic sumb1[1000], sumb2[1000];
	struct Salary sums1[1000], sums2[1000];
	int a[1000], b[1000], c = 0;
	int i1, i2, j1 = 0, j2 = 0;
	if ((fpb = fopen("basic", "r+")) == NULL)
		printf("Cannot open the file!");
	if ((fps = fopen("salary", "r+")) == NULL)
		printf("Cannot open the file!");
	for (i1 = 0; fread(&sumb1[i1], sizeof(struct Basic), 1, fpb) == 1; i1++)
	{
		if (strcmp(sumb1[i1].name, name) == 0)
		{
			c = 1;
			sumb2[j1] = sumb1[i1];
			show5(sumb2[j1].number);
			for (i2 = 0; fread(&sums1[i2], sizeof(struct Salary), 1, fps) == 1; i2++)
				if (strcmp(sumb2[j1].number, sums1[i2].number) == 0)
				{
					sums2[j2] = sums1[i2];
					show6(sums2[j2].number);
					j2++;
					break;
				}
			j1++;
		}
	}
	if (c)
	{
		printf("请输入工号:\n");
		change1();
	}
	else
		printf("查无此人!\n");

	fclose(fpb);
	fclose(fps);
}
void change3()
{
	FILE *fpb1, *fpb2, *fps1, *fps2;
	char number[20];
	int i;
	struct Basic te[1000], te1[1000];
	struct Salary se[1000], se1[1000];
	if ((fpb1 = fopen("basic", "r+")) == NULL)
		printf("Cannot open the basicfile!\n");
	if ((fpb2 = fopen("basic1", "w+")) == NULL)
		printf("Cannot open the basicfile!\n");
	if ((fps1 = fopen("salary", "r+")) == NULL)
		printf("Cannot open the salaryfile!\n");
	if ((fps2 = fopen("salary1", "w+")) == NULL)
		printf("Cannot open the salaryfile!\n");
	char decision1, decision2;
	scanf("%s", number);
	printf("是否删除改工号及其数据?y/n \n");
	getchar();
	scanf("%c", &decision1);
	if (decision1 == 'y')
	{
		printf("删除后数据将无法恢复,请确认。 y/n \n");
		getchar();
		scanf("%c", &decision2);
		if (decision2 == 'y')
		{
			for (i = 0; fread(&te[i], sizeof(struct Basic), 1, fpb1) == 1; i++)
			{
				if (strcmp(te[i].number, number) == 0)
					printf("删除基本信息成功\n");
				else
					fwrite(&te[i], sizeof(struct Basic), 1, fpb2);
			}
			for (i = 0; fread(&se[i], sizeof(struct Salary), 1, fps1) == 1; i++)
			{
				if (strcmp(se[i].number, number) == 0)
					printf("删除工资信息成功\n");
				else
					fwrite(&se[i], sizeof(struct Salary), 1, fps2);
			}
		}
	}
	fclose(fpb1);
	fclose(fpb2);
	fclose(fps1);
	fclose(fps2);
	fpb1 = fopen("basic", "w");
	fpb2 = fopen("basic1", "r");
	fps1 = fopen("salary", "w");
	fps2 = fopen("salary1", "r");
	for (i = 0; fread(&te1[i], sizeof(struct Basic), 1, fpb2) == 1; i++)
		fwrite(&te1[i], sizeof(struct Basic), 1, fpb1);
	for (i = 0; fread(&se1[i], sizeof(struct Salary), 1, fps2) == 1; i++)
		fwrite(&se1[i], sizeof(struct Salary), 1, fps1);
	fclose(fpb1);
	fclose(fpb2);
	fclose(fps1);
	fclose(fps2);
}
int judgecollege(char cl[])
{
	int n = 20;
	int i, a = 1;
	for (i = 0; i < n; i++)
	{
		if (strcmp(cl, restrictcollege[i]) == 0)
		{
			a = 0;
			break;
		}
	}
	return a;
}
int judgetitle(char tl[])
{
	int n = 20;
	int i, a = 1;
	for (i = 0; i < n; i++)
	{
		if (strcmp(tl, restricttitle[i]) == 0)
		{
			a = 0;
			break;
		}
	}
	return a;
}
void show1()
{
	FILE *fp;
	char *buf;
	int i;
	struct Basic te[1000];
	if ((fp = fopen("basic", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	//fseek(fp,0L,0);
	for (i = 0; fread(&te[i], sizeof(struct Basic), 1, fp) == 1; i++)
	{
		printf("工号:%s\n", te[i].number);
		printf("姓名:%s\n", te[i].name);
		printf("学院:%s\n", te[i].college);
		printf("职称:%s\n", te[i].title);
	}
	fclose(fp);
}
void show2(int month)
{
	FILE *fp;
	char *buf;
	int i = 0;
	struct Salary sum[1000];
	if ((fp = fopen("salary", "r")) == NULL)
	{
		printf("Cannot open  the file!\n");
	}
	for (i = 0; fread(&sum[i], sizeof(struct Salary), 1, fp) == 1; i++)
	{
		if (sum[i].month[month - 1] == month)
		{
			printf("工号:%s\t", sum[i].number);
			printf("月份:%d\t", sum[i].month[month - 1]);
			printf("基本工资:%d\t", sum[i].base[month - 1]);
			printf("业绩津贴:%d\t", sum[i].allowance[month - 1]);
			printf("扣除费用:%d\t", sum[i].deduct[month - 1]);
			printf("应发工资:%d\t", sum[i].predict[month - 1]);
			printf("实发工资:%d\n", sum[i].fact[month - 1]);
			sum[i].month[month - 1] = 0;
		}
	}
	fclose(fp);
}
void show3(char number[], int month)
{
	FILE *fpb, *fps;
	int i, a = 1, b = 1;
	struct Basic te[1000];
	struct Salary se[1000];
	if ((fps = fopen("salary", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	if ((fpb = fopen("basic", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	for (i = 0; fread(&te[i], sizeof(struct Basic), 1, fpb) == 1; i++)
	{
		if (strcmp(number, te[i].number) == 0)
		{
			printf("工号:%s\n", te[i].number);
			printf("姓名:%s\n", te[i].name);
			printf("学院:%s\n", te[i].college);
			printf("职称:%s\n", te[i].title);
			a = 0;
		}
	}
	for (i = 0; fread(&se[i], sizeof(struct Salary), 1, fps) == 1; i++)
	{
		if (strcmp(se[i].number, number) == 0 && se[i].month[month - 1] == month)
		{
			printf("工号:%s\t", se[i].number);
			printf("月份:%d\t", se[i].month[month - 1]);
			printf("基本工资:%d\t", se[i].base[month - 1]);
			printf("业绩津贴:%d\t", se[i].allowance[month - 1]);
			printf("扣除费用:%d\t", se[i].deduct[month - 1]);
			printf("应发工资:%d\t", se[i].predict[month - 1]);
			printf("实发工资:%d\n", se[i].fact[month - 1]);
			b = 1;
		}
	}
	if (a)
		printf("暂无该教师数据\n");
	if (!a && b)
		printf("暂无该月工资数据\n");
	fclose(fpb);
	fclose(fps);
}
void show4(char *name, int month)
{
	FILE *fpb, *fps;
	int i, a = 1, b = 1;
	struct Basic te[1000];
	struct Salary se[1000];
	char *number;
	if ((fps = fopen("salary", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	if ((fpb = fopen("basic", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	for (i = 0; fread(&te[i], sizeof(struct Basic), 1, fpb) == 1; i++)
	{
		if (strcmp(te[i].name, name) == 0)
		{
			printf("工号:%s\n", te[i].number);
			printf("姓名:%s\n", te[i].name);
			printf("学院:%s\n", te[i].college);
			printf("职称:%s\n", te[i].title);
			number = te[i].number;
			a = 0;
		}
	}
	if (a == 0)
		for (i = 0; fread(&se[i], sizeof(struct Salary), 1, fps) == 1; i++)
		{
			if (strcmp(se[i].number, number) == 0 && se[i].month[month - 1] == month)
			{
				printf("工号:%s\t", se[i].number);
				printf("月份:%d\t", se[i].month[month - 1]);
				printf("基本工资:%d\t", se[i].base[month - 1]);
				printf("业绩津贴:%d\t", se[i].allowance[month - 1]);
				printf("扣除费用:%d\t", se[i].deduct[month - 1]);
				printf("应发工资:%d\t", se[i].predict[month - 1]);
				printf("实发工资:%d\n", se[i].fact[month - 1]);
				b = 0;
			}
		}
	if (a)
		printf("查无此人!\n");
	if (a == 0 && b == 1)
		printf("暂无该月工资信息\n");
	fclose(fpb);
	fclose(fps);
}
void show5(char *number)
{
	FILE *fpb;
	struct Basic sum[100];
	int i;
	if ((fpb = fopen("basic", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}

	for (i = 0; fread(&sum[i], sizeof(struct Basic), 1, fpb); i++)
	{
		if (strcmp(number, sum[i].number) == 0)
		{
			printf("工号:%s\n", sum[i].number);
			printf("姓名:%s\n", sum[i].name);
			printf("学院:%s\n", sum[i].college);
			printf("职称:%s\n", sum[i].title);
		}
	}
}
void show6(char *number)
{
	FILE *fps;
	struct Salary sum[100];
	int i, j;
	if ((fps = fopen("salary", "r")) == NULL)
	{
		printf("Cannot open the file!\n");
	}
	for (i = 0; fread(&sum[i], sizeof(struct Salary), 1, fps) == 1; i++)
	{
		if (strcmp(sum[i].number, number) == 0)
		{
			//printf("工号:%s\n",sum[i].number);
			for (j = 0; j < 12; j++)
			{
				printf("月份%d:\t", j + 1);
				printf("基本工资:%d\t", sum[i].base[j]);
				printf("业绩津贴:%d\t", sum[i].allowance[j]);
				printf("扣除费用:%d\t", sum[i].deduct[j]);
				printf("应发工资:%d\t", sum[i].predict[j]);
				printf("实发工资:%d\n", sum[i].fact[j]);
			}
		}
	}
}
void show7()
{
	FILE *fpb, *fps;
	int i, j, k, n = 0;
	struct Basic te[1000];
	struct Salary se[1000];
	if ((fpb = fopen("basic", "r")) == NULL)
		printf("Cannot open the file!\n");
	if ((fps = fopen("salary", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&se[i], sizeof(struct Salary), 1, fps) == 1; i++)
		n++;
	for (i = 0; fread(&te[i], sizeof(struct Basic), 1, fpb) == 1; i++)
	{
		printf("工号:%s\n", te[i].number);
		printf("姓名:%s\n", te[i].name);
		printf("学院:%s\n", te[i].college);
		printf("职称:%s\n", te[i].title);
		for (j = 0; j < n; j++)
		{
			if (strcmp(te[i].number, se[j].number) == 0)
			{
				for (k = 0; k < 12; k++)
				{
					printf("月份%d:\t", k + 1);
					printf("基本工资:%d\t", se[j].base[k]);
					printf("业绩津贴:%d\t", se[j].allowance[k]);
					printf("扣除费用:%d\t", se[j].deduct[k]);
					printf("应发工资:%d\t", se[j].predict[k]);
					printf("实发工资:%d\n", se[j].fact[k]);
				}
				break;
			}
		}
	}
	fclose(fpb);
	fclose(fps);
}
void count1()
{
	FILE *fpb, *fps;
	int month, i, j, k, l, m, n, n1, n2, n3, a;
	j = 1;
	m = 1;
	n1 = 0;
	n2 = 0;
	n3 = 0;
	scanf("%d", &month);
	struct Basic sumb[1000];
	struct Salary sums[1000];
	char college[20][20], tsc[20];
	double averagep[20], averagef[20], ts;
	int sump[20] = {0};
	int sumf[20] = {0};
	int max;
	if ((fps = fopen("salary", "r")) == NULL)
		printf("Cannot open the file!\n");
	if ((fpb = fopen("basic", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sumb[i], sizeof(struct Basic), 1, fpb) == 1; i++)
		n1++;
	for (i = 0; fread(&sums[i], sizeof(struct Salary), 1, fps) == 1; i++)
		n2++;
	strcpy(college[0], sumb[0].college);
	i = 0;
	while (i < n1)
	{
		a = 1;
		for (j = 0; j < m; j++)
			if (strcmp(college[j], sumb[i].college) == 0)
			{
				a = 0;
				break;
			}
		if (a)
		{
			strcpy(college[m], sumb[i].college);
			m++;
		}
		i++;
	}
	for (i = 0; i < m; i++, n3 = 0)
	{
		for (j = 0; j < n1; j++)
			if (strcmp(college[i], sumb[j].college) == 0)
				for (k = 0; k < n2; k++)
					if (strcmp(sumb[j].number, sums[k].number) == 0)
					{
						sump[i] += sums[k].predict[month - 1];
						sumf[i] += sums[k].fact[month - 1];
						n3++;
					}
		if (sump[i] == 0 && sumf[i] == 0)
		{
			averagef[i] = 0;
			averagep[i] = 0;
		}
		else
		{
			averagep[i] = (double)sump[i] / n3;
			averagef[i] = (double)sumf[i] / n3;
		}
	}
	for (i = 0; i < m - 1; i++)
		for (j = 0; j < m - i - 1; j++)
		{
			if (averagep[j] - averagep[j + 1] > 1e-7)
			{
				ts = averagep[j];
				averagep[j] = averagep[j + 1];
				averagep[j + 1] = ts;
				ts = averagef[j];
				averagef[j] = averagef[j + 1];
				averagef[j + 1] = ts;
				strcpy(tsc, college[j]);
				strcpy(college[j], college[j + 1]);
				strcpy(college[j + 1], tsc);
			}
		}
	for (i = 0; i < m; i++)
	{
		printf("%s\t", college[i]);
		printf("平均应发工资:%6.2lf\t", averagep[i]);
		printf("平均实发工资:%6.2lf\n", averagef[i]);
	}
	printf("暂无其它学院工资信息\n");
	fclose(fpb);
	fclose(fps);
}
void count2()
{
	FILE *fpb, *fps;
	int month, i, j, k, l, m, n, n1, n2, n3, a;
	j = 1;
	m = 1;
	n1 = 0;
	n2 = 0;
	n3 = 0;
	scanf("%d", &month);
	struct Basic sumb[1000];
	struct Salary sums[1000];
	char title[20][20], tst[20];
	double averagep[20], averagef[20], ts;
	int sump[20] = {0};
	int sumf[20] = {0};
	int max;
	if ((fps = fopen("salary", "r")) == NULL)
		printf("Cannot open the file!\n");
	if ((fpb = fopen("basic", "r")) == NULL)
		printf("Cannot open the file!\n");
	for (i = 0; fread(&sumb[i], sizeof(struct Basic), 1, fpb) == 1; i++)
		n1++;
	for (i = 0; fread(&sums[i], sizeof(struct Salary), 1, fps) == 1; i++)
		n2++;
	strcpy(title[0], sumb[0].title);
	i = 0;
	while (i < n1)
	{
		a = 1;
		for (j = 0; j < m; j++)
			if (strcmp(title[j], sumb[i].title) == 0)
			{
				a = 0;
				break;
			}
		if (a)
		{
			strcpy(title[m], sumb[i].title);
			m++;
		}
		i++;
	}
	for (i = 0; i < m; i++, n3 = 0)
	{
		for (j = 0; j < n1; j++)
			if (strcmp(title[i], sumb[j].title) == 0)
				for (k = 0; k < n2; k++)
					if (strcmp(sumb[j].number, sums[k].number) == 0)
					{
						sump[i] += sums[k].predict[month - 1];
						sumf[i] += sums[k].fact[month - 1];
						n3++;
					}
		if (sump[i] == 0 && sumf[i] == 0)
		{
			averagef[i] = 0;
			averagep[i] = 0;
		}
		else
		{
			averagep[i] = (double)sump[i] / n3;
			averagef[i] = (double)sumf[i] / n3;
		}
	}
	for (i = 0; i < m - 1; i++)
		for (j = 0; j < m - i - 1; j++)
		{
			if (averagef[j] - averagef[j + 1] > 1e-7)
			{
				ts = averagep[j];
				averagep[j] = averagep[j + 1];
				averagep[j + 1] = ts;
				ts = averagef[j];
				averagef[j] = averagef[j + 1];
				averagef[j + 1] = ts;
				strcpy(tst, title[j]);
				strcpy(title[j], title[j + 1]);
				strcpy(title[j + 1], tst);
			}
		}
	for (i = 0; i < m; i++)
	{
		printf("%s\t", title[i]);
		printf("平均实发工资:%6.2lf\t", averagef[i]);
		printf("平均应发工资:%6.2lf\n", averagep[i]);
	}
	printf("暂无其它职称工资信息\n");
	fclose(fpb);
	fclose(fps);
}
int main()
{
	struct Basic te[200];
	struct Salary se[200];
	prompt0();
	item();
	printf("感谢您的使用\n");
	system("pause");
	return 0;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值