要求:
1.充值功能;
2.刷卡功能:公交刷卡,地铁刷卡,扣款;
3.配置功能:基本票价,公交车票折扣,地铁票折扣,学生票折扣的设置和调整
4.余额查询:余额不足报警系统
5.数据配置文件的保存,读取以及修改
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
typedef struct Bus
{
int num;
char name[20];
int money;
int state;
struct Bus * pnext;
} Bus;
int NUMBER=0;
Bus * Head = NULL;//链表头指针
Bus * End = NULL;
void Save() //存入板块
{
FILE * pfile=NULL;
struct Bus * atemp=Head;
if(atemp==NULL)
{
return;
}
pfile=fopen("一卡通.dat","wb");
//以二进制格式打开一个文件只用于写入
if(pfile==NULL)
{
printf("\n警告:用户数据丢失请检查!!!\n");
}
while(atemp!=NULL)
{
fwrite(atemp,sizeof(struct Bus),1,pfile);
//是要输出数据的地址。
//要写入的字节数;
//要进行写入size字节的数据项的个数;
//目标文件指针。
atemp=atemp->pnext;
}
fclose(pfile);
}
void Read() //读取文件
{
int count=0;
FILE *fp;
if ((fp = fopen("一卡通.dat", "rb")) == NULL )
{
printf("\n警告:用户数据丢失请检查!!!\n");
return;
}
else
{
while(!feof(fp))
{
Bus * atemp=(struct Bus *)malloc(sizeof(struct Bus));
fread(atemp, sizeof(struct Bus), 1, fp);
count++;
}
fp = fopen("公交一卡通.dat", "rb");
while(count!=1)
{
Bus * atemp=(struct Bus *)malloc(sizeof(struct Bus));
fread(atemp, sizeof(struct Bus), 1, fp);
if (NULL==Head||NULL==End) //排除只有头尾的情况
{
Head = atemp; //链表为空,新节点即是头也是尾
End = atemp;
}
else
{
End->pnext =atemp; //新节点下一个指向尾
End = atemp; //新节点变成尾
}
count--;
}
}
fclose(fp);
}
void loading()
{
int k=1;
for(; k<3; k++)
{
system("cls");
printf("| 请稍等. | \n");
printf("| 加载中: -- | \n");
Sleep(200);
system("cls");
printf("| 请稍等.. | \n");
printf("| 加载中: \\ | \n");
Sleep(200);
system("cls");
printf("| 请稍等... | \n");
printf("| 加载中: || | \n");
Sleep(200);
system("cls");
printf("| 请稍等.... | \n");
printf("| 加载中: // | \n");
Sleep(200);
system("cls");
printf("| 请稍等..... | \n");
printf("| 加载中: -- | \n");
Sleep(200);
system("cls");
printf("| 请稍等...... | \n");
printf("| 加载中: \\ | \n");
Sleep(200);
system("cls");
printf("| 请稍等...... | \n");
printf("| 加载中: || | \n");
Sleep(200);
system("cls");
printf("| 请稍等...... | \n");
printf("| 加载中: // | \n");
Sleep(200);
system("cls");
}
}
void CreateList() //创建板块
{
Bus * ate