(一)系统的功能构成图
(二)系统的功能说明
序号 | 模块 | 功能 | 说明 |
1 | 卡管理 | 添加卡 | 输入卡号、密码、开卡金额等卡信息,将卡信息保存到data文件夹的card.txt文件中 |
2 | 查询卡 | 根据输入的卡号,查询卡号相同的卡信息,并以表格形式显示在控制台中 | |
3 | 注销卡 | 根据输入的卡号、密码,将对应卡的状态改为注销,注销卡不能进行上机 | |
4 | 计费标准管理 | 新增计费标准 | 输入计费标准的信息,将输入的计费标准保存到data文件夹的rate.txt文件中 |
5 | 查询计费标准 | 根据上机时间,查询对应的计费标准 | |
6 | 删除计费标准 | 从计费标准文件data文件夹的rate.txt文件中,删除一条计费标准 | |
7 | 修改计费标准 | 修改一条计费标准 | |
8 | 计费管理 | 上机 | 根据输入的卡号、密码,判断该卡能否上机,如果能上机,则保存计费信息 |
9 | 下机 | 根据输入下机卡的卡号,进行下机结算操作 | |
10 | 费用管理 | 充值 | 给一条已经存在的卡进行充值。 |
11 | 退费 | 将卡中余额返回给用户 | |
12 | 查询统计 | 查询消费记录 | 查询一张卡在一段时间内的消费记录 |
13 | 统计总营业额 | 统计一段时间内,总营业额 | |
14 | 统计月营业额 | 统计一年中,每个月上机次数、总营业额,将统计结果保存到文本文件中,并以列表形式显示在控制台中。 | |
15 | 权限管理 | 添加管理员 | 超级管理员添加一个管理员信息 |
16 | 删除管理员 | 超级管理员删除一个管理员信息 | |
17 | 配置权限 | 添加管理员时,配置管理员的权限 | |
18 | 系统 | 登录 | 超级管理员和管理员登录系统 |
19 | 退出 | 超级管理员和管理员退出系统 |
(三)系统的实现技术要求
- 必须使用链表描述系统的数据结构,使用文件保存数据。
- 要求每一项功能的实现必须以函数调用的形式完成。
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<time.h>
struct monthtime
{
int year;
int month;
float cost;
struct monthtime* next;
}monthtime;
struct standerd
{
int time;
float money;
struct standerd* next;
}standerd; //计费标准结构体
struct people //每个人的结构体
{
int card; //卡号
char passward[20]; //密码
float money; //金额
int type; //普通人 0 管理员 1,超管 2 注销3
struct jur //权限设置
{
int a, b, c, d, e; //a计费标准管理,b计费管理,c费用管理,d查询统计,e权限管理.
}jur;
int state; //显示现在卡是否上机 1在线 0不在线
struct people* next; //连接
struct up //上机记录时间
{
int year;
int month;
int day;
int hour;
int minute;
int second;
}up;
struct down //下机记录时间
{
int year;
int month;
int day;
int hour;
int minute;
int second;
}down;
unsigned int time; //记录秒数,方便计算
float cost;
}people;
void Cardmanagement(struct people* head, struct people d);//卡管理系统
void cardadd(struct people* head);//添加卡的操作
void cardfind();//查询卡操作
void cardcancellation(struct people* head, struct people z);//卡号注销和重启
void freightbasis(struct people d);//计费管理标准系统
void addbasis();//增加操作
void findbasis();//查询
void delbasis();//删除
void revisionbasis();//修改
void updown(struct people d);//上下机系统
void upcomputer();//上机操作
void downcomputer();//下机操作
void cost(struct people d);//充值退费系统
void Recharge();//充值账号
void Refund();//退钱
void Authoritymanagement(struct people* head, struct people d);//配置管理员权限
void resetsuper();//重置设置超管
void superresgis();//超管权限注册
void judgemoney();//用来查消费记录和总额
void moneycost();//查询某张卡的消费记录
void findtimemoney();//统计总营业额
void findtimemoney();//查找一段时间的总金额(只支持年份和月份)
void findyear();//查询某一年的上机次数和当月总金额
void addadministrators(struct people* head);//注册一个新的管理员并配置权限
void delcard(struct people im);//删除管理员
struct people signin(struct people* head);//登录系统
void read(struct people** head);//读取card的所有链表
void type(struct people d);//身份判断系统
int cardfind1(struct people d, struct people* head);//判断是否与已有卡重复,若是返回1
void changeministrators();//修改权限
void readbasis(struct standerd** head);//读取rate里面的内容
void writebasis(struct standerd* head);//将链表的内容写入
void rangebasis(struct standerd** head, struct standerd d);//将要增加排序后放入链表
void judgebasis();
void readmoney(struct people** head);
void moneymanagement(struct people d);
void addmonthtime(struct people d);//读取money的列表
void addmonthtime(struct people d);//每次下机都写入文件中
void readmonthtime(struct monthtime** head);//读取文件
void judgemonth();//判断month.txt是否存在
int main(void)
{
struct people* head, im; //head为头结点,im为当前登录账户的所有信息
int m, d = 0; //m主菜单用来进二级系统的判断,d退出系统判断
superresgis();
judgebasis();
judgemoney();
judgemonth();
logoff:read(&head);
im = signin(head);
if (im.type == 4) //判断密码或账户是否错误,错误直接退出
{
return 0;
}
printf("%d账号登录此系统,您的身份是", im.card);
type(im);
while (1) //主菜单
{
printf("\n----------------**************----------------");
printf("\n 请输入你要进入的系统!\n");
printf("\n 1 卡管理系统\n\n 2 计费标准管理\n\n 3 上下机\n\n 4 充值退费\n\n 5 管理员系统\n\n 6 查询消费记录\n\n 7 注销账号并登录其它账号\n\n 8 退出系统\n ");
printf("\n 请选择要进入的系统:");
scanf("%d", &m);
printf("\n\n--------------**************----------------");
switch (m)
{
case 1:Cardmanagement(head, im); break;
case 2:freightbasis(im); break;
case 3:updown(im); break;
case 4:cost(im); break;
case 5:Authoritymanagement(head, im); break;
case 6:moneymanagement(im); break;
case 7:goto logoff;
case 8: d = 1; break;
}
if (d == 1)
break;
}
}
void resetsuper() //重置设置超管
{
FILE* fp;
char a;
struct people d;
if ((fp = fopen("judge.txt", "r")) != NULL)
{
fclose(fp);
return;
}
fp = fopen("judge.txt", "w+");
a = '0';
fputc(a, fp);
fclose(fp);
}
void superresgis()//超管权限注册
{
FILE* fp;
char a;
struct people d;
resetsuper();//重置超管
fp = fopen("judge.txt", "r+");
a = fgetc(fp);
if (a == '1')
{
fclose(fp);
return;
}
rewind(fp);
a = '1';
fputc(a, fp);
fclose(fp);
fp = fopen("card.txt", "wb+");
printf(" **********您已进入超级管理员注册系统!*********** \n");
printf("* *\n");
printf("\n* 请输入需要注册的卡号: *\n");
scanf("%d", &d.card);
printf("\n* 请输入您的密码(密码不得超过20位): *\n");
scanf("%s", &d.passward);
printf("\n* 卡内拥有金额为: *\n");
scanf("%f", &d.money);
//scanf("%d%s%d", &d.card, &d.passward, &d.money);
d.type = 2;
d.jur.a = 1, d.jur.b = 1, d.jur.c = 1, d.jur.d = 1, d.jur.e = 1;
d.next = NULL;
d.state = 0;
fwrite(&d, sizeof(struct people), 1, fp);
printf("\n* 恭喜您已经成功注册超管,拥有所有权限! *\n");
fclose(fp);
return;
}
struct people signin(struct people* head)//登录系统
{
int c = 0;
printf("\n----------------------------------------- \n ");
try1:printf("\n请输入您的卡号:");
struct people d;
scanf("%d", &d.card);
struct people* p1, * p2;
p1 = head;
while (p1 != NULL)
{
if (p1->card == d.card)
{
p2 = p1;
c = 1;
break;
}
p1 = p1->next;
if (p1->card < 0)
break;
}
if (c == 1)
{
try2:printf("\n请输入密码:");
scanf("%s", d.passward);
if (strcmp(p2->passward, d.passward) == 0)//返回此账户的所有信息
{
d = *p2;
printf("\n欢迎");
return d;
}
else
{
printf("密码错误,请重新输入\n");
goto try2;
}//此处未来需要做一个重新输入密码系统
}
else
{
printf("未查询到此卡号,请重新检查\n");//未来做退出和重新输入
printf("\n--------------------------------------- \n ");
goto try1;
return d;
}
}
void read(struct people** head)//读取card的所有链表
{
FILE* fp, * fp1;
fp = fopen("card.txt", "rb");
int i;
struct people* p1, * p2;
for (i = 1;; i++)
{
if (feof(fp))
break;
if ((p1 = (struct people*)malloc(sizeof(struct people))) == NULL)
{
printf("不能成功分配储存区块!\n");
}
fread(p1, sizeof(struct people), 1, fp);
if (i == 1)
*head = p1;
else
p2->next = p1;
p2 = p1;
p1->next = NULL;
}
fclose(fp);
}
void type(struct people d)//身份判断系统
{
if (d.type == 0)
{
printf("普通用户!\n");
}
if (d.type == 1)
{
printf("管理员!\n");
}
if (d.type == 2)
{
printf("超级管理员!\n");
}
if (d.type == 3)
{
printf("注销卡\n");
}
}
void Cardmanagement(struct people* head, struct people d)//卡管理系统
{
int c, z = 0;
if (d.type == 0 || d.jur.a == 0)
{
printf("您没有权限进入卡管理系统");
return;
}
while (1)//卡管理系统页面
{
printf("\n \n------------------<<<<<<<<------------------ \n");
printf("\n 请选择进入的页面\n\n");
printf(" 1 添加卡\n\n 2 查询卡\n\n 3 注销和恢复卡\n\n 4 删除卡\n\n 5 退出卡管理系统\n ");
printf("\n 请选择:");
scanf("%d", &c);
printf("\n \n------------------<<<<<<<<------------------ \n\n");
switch (c)
{
case 1:cardadd(head); break;
case 2:cardfind(); break;
case 3:cardcancellation(head, d); break;
case 4:delcard(d); break;
case 5:z = 1; break;
}
if (z == 1)
break;
}
}
void cardadd(struct people* head)//添加卡的操作
{
FILE* fp;
struct people d, f;
int z = 0;//判断是否注册
try1:printf("---------------------------------------------\n");
printf("\n是否要退出卡增加系统,是请按1,不是按0: ");//防止点错了
scanf("%d", &z);
if (z == 1)
return;
printf("\n输入添加的卡号(卡号需要大于0),密码,存储金额: ");
int c = 0;//判断是否重复
scanf("%d%s%f", &d.card, &d.passward, &d.money);
c = cardfind1(d, head);
if (c == 1)
{
printf("\n卡号重复,请换号码\n");
goto try1;
}
printf("\n请再次输入一遍密码:");
scanf("%s", f.passward);
if (strcmp(d.passward, f.passward) == 0)
{
d.type = 0, d.next = NULL, d.jur.c = 1, d.jur.d = 1, d.jur.e = 1, d.state = 0;
fp = fopen("card.txt", "ab");
fwrite(&d, sizeof(struct people), 1, fp);
printf("\n恭喜您成功添加卡!\n\n");
printf("---------------------------------------------\n");
fclose(fp);
}
else
{
printf("请重新注册\n\n");
printf("---------------------------------------------\n");
goto try1;
}
}
void cardfind()
{
int c = 0;
struct people* head1;
read(&head1);
printf("---------------------------------------------\n");
printf("\n请输入您的卡号: ");
struct people d;
scanf("%d", &d.card);
struct people* p1, * p2;
p1 = head1;
while (p1 != NULL)
{
if (p1->card == d.card)
{
p2 = p1;
c = 1;
break;
}
p1 = p1->next;
if (p1->card <= 0)
break;
}
if (c == 1)
{
d = *p2;
printf("已查询到此卡\n");
printf("此卡账号为%d,剩余金额为%.2f,权限为", p2->card, p2->money);
type(d);
printf("状态为");
if (d.state == 0)
printf("下机");
else
printf("上机中");
printf("\n已返回卡管理系统!\n\n");
printf("---------------------------------------------\n");
}
else
{
printf("无法查到此卡\n\n");
printf("---------------------------------------------\n");
}
}
int cardfind1(struct people d, struct people* head)//判断是否与已有卡重复,若是返回1
{
int c = 0;
struct people* p1, * p2;
p1 = head;
while (p1 != NULL)
{
if (p1->card == d.card)
{
p2 = p1;
c = 1;
break;
}
p1 = p1->next;
if (p1->card < 0)
break;
}
if (c == 1)
return 1;
else
return 0;
}
void cardcancellation(struct people* head, struct people z)//卡号注销和重启
{
FILE* fp;
fp = fopen("card.txt", "r+");
int a;//用来判断注销或重启
int c = 0;//判断有没有这张卡
printf("---------------------------------------------\n");
printf("\n请输入您需要操作的卡号: ");
struct people d, e;//e用来储存要更改的文件项目
scanf("%d", &d.card);
while (!feof(fp))
{
fread(&e, sizeof(struct people), 1, fp);
if (e.card == d.card)
{
d = e;
fseek(fp, -sizeof(struct people), 1);
c = 1;
break;
}
}
if (c == 1)
{
printf("请输入操作 0为注销卡,1为恢复卡:");
scanf("%d", &a);
if (a == 0)
{
printf("注意,此操作也会把管理员和超级管理员给注销\n");
d.type = 3;
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
printf("已经成功变为注销卡\n\n");
printf("---------------------------------------------\n");
}
else if (a == 1)
{
int h;
printf("请选择恢复身份,0普通人,1管理员(注意,若登陆身份为管理员则无法将卡恢复为管理员): ");
scanf("%d", &h);
if (h == 1)
{
if (z.type == 1)
{
printf("操作无效\n\n");
printf("---------------------------------------------\n");
return;
}
}
d.type = h;
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
printf("已经成功恢复!\n\n");
printf("---------------------------------------------\n");
return;
}
else
{
printf("操作无效!\n\n");
printf("---------------------------------------------\n");
return;
}
}
else
{
printf("找不到此卡!\n\n");
printf("---------------------------------------------\n");
return;
}
}
void Authoritymanagement(struct people* head, struct people d)//配置管理员权限
{
int c;
if (d.type != 2 || d.jur.a == 0)
{
printf("您没有权限进入此系统\n");
return;
}
while (1)
{
printf("\n--------------<<<<<<<<<<----------------\n\n");
printf(" 1 增加管理员\n\n 2 修改管理员\n\n 3 删除管理员\n\n 4 退出\n\n 请选择要进入的系统:");
scanf("%d", &c);
printf("\n--------------<<<<<<<<<<----------------\n");
switch (c)
{
case 1:addadministrators(head); break;
case 2:changeministrators(); break;
case 3:delcard(d); break;
case 4:return;
}
}
}
void addadministrators(struct people* head)//注册一个新的管理员并配置权限
{
FILE* fp;
struct people d, f;
int z = 0;
try1:printf("\n---------------------------------------------\n");
printf("\n输入添加的卡号(卡号需要大于0),密码,存储金额:");
int c = 0;//判断是否重复
scanf("%d%s%d", &d.card, &d.passward, &d.money);
c = cardfind1(d, head);
if (c == 1)
{
printf("卡号重复,请换号码\n");
goto try1;
}
printf("\n请再次输入一遍密码:");
scanf("%s", f.passward);
if (strcmp(d.passward, f.passward) == 0)
{
int a[5];
printf("\n配置管理员权限(1为允许,0为不允许)\n");
printf("\n管理员权限为:卡管理系统,计费标准管理系统,计费管理系统,费用系统,查询统计\n");
printf("\n请输入(输入0或1设置是否配置该权限):");
scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
d.jur.a = a[0], d.jur.b = a[1], d.jur.c = a[2], d.jur.d = a[3], d.jur.e = a[4], d.type = 1, d.state = 0;
fp = fopen("card.txt", "ab");
fwrite(&d, sizeof(struct people), 1, fp);
printf("\n成功添加卡!\n\n");
fclose(fp);
return;
}
else
{
printf("\n请重新注册!\n\n");
goto try1;
}
}
void changeministrators()//修改权限
{
FILE* fp;
fp = fopen("card.txt", "r+");
int a[5];//更改权限
int c = 0;//判断有没有这张卡
printf("\n---------------------------------------------\n");
printf("\n请输入您需要操作的卡号:");
struct people d, e;//e用来储存要更改的文件项目
scanf("%d", &d.card);
while (!feof(fp))
{
fread(&e, sizeof(struct people), 1, fp);
if (e.card == d.card)
{
d = e;
fseek(fp, -sizeof(struct people), 1);
c = 1;
break;
}
}
if (d.type != 1)
{
printf("\n这不是管理员账户,无法更改\n");
return;
}
if (c == 1)
{
printf("\n配置管理员权限(1为允许,0为不允许)\n");
printf("\n权限包括:卡管理系统,计费标准管理系统,计费管理系统,费用系统,查询统计,\n");
printf("\n请输入(输入0或1设置是否配置该权限):");
scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
d.jur.a = a[0], d.jur.b = a[1], d.jur.c = a[2], d.jur.d = a[3], d.jur.e = a[4];
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
printf("\n修改成功!\n\n");
}
else
{
printf("\n未找到此卡号!\n\n");
fclose(fp);
}
}
void delcard(struct people im)
{
FILE* fp;
int c = 0, i = 1;//判断有无卡,判断是否是第一次
struct people d, e, * p1, * p2, * head;
read(&head);
printf("\n请输入要删除的卡号: ");
scanf("%d", &d.card);
p1 = head;
p2 = p1;
while (p1->next != NULL)
{
if (p1->card == d.card)
{
c = 1;
break;
}
if (i > 1)
p2 = p1;
p1 = p1->next;
i++;
if (p1->card <= 0)
break;
}
if (p1 == p2)
{
printf("无法删除超级管理员!\n\n");
return;
}
if (c == 0)
{
printf("对不起,没有找到这张卡!\n\n");
return;
}
if (p1->type == im.type)
{
printf("管理员无法删除管理员!\n\n");
}
else
{
p2->next = p1->next;
p1->next = NULL;
p1 = head;
fp = fopen("card.txt", "wb+");
while (p1->card > 0)//写入文件
{
d = *p1;
fwrite(&d, sizeof(struct people), 1, fp);
p1 = p1->next;
}
fclose(fp);
printf("已成功删除此卡号!\n\n");
return;
}
}
void cost(struct people d)//充值退费系统
{
int c;
if (d.type == 0 || d.jur.c == 0)
{
printf("你无权限进入\n");
return;
}
while (1)
{
printf("\n--------------<<<<<<<<<<----------------\n\n");
printf(" 1 充值\n\n 2 退费\n\n 3 退出\n\n 请选择要进入的系统:");
scanf("%d", &c);
printf("\n\n--------------<<<<<<<<<<----------------\n");
switch (c)
{
case 1:Recharge(); break;
case 2:Refund(); break;
case 3:return;
}
}
}
void Recharge()//充值账号
{
FILE* fp;
float c, h;
struct people d, e;
fp = fopen("card.txt", "rb+");
printf("\n请输入要充值的卡号: ");
scanf("%d", &d.card);
while (!feof(fp))
{
fread(&e, sizeof(struct people), 1, fp);
if (e.card == d.card)
{
d = e;
fseek(fp, -sizeof(struct people), 1);
c = 1;
break;
}
}
if (c == 1)
{
printf("请输入要充值的金额: ");
scanf("%f", &h);
d.money = d.money + h;
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
printf("充值成功,当前账户余额%.2f\n\n", d.money);
return;
}
else
{
fclose(fp);
printf("无法查询到此卡\n\n");
printf("\n--------------------------------------------\n");
return;
}
}
void Refund()//退钱
{
FILE* fp;
int c;
float h;
struct people d, e;
fp = fopen("card.txt", "rb+");
printf("\n请输入要退费的卡号: ");
scanf("%d", &d.card);
while (!feof(fp))
{
fread(&e, sizeof(struct people), 1, fp);
if (e.card == d.card)
{
d = e;
fseek(fp, -sizeof(struct people), 1);
c = 1;
break;
}
}
if (c == 1)
{
printf("这张卡当前余额%.2f\n", d.money);
try1:printf("请输入要退费的金额: ");
scanf("%f", &h);
if (d.money < h)
{
printf("您的余额不足,请重新输入!\n\n");
goto try1;
}
d.money = d.money - h;
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
printf("退费成功,当前账户余额%.2f\n\n", d.money);
return;
}
else
{
fclose(fp);
printf("无法查询到此卡\n\n");
return;
}
}
void freightbasis(struct people d)//计费管理标准系统
{
if (d.type == 0 || d.jur.b == 0 || d.type == 0)
{
printf(",对不起,您没有权限进入此系统");
return;
}
int c;
while (1)
{
printf("\n--------------<<<<<<<<<<----------------\n\n");
printf(" 1 增加\n\n 2 查询\n\n 3 删除\n\n 4 修改\n\n 5 退出\n\n 请选择要进入的系统:");
scanf("%d", &c);
printf("\n--------------<<<<<<<<<<----------------\n");
switch (c)
{
case 1:addbasis(); break;
case 2:findbasis(); break;
case 3:delbasis(); break;
case 4:revisionbasis(); break;
case 5:return; break;
}
}
}
void addbasis()//增加操作
{
int c = 0;
struct standerd d, * p1, * p2;
printf("\n输入多少时间(小时)多少钱(元): ");
scanf("%d%f", &d.time, &d.money);
d.next = NULL;
readbasis(&p1);
p2 = p1;
while (p2 != NULL)
{
if (p2->time == d.time)
{
c = 1;
break;
}
p2 = p2->next;;
}
if (c == 0)
rangebasis(&p1, d);
else
printf("输入了重复的时间!\n");
}
void readbasis(struct standerd** head)//读取rate里面的内容
{
FILE* fp, * fp1;
fp = fopen("rate.txt", "rb");
int i;
struct standerd* p1, * p2;
for (i = 1;; i++)
{
if (feof(fp))
break;
if ((p1 = (struct standerd*)malloc(sizeof(struct standerd))) == NULL)
{
printf("不能成功分配储存区块!\n");
}
fread(p1, sizeof(struct standerd), 1, fp);
if (p1->money < 0)
return;
if (i == 1)
*head = p1;
else
p2->next = p1;
p2 = p1;
p2->next = NULL;
}
fclose(fp);
}
void rangebasis(struct standerd** head, struct standerd d)//将要增加排序后放入链表
{
struct standerd* p1, * p2, * p4;
int c = 0;
p1 = *head;
if (p1 == NULL)
{
p1 = &d;
c = 1;
}
if (p1->next == NULL && d.time > p1->time)
{
p1->next = &d;
c = 1;
}
if (p1->next == NULL && d.time < p1->time)
{
d.next = p1;
*head = &d;
c = 1;
}
while (c == 0)
{
if (p1->next == NULL)
{
p1->next = &d;
d.next = NULL;
break;
}
if (d.time > p1->time && d.time < p1->next->time)
{
p2 = p1->next;
p1->next = &d;
d.next = p2;
break;
}
p1 = p1->next;
}
writebasis(*head);
printf("成功写入\n");
}
void writebasis(struct standerd* head)//将链表的内容写入
{
FILE* fp;
struct standerd d, * p1;
p1 = head;
fp = fopen("rate.txt", "wb+");
while (p1 != NULL)
{
d = *p1;
fwrite(&d, sizeof(struct standerd), 1, fp);
p1 = p1->next;
}
fclose(fp);
return;
}
void findbasis()
{
struct standerd* p1;
readbasis(&p1);
int c;
for (c = 0;; c++)
{
if (c != 0)
printf("\n%d.上机%d小时需要花费%.2f人民币\n", c, p1->time, p1->money);
p1 = p1->next;
if (p1 == NULL)
break;
}
return;
}
void delbasis()
{
FILE* fp;
struct standerd* head, * p1, * p2;
readbasis(&head);
p1 = p2 = head;
printf("\n输入你要删除的计费标准(输入小时数):");
int c, i = 1, g = 0;
scanf("%d", &c);
printf("已成功删除!\n\n");
while (p1 != NULL)
{
if (p1->time == c)
{
p2->next = p1->next;
p1->next = NULL;
g = 1;
break;
}
if (i != 1)
p2 = p1;
i++;
p1 = p1->next;
}
if (g == 1)
{
fp = fopen("rate.txt", "wb+");
struct standerd d;
p1 = head;
while (p1 != NULL)
{
fwrite(p1, sizeof(struct standerd), 1, fp);
p1 = p1->next;
}
fclose(fp);
}
else
printf("未找到此小时数!\n\n");
}
void revisionbasis()
{
FILE* fp;
struct standerd d;
int r, time, money;
printf("\n输入你要修改的计费标准(输入小时数): ");
scanf("%d", &r);
fp = fopen("rate.txt", "rb+");
while (!feof(fp))
{
fread(&d, sizeof(struct standerd), 1, fp);
if (d.time == r)
{
printf("请输入要修改的时间以及金额:");
scanf("%d%d", &time, &money);
printf("已修改成功!\n\n");
fseek(fp, -sizeof(struct standerd), 1);
d.time = time, d.money = money;
fwrite(&d, sizeof(struct standerd), 1, fp);
fclose(fp);
return;
}
}
printf("未能找到!\n\n");
fclose(fp);
return;
}
void updown(struct people d)//上下机系统
{
if (d.type == 3 || d.jur.c == 0)
{
printf("此卡已注销或无权限访问,无法上下机,请寻找管理员恢复");
return;
}
int c;
while (3)
{
printf("\n--------------<<<<<<<<<<----------------\n\n");
printf(" 1 上机\n\n 2 下机\n\n 3 退出\n\n 请选择要进入的系统:");
scanf("%d", &c);
printf("\n\n--------------<<<<<<<<<<----------------\n");
switch (c)
{
case 1:upcomputer(); break;
case 2:downcomputer(); break;
case 3:return; break;
}
}
}
void upcomputer()//上机操作
{
int u = 0;
struct people p, d, * p3;
printf("\n输入上机的卡号:");
scanf("%d", &p.card);
printf("上机成功!\n\n");
read(&p3);
while (p3 != NULL)
{
if (p3->card = p.card)
{
d = *p3;
u = 1;
break;
}
p3 = p3->next;
}
if (u == 0)
{
printf("未能找到此卡!\n\n");
}
if (d.state == 1)
{
printf("无法重复上机,此卡已经在上机状态!\n\n");
return;
}
FILE* fp;
int h = 0;//判断是否找到
struct people c;
fp = fopen("card.txt", "rb+");
while (!feof(fp))
{
fread(&c, sizeof(struct people), 1, fp);
if (c.card == d.card)
{
fseek(fp, -sizeof(struct people), 1);
h = 1;
break;
}
}
if (h == 0)
{
printf("无法找到此卡!\n\n");
return;
}
struct tm info;
time_t now = time(NULL);
info = *localtime(&now);
d.up.year = info.tm_year + 1900;
d.up.month = info.tm_mon + 1;
d.up.day = info.tm_mday;
d.up.hour = info.tm_hour;
d.up.minute = info.tm_min;
d.up.second = info.tm_sec;
d.time = now;
d.state = 1;
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
return;
}
void downcomputer()//按照上行计算,比如有1小时和3小时计费标准,上机2小时,则按照三小时的单价去计算
{
int u = 0;
struct people p, d, * p3;
printf("\n输入下机的卡号: ");
scanf("%d", &p.card);
printf("下机成功!\n\n");
read(&p3);
while (p3 != NULL)
{
if (p3->card == p.card)
{
d = *p3;
u = 1;
break;
}
p3 = p3->next;
}
if (u == 0)
{
printf("未能找到此卡!\n\n");
}
if (d.state == 0)
{
printf("此卡已在下机状态!\n\n");
return;
}
unsigned int s, e, h = 0, f, i;//s记录开始时间,e记录结束时间,h判断有没有找到卡,f最终的小时数
float y, l, cost1;
struct standerd t, * head, * p1, * p2;
struct people c;
FILE* fp, * fp1;
fp = fopen("card.txt", "rb+");
while (!feof(fp))
{
fread(&c, sizeof(struct people), 1, fp);
if (c.card == d.card)
{
fseek(fp, -sizeof(struct people), 1);
h = 1;
break;
}
}
if (h == 0)
{
printf("无法找到此卡!\n\n");
return;
}
struct tm info;
time_t now = time(NULL);
info = *localtime(&now);
d.down.year = info.tm_year + 1900;
d.down.month = info.tm_mon + 1;
d.down.day = info.tm_mday;
d.down.hour = info.tm_hour;
d.down.minute = info.tm_min;
d.down.second = info.tm_sec;
s = d.time;
e = now;
e = e - s;
y = e;
e = e / 3600;
y = y / 3600;
if (e == y)
f = y;
else
f = e + 1;
readbasis(&head);
p1 = head;
for (i = 0;; i++)
{
if (p1->next == NULL)
{
l = p1->money / p1->time;
cost1 = l * f;
d.cost = cost1;
if (d.money < cost1)
{
printf("您的余额不足,请先充值再下机\n\n");
return;
}
d.money = d.money - cost1;
d.state = 0;
d.next = NULL;
addmonthtime(d);
break;
}
if (p1->next->time >= f && p1->time < f)
{
p1 = p1->next;
l = p1->money / p1->time;//算出每小时单价
cost1 = l * f;//算出花费数
if (d.money < cost1)
{
printf("您的余额不足,请先充值再下机!\n\n");
return;
}
d.cost = cost1;//保存到结构体
d.money = d.money - cost1;//扣费
d.state = 0;//改变状态
d.next = NULL;
addmonthtime(d);
break;
}
p1 = p1->next;
}
fwrite(&d, sizeof(people), 1, fp);
fclose(fp);
fp = fopen("money.txt", "ab+");
fwrite(&d, sizeof(struct people), 1, fp);
fclose(fp);
}
void judgebasis()
{
FILE* fp;
struct standerd h;
if ((fp = fopen("rate.txt", "r")) != NULL)
{
fclose(fp);
return;
}
h.money = 0, h.time = 0;
fp = fopen("rate.txt", "wb+");
fwrite(&h, sizeof(struct standerd), 1, fp);
fclose(fp);
}
void judgemoney()//用来查消费记录和总额的
{
FILE* fp;
if ((fp = fopen("money.txt", "r")) != NULL)
{
fclose(fp);
return;
}
fp = fopen("money.txt", "w");
fclose(fp);
return;
}
void moneymanagement(struct people d)
{
int c;
if (d.type == 3 || d.jur.d == 0)
{
printf("您没有权限进入此系统");
return;
}
while (1)
{
printf("\n--------------<<<<<<<<<<----------------\n\n");
printf(" 1 查询某张卡的消费记录\n\n 2 查找一段时间内的总金额\n\n 3 查找某一年的总金额\n\n 4 退出\n\n 请选择要进入的系统:");
scanf("%d", &c);
printf("\n--------------<<<<<<<<<<----------------\n");
switch (c)
{
case 1:moneycost(); break;
case 2:findtimemoney(); break;
case 3:findyear(); break;
case 4:return; break;
}
}
}
void moneycost()//查询某张卡的消费记录
{
struct people* p1, d;
readmoney(&p1);
printf("\n输入要查询的卡号: ");
scanf("%d", &d.card);
int c = 0;
while (p1 != NULL)
{
if (p1 == NULL)
break;
if (p1->card == d.card)
{
printf("%d年%d月%d号%d时%d分%d秒开始一直到%d年%d月%d号%d时%d分%d秒下机\n", p1->up.year, p1->up.month, p1->up.day, p1->up.hour, p1->up.minute, p1->up.second, p1->down.year, p1->down.month, p1->down.day, p1->down.hour, p1->down.minute, p1->down.second);
printf("共花费%.2f元\n\n", p1->cost);
c = 1;
}
p1 = p1->next;
}
if (c == 0)
{
printf("未查询到此卡的相关消费记录\n\n");
}
}
void readmoney(struct people** head)//读取money的列表
{
FILE* fp, * fp1;
fp = fopen("money.txt", "rb");
int i;
struct people* p1, * p2;
for (i = 1;; i++)
{
if (feof(fp))
break;
if ((p1 = (struct people*)malloc(sizeof(struct people))) == NULL)
{
printf("不能成功分配储存区块!\n");
}
fread(p1, sizeof(struct people), 1, fp);
if (i == 1)
*head = p1;
else
p2->next = p1;
p2 = p1;
p1->next = NULL;
}
fclose(fp);
}
void findtimemoney()//查找一段时间的总金额(只支持年份和月份)
{
struct monthtime* p1;
int year, monthstart, monthend, i, monthjudge;
float costall = 0;
readmonthtime(&p1);
printf("\n请输入年份和开始月份,结束月份: ");
scanf("%d%d%d", &year, &monthstart, &monthend);
while (1)
{
if (p1->year == year)
{
if (p1->month >= monthstart && p1->month <= monthend)
{
monthjudge = p1->month;
while (1)
{
if (p1->next == NULL)
break;
if (p1->cost < 0)
break;
costall += p1->cost;
if (p1->next->month != monthjudge)
break;
p1 = p1->next;
}
}
}
printf("从%d月到%d月的总营业额为%.2f\n\n", monthstart, monthend, costall);
if (p1->next == NULL)
break;
p1 = p1->next;
}
}
void addmonthtime(struct people d)//每次下机都写入文件中
{
struct monthtime c;
c.cost = d.cost;
c.month = d.down.month;
c.year = d.down.year;
FILE* fp;
fp = fopen("month.txt", "a+");
fwrite(&c, sizeof(struct monthtime), 1, fp);
fclose(fp);
}
void readmonthtime(struct monthtime** head)//读取文件
{
FILE* fp;
fp = fopen("month.txt", "rb");
int i;
struct monthtime* p1, * p2;
for (i = 1;; i++)
{
if (feof(fp))
break;
if ((p1 = (struct monthtime*)malloc(sizeof(struct monthtime))) == NULL)
{
printf("不能成功分配储存区块!\n");
}
if ((fread(p1, sizeof(struct monthtime), 1, fp)) == 0)
return;
if (i == 1)
*head = p1;
else
p2->next = p1;
p2 = p1;
p2->next = NULL;
}
fclose(fp);
}
void judgemonth()//判断month.txt是否存在
{
{
FILE* fp;
if ((fp = fopen("month.txt", "r")) != NULL)
{
fclose(fp);
return;
}
fp = fopen("month.txt", "w");
fclose(fp);
return;
}
}
void findyear()//查询某一年的上机次数和当月总金额
{
int year, i, monthjudge;
float costall;
struct monthtime* p1;
readmonthtime(&p1);
printf("\n请输入要查询的年份:");
scanf("%d", &year);
while (1)
{
if (p1->year == year)
{
if (1)
{
monthjudge = p1->month;
costall = 0;
i = 0;
printf("┌──────┐────────────────────┐─────────────────────┐\n");
printf("│ %d月 │", monthjudge);
while (1)
{
if (p1->next == NULL)
break;
if (p1->cost < 0)
break;
costall += p1->cost;
i++;
if (p1->next->month != monthjudge)
break;
p1 = p1->next;
}
printf(" 总营业额为%.2f │ 总上机次数为%d次 │\n", costall, i);
printf("└──────└────────────────────└─────────────────────┘\n");
}
}
if (p1->next == NULL)
break;
p1 = p1->next;
}
}