(C语言)实现基于PHP的某公司自来水收费管理系统

项目采用C语言完成自来水收费系统,替代原计划的PHP开发。个人承担所有开发工作,利用结构体和文件模拟数据链表功能,实现用户管理、收费管理等模块。系统包含管理员与用户双界面,通过登录验证进入不同操作层级。

 这是本来要用PHP写的项目

但是是我学校C语言实训课的毕设

所以全项目是用C语言写的

同时,班上分的小组完成,而我所在的组里都是几个摸鱼的人,所以全项目是我一个人手搓的,虽然没有用上数据链表,用的是结构体加文件形成的类似于数据链表的形式实现其基本功能,但是足够了

言归正传

全项目分为三个文件

Structure.c文件是整个系统的基础所在,内含一个main函数,是整个系统的框架结构体现

#include"manage.h"

int main()
{
	//文件
	File();

	//系统
	int input1 = 1, input2 = 0, pass = 0;
	do
	{
		if (pass == 0)
			pass = PassMenu();
		else if (pass == 1)
		{
			AdMainMenu();
			scanf("%d", &input1);
			switch (input1)
			{
			case 1:
				SystemInformation();
				break;
			case 2:
				do
				{
					AdUserManageMenu();
					scanf("%d", &input2);
					switch (input2)
					{
					case 1:
						AdChangeUserInformation();
						break;
					case 2:
						AddUserInformation();
						break;
					case 3:
						DeleteUserInformation();
						break;
					case 4:
						SearchUserInformation();
						break;
					case 5:
						LookThroughAllUserInformation();
						break;
					case 6:
						printf("\n正在返回上一级...\n");
						input2 = 0;
						break;
					default:
						printf("\n输入错误,请重试\n");
					}
				} while (input2);
				break;
			case 3:
				do
				{
					AdBillingManageMenu();
					scanf("%d", &input2);
					switch (input2)
					{
					case 1:
						AllUserBillingInformation();
						break;
					case 2:
						SearchUserBillingInformation();
						break;
					case 3:
						BillingStandard();
						break;
					case 4:
						UserBillingUp();
						break;
					case 5:
						UserBillingWarning();
						break;
					case 6:
						printf("\n正在返回上一级...\n");
						input2 = 0;
						break;
					default:
						printf("\n输入错误,请重试\n");
					}
				} while (input2);
				break;
			case 4:
				ExitMenu();
				input1 = 0;
				break;
			default:
				printf("\n输入错误,请重试\n");
			}
		}
		else if (pass == 2)
		{
			UserMainMenu();
			scanf("%d", &input1);
			switch (input1)
			{
			case 1:
				do
				{
					UserManageMenu();
					scanf("%d", &input2);
					switch (input2)
					{
					case 1:
						ChangeUserInformation();
						break;
					case 2:
						LookThroughUserInformation();
						break;
					case 3:
						printf("\n正在返回上一级...\n");
						input2 = 0;
						break;
					default:
						printf("\n输入错误,请重试\n");
					}
				} while (input2);
				break;
			case 2:
				do
				{
					BillingManageMenu();
					scanf("%d", &input2);
					switch (input2)
					{
					case 1:
						BillingStandard();
						break;
					case 2:
						BillingInformation();
						break;
					case 3:
						BillingUp();
						break;
					case 4:
						printf("\n正在返回上一级...\n");
						input2 = 0;
						break;
					default:
						printf("\n输入错误,请重试\n");
					}
				} while (input2);
				break;
			case 3:
				ExitMenu();
				input1 = 0;
				break;
			default:
				printf("\n输入错误,请重试\n");
			}
		}
	} while (input1);
	return 0;
}

Manage.h文件是整个系统的头文件,内含多个系统头文件,定义了多个函数

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

//文件
void File();
void AddUserInformation();
void DeleteUserInformation();
void SearchUserInformation();
void LookThroughAllUserInformation();
void LookThroughUserInformation();
void AdChangeUserInformation();
void ChangeUserInformation();

//菜单
int PassMenu();
int AdMainMenu();
int UserMainMenu();
int ExitMenu();
int AdUserManageMenu();
int UserManageMenu();
int AdBillingManageMenu();
int BillingManageMenu();

//系统
void SystemInformation();

//登录
int CheckName();
int CheckPassword();

//收费
void AllUserBillingInformation();
void SearchUserBillingInformation();
void UserBillingUp();
void UserBillingWarning();
void BillingInformation();
void BillingUp();
float BillingCalculation();
void BillingStandard();

System.c文件是整个系统的关键、核心,内含众多函数用于实现系统的各种功能

#include"manage.h"

char Administer[] = "MingAn";
char AdPassword[] = "123lan??";
char Use[20] = { 0 };
char Password = { 0 };
struct User
{
	char name[21];
	char password[17];
	float water;
	float fee;
}user[1000] = { 0, 0, 0, 0 };

//---------------------------------------文件--------------------------------------
void File()
{
	FILE* fp = fopen("UserList", "r");
	if (fp == NULL)
	{
		printf("用户文件'UserList'不存在,将重新创建\n");
		fp = fopen("UserList", "w");
	}
}

void AddUserInformation()
{
	FILE* fp = fopen("UserList", "a+");
	struct user;
	printf("\n请输入用户名(最长20位):");
	scanf("%s", user->name);
	printf("\n请输入密码(区分大小写、最长16位):");
	scanf("%s", user->password);
	printf("\n请输入已使用的水量(单位:吨)");
	scanf("%f", &user->water);
	printf("\n系统正在计算您的费用...\n");
	float take = user->water;
	user->fee = BillingCalculation(&take);
	fwrite(&(user), 1, sizeof(struct User), fp);
	fclose(fp);
	printf("\n用户添加成功!\n即将返回上一级...\n");
}

void DeleteUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0;
	printf("\n请输入要删除的用户名:");
	scanf("%s", input);
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			for (; count < num; count++)
			{
				strcpy(user[count].name, user[count + 1].name);
				strcpy(user[count].password, user[count + 1].password);
				user[count].water = user[count + 1].water;
				user[count].fee = user[count + 1].fee;
			}
			printf("\n删除成功!\n即将返回上一级\n");
			break;
		}
		else
			count++;
	}
	if (count > num)
		printf("\n未找到此用户\n即将返回上一级\n");
	fp = fopen("UserList", "w");
	count = 0;
	while (count < num)
	{
		fwrite(&user[count], 1, sizeof(struct User), fp);
		count++;
	}
	fclose(fp);
}

void SearchUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0;
	printf("\n请输入要查找的用户名:");
	scanf("%s", input);
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户信息                                              |\n");
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("|                                                                                                  |\n");
			printf("|       用户名:%-21s密码:%-17s用水量:%.1f吨\t费用:%.2f元\t   |\n", user[count].name, user[count].password, user[count].water, user[count].fee);
			count++;
			take = 1;
		}
		else
			count++;
	}
	if (take == 0)
		printf("\n未找到此用户!\n即将返回上一级...\n");
	else
	{
		printf("|                                                                                                  |\n");
		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
		printf("\n若要返回上一级");
		system("pause");
	}
}

void LookThroughAllUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	int count = 0;
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户信息                                              |\n");
	while (count < num)
	{
		if (strcmp(user[count].name, "") != 0)
		{
			printf("|                                                                                                  |\n");
			printf("|       用户名:%-21s密码:%-17s用水量:%.1f吨\t费用:%.2f元\t   |\n", user[count].name, user[count].password, user[count].water, user[count].fee);
			count++;
		}
		else
			count++;
	}
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n若要返回上一级");
	system("pause");
}

void LookThroughUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0;
	printf("\n请输入用户名以验证身份:");
	scanf("%s", input);
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户信息                                              |\n");
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("|                                                                                                  |\n");
			printf("|       用户名:%-21s密码:%-17s用水量:%.1f吨\t费用:%.2f元\t   |\n", user[count].name, user[count].password, user[count].water, user[count].fee);
			count++;
			take = 1;
		}
		else
			count++;
	}
	if (take == 0)
		printf("\n用户验证失败!\n即将返回上一级...\n");
	else
	{
		printf("|                                                                                                  |\n");
		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
		printf("\n若要返回上一级");
		system("pause");
	}
}

void AdChangeUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0, take = 1;
	printf("\n请输入用户名:");
	scanf("%s", input);
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			while (take)
			{
				printf("\n请输入要修改的密码:");
				scanf("%s", input);
				if (strcmp(user[count].password, input) == 0)
					printf("\n输入的密码与原密码一致,请重试!\n");
				else
				{
					strcpy(user[count].password, input);
					take = 0;
				}
			}
			printf("\n修改成功!\n即将返回上一级...\n");
			break;
		}
		count++;
	}
	if (count > num)
		printf("\n未找到此用户!\n即将返回上一级...\n");
	fp = fopen("UserList", "w");
	count = 0;
	while (count < num)
	{
		fwrite(&user[count], 1, sizeof(struct User), fp);
		count++;
	}
	fclose(fp);
}

void ChangeUserInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0, take = 1;
	printf("\n请输入你的用户名以确认身份:");
	scanf("%s", input);
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			while (take)
			{
				printf("\n请输入要修改的密码:");
				scanf("%s", input);
				if (strcmp(user[count].password, input) == 0)
					printf("\n输入的密码与原密码一致,请重试!\n");
				else
				{
					strcpy(user[count].password, input);
					take = 0;
				}
			}
			printf("\n修改成功!\n即将返回上一级...\n");
			break;
		}
		count++;
	}
	if (count > num)
		printf("\n验证用户身份失败!\n即将返回上一级...\n");
	fp = fopen("UserList", "w");
	count = 0;
	while (count < num)
	{
		fwrite(&user[count], 1, sizeof(struct User), fp);
		count++;
	}
	fclose(fp);
}



//---------------------------------------菜单--------------------------------------
int PassMenu()
{
	int pass = 0, a = 0;
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                             初始界面                                             |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                       未检测到用户登录信息                                       |\n");
	printf("|                                              请登录                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	do
	{
		char username[20] = { 0 }, password[20] = { 0 };
		printf("\n请输入账号:");
		gets(username);
		printf("\n请输入密码(区分大小写):");
		gets(password);
		if (strcmp(username, Administer) == 0 && strcmp(password, AdPassword) == 0)//管理员
		{
			pass = 1;
			return pass;
		}
		else if (CheckName(username) == 1 && CheckPassword(password) == 1)//用户
		{
			pass = 2;
			return pass;
		}
		else
		{
			printf("\n用户名或密码错误,请重新输入\n");
			pass = 0;
			return pass;
		}
	} while (a);
}

int AdMainMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            管理员界面                                            |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                         1.查看系统基本信息                                       |\n");
	printf("|                                         2.用户信息管理                                           |\n");
	printf("|                                         3.用户收费管理                                           |\n");
	printf("|                                         4.退出                                                   |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}

int UserMainMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户界面                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                          1.用户信息管理                                          |\n");
	printf("|                                          2.用户收费管理                                          |\n");
	printf("|                                          3.退出                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}

int ExitMenu()
{
	printf("\n正在退出系统...\n");
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                          感谢您的使用                                            |\n");
	printf("|                                          欢迎下次光临                                            |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}

int AdUserManageMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户管理                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                         1.修改用户信息                                           |\n");
	printf("|                                         2.增加用户信息                                           |\n");
	printf("|                                         3.删除用户信息                                           |\n");
	printf("|                                         4.查找用户信息                                           |\n");
	printf("|                                         5.查看用户信息                                           |\n");
	printf("|                                         6.返回                                                   |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}


int UserManageMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户管理                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                         1.修改用户信息                                           |\n");
	printf("|                                         2.查看用户信息                                           |\n");
	printf("|                                         3.返回                                                   |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}

int AdBillingManageMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费管理                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                     1.查看全体用户费用信息                                       |\n");
	printf("|                                     2.查看单一用户费用信息                                       |\n");
	printf("|                                     3.查看收费标准                                               |\n");
	printf("|                                     4.用户费用充值                                               |\n");
	printf("|                                     5.用户费用预警                                               |\n");
	printf("|                                     6.返回                                                       |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}

int BillingManageMenu()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费管理                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                     1.查看收费标准                                               |\n");
	printf("|                                     2.查看费用信息                                               |\n");
	printf("|                                     3.费用充值                                                   |\n");
	printf("|                                     4.返回                                                       |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n请输入数字以进行下一步操作:");
}


//---------------------------------------信息--------------------------------------
void SystemInformation()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            系统信息                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                  系统名称:自来水收费管理系统                                    |\n");
	printf("|                             系统作者:十组 - 兰小贵、王奕力、杨浩楠                              |\n");
	printf("|                                         系统版本:V1.1                                           |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n若要返回主界面");
	system("pause");
}


//---------------------------------------收费--------------------------------------
void AllUserBillingInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	int count = 0;
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费信息                                              |\n");
	while (count < num)
	{
		if (strcmp(user[count].name, "") != 0)
		{
			printf("|                                                                                                  |\n");
			printf("|              用户名:%-21s用水量:%.1f吨\t      费用:%.2f元\t           |\n", user[count].name, user[count].water, user[count].fee);
			count++;
		}
		else
		count++;
	}
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n若要返回上一级");
	system("pause");
}

void SearchUserBillingInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0;
	printf("\n请输入要查找的用户名:");
	scanf("%s", input);
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费信息                                              |\n");
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("|                                                                                                  |\n");
			printf("|              用户名:%-21s用水量:%.1f吨\t      费用:%.2f元\t           |\n", user[count].name, user[count].water, user[count].fee);
			count++;
			take = 1;
		}
		else
			count++;
	}
	if (take == 0)
		printf("\n未找到此用户!\n即将返回上一级...\n");
	else
	{
		printf("|                                                                                                  |\n");
		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
		printf("\n若要返回上一级");
		system("pause");
	}
}

void UserBillingUp()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0, take = 1;
	printf("\n请输入用户名:");
	scanf("%s", input);
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("\n请输入充值金额:");
			float fee = 0;
			scanf("%f", &fee);
			user[count].fee += fee;
			printf("\n充值成功!\n即将返回上一级...\n");
			break;
		}
		count++;
	}
	if (count > num)
		printf("\n未找到此用户!\n即将返回上一级...\n");
	fp = fopen("UserList", "w");
	count = 0;
	while (count < num)
	{
		fwrite(&user[count], 1, sizeof(struct User), fp);
		count++;
	}
	fclose(fp);
}

void UserBillingWarning()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	int count = 0;
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费信息                                              |\n");
	while (count < num)
	{
		if (strcmp(user[count].name, "") != 0)
		{
			if (user[count].fee < 0)
			{
				printf("|                                                                                                  |\n");
				printf("|              用户名:%-21s用水量:%.1f吨\t      费用:%.2f元\t           |\n", user[count].name, user[count].water, user[count].fee);
				count++;
			}
			else
				count++;
		}
		else
			count++;
	}
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n若要返回上一级");
	system("pause");
}

void BillingInformation()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0;
	printf("\n请输入用户名以验证身份:");
	scanf("%s", input);
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            用户信息                                              |\n");
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("|                                                                                                  |\n");
			printf("|       用户名:%-21s密码:%-17s用水量:%.1f吨\t费用:%.2f元\t   |\n", user[count].name, user[count].password, user[count].water, user[count].fee);
			count++;
			take = 1;
		}
		else
			count++;
	}
	if (take == 0)
		printf("\n用户验证失败!即将返回上一级...\n");
	else
	{
		printf("|                                                                                                  |\n");
		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
		printf("\n若要返回上一级");
		system("pause");
	}
}

void BillingUp()
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	char input[21] = { 0 };
	int count = 0, take = 1;
	printf("\n请输入用户名以验证身份:");
	scanf("%s", input);
	while (count <= num)
	{
		if (strcmp(user[count].name, input) == 0)
		{
			printf("\n请输入充值金额:");
			float fee = 0;
			scanf("%f", &fee);
			user[count].fee += fee;
			printf("\n充值成功!\n即将返回上一级...\n");
			break;
		}
		count++;
	}
	if (count > num)
		printf("\n用户验证失败!\n即将返回上一级...\n");
	fp = fopen("UserList", "w");
	count = 0;
	while (count < num)
	{
		fwrite(&user[count], 1, sizeof(struct User), fp);
		count++;
	}
	fclose(fp);
}

float BillingCalculation(float *water)
{
	float fee = 0;
	if (*water <= 15)
		fee = *water * 0.6;
	else if (*water > 15 && *water <= 20)
		fee = 9 + (*water - 15) * 1.4;
	else
		fee = 9 + 7 + (*water - 20) * 2.1;
	return -fee;
}

void BillingStandard()
{
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                  欢迎使用本公司自来水收费管理系统                                |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("|                                            收费标准                                              |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                    用水15吨以内为0.6元/吨                                       |\n");
	printf("|                                    15-20吨为1.4元/吨                                            |\n");
	printf("|                                    20吨以上为2.1元/吨                                           |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("|                                                                                                  |\n");
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n若要返回上一级");
	system("pause");
}


//---------------------------------------登录--------------------------------------

int CheckName(char Username[])
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	int count = 0;
	while (count <= num)
	{
		if (strcmp(user[count].name, Username) == 0)
		{
			take = 1;
			return take;
		}
		else
			count++;
	}
	count--;
	if (count > num)
		take = 0;
	return take;
}

int CheckPassword(char Password[])
{
	FILE* fp = fopen("UserList", "r");
	int r = 0, num = 0, take = 0;
	r = fread(&user[num], 1, sizeof(struct User), fp);
	while (r)
	{
		num++;
		r = fread(&user[num], 1, sizeof(struct User), fp);
	}
	fclose(fp);
	int count = 0;
	while (count <= num)
	{
		if (strcmp(user[count].password, Password) == 0)
		{
			take = 1;
			return take;
		}
		else
			count++;
	}
	count--;
	if (count > num)
		take = 0;
	return take;
}

以上,做完这个项目后感觉整个人对文件和结构体的理解瞬间深刻了起来(感觉上的),听说下学期开始学Java了,C语言进阶也估计不会再学了

就这样吧,大致掌握一门编程语言的基础,写出这么一个勉强能用的系统,虽说才学了一学期的C语言(10月开学,12月中旬提前放假,9月开始看网课学习,大概三个月半的学习,大致上是掌握了)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值