#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
#include<process.h>
#define Up 0x48
#define Down 0x50
#define LEN sizeof(struct node)
#define LEN_ sizeof(struct node_user)
#define LEN_1 sizeof(struct node_repairman)
typedef struct node
{
char number[100];
char mima[100];
char address[100];
char profit[100];
struct node *next;
}NODE;
typedef struct node_user
{
char number_user[200];
char mima_user[100];
char mima_user2[100];
char name_user[200];
char bank_card[200];
int age;
int h;
int purse;
struct node_user *next;
}NODE_USER;
typedef struct node_repairman
{
char number_repairman[100];
char mima_repairman[100];
char mima_repairman2[100];
char name_repairman[100];
int age;
struct node_repairman *next;
}NODE_REPAIRMAN;
int icount,j,w=1,k;
//**********************函数声明**************************
void Gotoxy(int x, int y);
NODE *input ();
void show (); //管理员创建单车信息
NODE * add_node (NODE *phead); //管理员增加单车信息
void delete_node (); //管理员删除单车信息
void print ();
void print_user(NODE_USER *m);
void print_repairman_(NODE_REPAIRMAN *m);
void print_repairman_1(NODE_REPAIRMAN *m); //输出
void modify (); //修改
NODE *look_for ();
void look_for2 (NODE_USER *n);
NODE_REPAIRMAN *look_for3 ();
void look_for_bike (NODE *a);
NODE *look_for_repetition (char a[20]); //查找
void savefile(NODE *phead); //写文件(A+)
void savefile_(NODE *phead);
void savefile_user(NODE *phead);
void savefile_user_(NODE_USER *m);
void savefile_repairman_check_1(); //写文件(W)
NODE *readfile();
NODE_USER *readfile_user();
NODE_REPAIRMAN *readfile_repairman();
void user (NODE_USER *l);
void repairman_ (NODE_REPAIRMAN *l);
void admin (); //读文件
void welcome(); //欢迎函数
void send_back (NODE *d);
void sort_num();
void sign_in ();
void menu_1 (); //菜单
void choice ();
void goodbye();
//********************************************************
void Gotoxy(int x, int y) //光标移动
{
HANDLE hout;//定义句柄变量
COORD coord;//定义结构体
coord.X = x;
coord.Y = y;
hout = GetStdHandle(STD_OUTPUT_HANDLE);//获得标准输出句柄
SetConsoleCursorPosition(hout, coord);//移动光标
return;
}
NODE *input () //管理员创建单车信息
{
char s[100];
NODE *phead,*pnew,*pend;
phead=NULL;
icount=0;
pend=pnew=(NODE *)malloc(LEN);
for(;;)
{
printf("\t\t\t共享单车的车牌号(数字):");
scanf("%s",pnew->number);
strcpy(s,pnew->number);
if(strlen(pnew->number)>8)
{
printf("请输入少于8位的车牌号!\n");
}
for(j=0;(size_t)j<strlen(s);j++)
{
if(s[j]<'0'||s[j]>'9')
{
printf("车牌号只能为数字!重新输入!\n");
break;
}
}
if(strlen(pnew->number)<=8&&(size_t)j==strlen(s))
{
break;
}
}
printf("\n\n\t\t\t请为该共享单车设置密码:");
scanf("%s",pnew->mima);
for(;;)
{
loop2:
menu_1();
// system("color 07");
printf("请选择该共享单车的初始投放地点:");
scanf("%s",pnew->address);
strcpy(s,pnew->address);
for(j=0;(size_t)j<strlen(s);j++)
{
if(s[j]<'0'||s[j]>'7')
{
system("cls");
printf("\a");
// system("color 0A");
printf("\n\n\n\n\n\t\t\t\t抱歉,目前只有这几个投放地点呦! ^_^ \n");
Sleep(500);
system("cls");
goto loop2;
}
}
if(strlen(pnew->address)<=8&&(size_t)j==strlen(s))
{
break;
}
}
while(strcmp(pnew->number,"0")==1)
{
system("cls");
icount++;
if(icount==1)
{
pnew->next=NULL;
phead=pnew;
}
else
{
pnew->next=NULL;
pend->next=pnew;
pend=pnew;
}
pnew=(NODE *)malloc(LEN);
for(;;)
{
printf("共享单车的车牌号(数字):");
scanf("%s",pnew->number);
strcpy(s,pnew->number);
if(strlen(pnew->number)>8)
{
printf("请输入少于8位的车牌号!\n");
}
for(j=0;(size_t)j<strlen(s);j++)
{
if(s[j]<'0'||s[j]>'9')
{
printf("车牌号只能为数字!重新输入!\n");
break;
}
}
if(strlen(pnew->number)<=8&&(size_t)j==strlen(s))
{
break;
}
}
printf("请为该共享单车设置密码:");
scanf("%s",pnew->mima);
for(;;)
{
loop3:
menu_1();
// system("color 07");
printf("请选择该共享单车的初始投放地点:");
scanf("%s",pnew->address);
strcpy(s,pnew->address);
for(j=0;(size_t)j<strlen(s);j++)
{
if(s[j]<'0'||s[j]>'7')
{
system("cls");
printf("\a");
// system("color 0A");
printf("\n\n\n\n\n\t\t\t\t抱歉,目前只有这几个投放地点呦! ^_^ \n");
Sleep(500);
system("cls");
goto loop3;
}
}
if(strlen(pnew->address)<=8&&(size_t)j==strlen(s))
{
break;
}
}
}
printf("正在保存!");
savefile(phead);
free(pnew);
return phead;
}
void delete_node () //管理员删除单车信息
{
NODE *l,*n,*m;
char s[100];
m=l=readfile();
printf("\t\t\t\t请输入您要删除的共享单车的车牌号:\n");
scanf("%s",s);
while(l!=NULL)
{
if(strcmp(m->number,s)==0)
{
m=m->next;
printf("删除成功!\n");
break;
}
if(strcmp(l->next->number,s)==0)
{
n=l;
n=n->next;
l->next=n->next;
printf("删除成功!\n");
break;
}
l=l->next;
if(l->next==NULL)
{
printf("\t\t\t\t无删除项\n");
break;
}
}
free(n);
savefile_(m);
}
void modify () //管理员修改单车信息
{
NODE *ma,*m;
char z[100];
m=ma=readfile();
printf("\t\t\t\t请输入您要修改共享单车的车牌号:\n");
scanf("%s",z);
while(ma!=NULL)
{
if(strcmp(ma->number,z)==0)
{
printf("请修改该共享单车的密码:");
scanf("%s",ma->mima);
break;
}
ma=ma->next;
if(ma->next==NULL)
{
printf("无修改项!\n");
break;
}
}
savefile_(m);
}
NODE *look_for (NODE_USER *l) //管理员查找单车信息
{
NODE *m;
char q[100];
m=readfile();
if(l->purse <=100)
{
printf("您的金额已经不足100元!请尽快充值!\n\n");
Sleep(500);
return NULL;
}
printf("\t\t\t\t请输入你要查找的共享单车的车牌号:\n");
scanf("%s",q);
while(m!=NULL)
{
if(strcmp(m->number,q)==0)
{
l->h=1;
printf("车牌号 密码 停放地点\n\n");
printf("%s\t \t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
break;
}
m=m->next;
}
if(m==NULL)
printf("\n还没有投放该编号的车哦!");
printf("\n");
return m;
}
NODE *look_for_0 () //管理员查找单车信息
{
NODE *m,*n;
int a,b=0;
char q[100],p[100];
n=m=readfile();
int flag;
int l = 8;
printf("\n");
printf("-->管理员端");
while (1)
{
b=0;
Gotoxy(53, 8);
printf("1.按车牌号查找");
Gotoxy(53, 10);
printf("2.按停放地点查询");
Gotoxy(53, 12);
printf("3.按车号和地点查询");
Gotoxy(53, 14);
printf("4.退出查询");
Gotoxy(52, l);
printf("★");
flag = _getch();
if (flag == Down)
{
l=l+2;
if (l == 16)
l = 8;
}
if (flag == Up)
{
l=l-2;
if (l == 6)
l = 14;
}
if (flag == 13)
{
if (l == 8)
{
system("cls");
printf("\n->请输入您要查找的车的车牌号:");
scanf("%s",q);
while(n!=NULL)
{
if(strcmp(n->number,q)==0)
{
b++;
}
n=n->next;
}
if(b!=0)
printf("车牌号 密码 停放地点\n\n");
while(m!=NULL)
{
if(strcmp(m->number,q)==0)
{
printf("%s\t \t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
break;
}
m=m->next;
}
if(m==NULL)
printf("\n还没有投放该编号的车哦!");
printf("\n");
_getch();
}
if (l == 10)
{
system("cls");
menu_1();
printf("\n->请输入您要查找在该停放位置的车:");
scanf("%s",q);
while(n!=NULL)
{
if(strcmp(n->address,q)==0)
{
b++;
}
n=n->next;
}
if(b!=0)
printf("车牌号 密码 停放地点\n\n");
while(m!=NULL)
{
if(strcmp(m->address,q)==0)
{
printf("%s\t \t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
a=1;
printf("\n");
}
m=m->next;
}
if(a!=1)
{
printf("\n\n\n->该停放点的车都被骑走了哟!");
}
_getch();
}
if (l == 12)
{
system("cls");
printf("\n->请输入您要查找的车的车牌号:");
scanf("%s",q);
menu_1();
printf("\n->请输入您要查找在该停放位置的车:");
scanf("%s",p);
while(m!=NULL)
{
if(strcmp(m->number,q)==0 && strcmp(m->address,p)==0)
{
printf("车牌号 密码 停放地点\n\n");
printf("%s\t \t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
}
m=m->next;
}
if(m==NULL)
printf("\n没有符合条件的车哦!");
printf("\n");
_getch();
}
if(l == 14)
{
return NULL;
}
return m;
}
}
}
NODE *look_for_bike (char a[100]) //报修时查找单车信息
{
NODE *m;
m=readfile();
while(m!=NULL)
{
if(strcmp(m->number,a)==0)
{
break;
}
m=m->next;
}
if(m==NULL)
printf("\n亲!报修信息有误!还没有投放该编号的车哦!");
printf("\n");
return m;
}
void send_back (NODE *d) //用户归还共享单车
{
NODE *m,*l;
char s[100];
l=m=readfile();
while(m!=NULL)
{
if(strcmp(m->number,d->number)==0)
{
menu_1 ();
printf("\t\t\t请选择您归还的地点:");
scanf("%s",m->address);
strcpy(s,m->address);
for(j=0;(size_t)j<strlen(s);j++)
{
if(s[j]<'0'||s[j]>'7')
{
system("cls");
printf("\a");
printf("\n\n\n\n\n\t\t\t\t抱歉,目前只有这几个投放地点呦! ^_^ \n");
Sleep(500);
system("cls");
}
}
if(strlen(m->address)<=8&&(size_t)j==strlen(s))
{
break;
}
}
m=m->next;
}
if(m==NULL)
printf("\n还没有投放该编号的车哦!");
printf("\n");
savefile_(l);
}
NODE_USER *look_for2 () //登录
{
loop_:
NODE_USER *m,*n;
int i=0;
char c,a[100],b[100];
char x[100],password[100],p[100];
int l = 8;
system("cls");
n=m=readfile_user();
printf("-->请输入正确的账号和密码\n");
printf("\n\n\n\n");
printf("\t\t\t\t\t╔════════════════╗\t\t\t\n");
printf("\t\t\t\t\t║☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆║\t\t\t\n");
printf("\t\t\t\t\t║┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t╚════════════════╝\t\t\t\n");
while (1)
{
Gotoxy(44, 8);
printf("★我的账号:");
Gotoxy(44, 10);
printf("★我的密码:");
Gotoxy(44, l);
if(l == 8)
{
printf("☆");
Gotoxy(56,8);
scanf("%s",x);
Gotoxy(44,10);
printf("☆");
Gotoxy(56,10);
while((c=getch())!=13)
{
if(c==8)
{
printf("\b \b");
i--;
continue;
}
password[i++]=c;
putchar('*');
}
password[i]='\0';
printf("\n");
}
break;
}
while(m!=NULL)
{
if(strcmp(m->number_user,x)==0&&strcmp(m->mima_user,password)==0)
{
system("cls");
printf("登陆成功!");
break;
}
m=m->next;
}
if(m==NULL)
{
mm:
printf("\n\n\n\t\t\t\t\t 账号或密码错误!请重新输入!\n");
Sleep(500);
printf("是否忘记密码,需要找回?");
scanf("%s",p);
for(;;)
{
if(strcmp(p,"y")==0||strcmp(p,"Y")==0)
{
printf("\n->请输入账号:");
scanf("%s",a);
printf("\n->请输入充值卡号:");
scanf("%s",b);
while(n!=NULL)
{
if(strcmp(n->number_user,a)==0 && strcmp(n->bank_card,b)==0)
{
system("cls");
printf("\n\n->成功找回!下次可别忘了哟!");
printf("\n\n我的用户名:%s",n->name_user);
printf("\n\n我的账号:%s\t",n->number_user);
printf("\n\n我的密码:%s\t",n->mima_user);
printf("\n\n我的钱包:¥ %d",n->purse);
getch();
break;
}
n=n->next;
}
break;
}
else if(strcmp(p,"n")==0||strcmp(p,"N")==0)
{
printf("->已取消操作!\n");
Sleep(500);
system("cls");
break;
}
else if(strcmp(p,"y")!=0 && strcmp(p,"Y")!=0 && strcmp(p,"n")!=0 && strcmp(p,"N")!=0)
{
printf("亲!只能输入y/n哦!手误的话重新输入吧!^_^\n");
Sleep(500);
system("cls");
goto mm;
}
}
goto loop_;
}
printf("\n");
return m;
}
NODE_REPAIRMAN *look_for3 () //登录
{
loop_:
int i=0;
char c;
char x[100],password[100];
int l = 8;
NODE_REPAIRMAN *m;
system("cls");
m=readfile_repairman();
printf("-->请输入正确的账号和密码\n");
printf("\n\n\n\n");
printf("\t\t\t\t\t╔════════════════╗\t\t\t\n");
printf("\t\t\t\t\t║☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆║\t\t\t\n");
printf("\t\t\t\t\t║┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t║ ║\t\t\t\n");
printf("\t\t\t\t\t╚════════════════╝\t\t\t\n");
while (1)
{
Gotoxy(44, 8);
printf("★我的账号:");
Gotoxy(44, 10);
printf("★我的密码:");
Gotoxy(44, l);
if(l == 8)
{
printf("☆");
Gotoxy(56,8);
scanf("%s",x);
Gotoxy(44,10);
printf("☆");
Gotoxy(56,10);
while((c=getch())!=13)
{
if(c==8)
{
printf("\b \b");
i--;
continue;
}
password[i++]=c;
putchar('*');
}
password[i]='\0';
printf("\n");
}
break;
}
while(m!=NULL)
{
if(strcmp(m->number_repairman,x)==0&&strcmp(m->mima_repairman,password)==0)
{
system("cls");
printf("登陆成功!");
break;
}
m=m->next;
}
if(m==NULL)
{
printf("\n\n\t\t\t\t\t 账号或密码错误!请重新输入!\n");
goto loop_;
}
printf("\n");
return m;
}
void look_for_user (NODE_USER *m) //查找
{
NODE_USER *n;
n=readfile_user();
while(n!=NULL)
{
if(strcmp(n->number_user,m->number_user)==0)
{
system("cls");
printf("****我的信息->\n");
printf("用户名:%s\n",n->name_user);
printf("账号:%s\n",n->number_user);
printf("密码:%s\n",n->mima_user);
break;
}
n=n->next;
}
printf("\n");
}
void look_for_repairman (NODE_REPAIRMAN *m) //查找
{
NODE_REPAIRMAN *n;
n=readfile_repairman();
while(n!=NULL)
{
if(strcmp(n->number_repairman,m->number_repairman)==0)
{
system("cls");
printf("****我的信息->\n");
printf("用户名:%s\n",n->name_repairman);
printf("账号:%s\n",n->number_repairman);
printf("密码:%s\n",n->mima_repairman);
break;
}
n=n->next;
}
printf("\n");
}
void savefile(NODE *phead) //写文件
{
FILE *fp;
NODE *p;
if((fp = fopen("bike.txt", "a+"))==NULL)
printf("\a error! Can not open the file!");
// fputs("车牌号 密码 停车点\n",fp);
for(p=phead;p!=NULL;p=p->next)
{
fprintf(fp,"%s %s %s \n",p->number,p->mima,p->address);
}
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_(NODE *phead) //写文件
{
FILE *fp;
NODE *p;
if((fp = fopen("bike.txt", "w"))==NULL)
printf("\a error! Can not open the file!");
for(p=phead;p!=NULL;p=p->next)
{
fprintf(fp,"%s %s %s \n",p->number,p->mima,p->address);
}
fclose(fp);
}
void savefile_user_bike(NODE *m) //写文件
{
FILE *fp;
if((fp = fopen("repairman_.txt", "a+"))==NULL)
printf("\a error! Can not open the file!");
fprintf(fp,"%s %s %s \n",m->number,m->mima,m->address);
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_user(NODE_USER *m) //写文件
{
FILE *fp;
if((fp = fopen("user.txt", "a+"))==NULL)
printf("\a error! Can not open the file!");
fprintf(fp,"%s %s %s %s %d \n",m->name_user,m->number_user,m->mima_user,m->bank_card,m->purse);
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_user_(NODE_USER *n) //写文件
{
NODE_USER *m;
FILE *fp;
if((fp = fopen("user.txt", "w"))==NULL)
printf("\a error! Can not open the file!");
for(m=n;m!=NULL;m=m->next)
{
fprintf(fp,"%s %s %s %s %d \n",m->name_user,m->number_user,m->mima_user,m->bank_card,m->purse);
}
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_repairman(NODE_REPAIRMAN *m) //写文件
{
FILE *fp;
if((fp = fopen("repairman.txt", "a+"))==NULL)
printf("\a error! Can not open the file!");
fprintf(fp,"%s %s %s \n",m->name_repairman,m->number_repairman,m->mima_repairman);
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_repairman_check(NODE_REPAIRMAN *m) //写文件
{
FILE *fp;
if((fp = fopen("repairman_check.txt", "a+"))==NULL)
printf("\a error! Can not open the file!");
fprintf(fp," %s %s %s \n",m->name_repairman,m->number_repairman,m->mima_repairman);
/* fprintf(fp,"%s\n",m->name_repairman);
fprintf(fp,"%s\n",m->number_repairman);
fprintf(fp,"%s\n",m->mima_repairman);*/
printf("\n\n->按任意键返回!\n");
fclose(fp);
}
void savefile_repairman_check_1() //写文件
{
FILE *fp;
fp = fopen("repairman_check.txt", "w");
fclose(fp);
}
NODE *readfile() //读文件
{
NODE *head,*u;
FILE *fp;
head=(NODE *)malloc(LEN);
head->next=NULL;
fp=fopen("bike.txt","a+");
fclose(fp);
if((fp=fopen("bike.txt","r"))==NULL)
{
printf("\n--->没有找到文件!\n");
Sleep(1000);
exit(0);
}
/* else
{
rewind(fp);
fgets(a,66,fp);
}
*/
while(!feof(fp))
{
u=(NODE *)malloc(LEN);
u->next=NULL;
fscanf(fp,"%s %s %s \n",u->number,u->mima,u->address);
u->next=head->next;
head->next=u;
}
fclose(fp);
return (head->next);
}
NODE_USER *readfile_user() //读文件
{
NODE_USER *head,*m;
FILE *fp;
head=(NODE_USER *)malloc(LEN_);
head->next=NULL;
fp=fopen("user.txt","a+");
fclose(fp);
if((fp=fopen("user.txt","r"))==NULL)
{
printf("\n--->没有找到文件!\n");
Sleep(1000);
exit(0);
}
while(!feof(fp))
{
m=(NODE_USER *)malloc(LEN_);
m->next=NULL;
fscanf(fp,"%s %s %s %s %d \n",m->name_user,m->number_user,m->mima_user,m->bank_card,&m->purse);
m->next=head->next;
head->next=m;
}
fclose(fp);
return (head->next);
}
NODE *readfile_user_bike()
{
char ch;
NODE *head,*m;
FILE *fp;
head=(NODE *)malloc(LEN);
head->next=NULL;
fp=fopen("repairman_.txt","a+");
fclose(fp);
if((fp=fopen("repairman_.txt","r"))==NULL)
{
printf("\n--->没有找到文件!\n");
Sleep(1000);
exit(0);
}
ch=fgetc(fp);
if(ch==EOF)
{
printf("还没有人报修呢!可以休息等等哦!\n\n");
k=1;
return NULL;
}
while(!feof(fp))
{
m=(NODE *)malloc(LEN);
m->next=NULL;
fscanf(fp,"%s %s %s \n",m->number,m->mima,m->address);
m->next=head->next;
head->next=m;
}
fclose(fp);
return (head->next);
}
NODE_REPAIRMAN *readfile_repairman() //读文件
{
NODE_REPAIRMAN *head,*m;
FILE *fp;
head=(NODE_REPAIRMAN *)malloc(LEN_);
head->next=NULL;
fp=fopen("repairman.txt","a+");
fclose(fp);
if((fp=fopen("repairman.txt","r"))==NULL)
{
printf("\n--->没有找到文件!\n");
Sleep(1000);
exit(0);
}
while(!feof(fp))
{
m=(NODE_REPAIRMAN *)malloc(LEN_);
m->next=NULL;
fscanf(fp,"%s %s %s \n",m->name_repairman,m->number_repairman,m->mima_repairman);
m->next=head->next;
head->next=m;
}
fclose(fp);
return (head->next);
}
NODE_REPAIRMAN *readfile_repairman_check() //读文件
{
char ch;
NODE_REPAIRMAN *head,*m;
FILE *fp;
head=(NODE_REPAIRMAN *)malloc(LEN_);
head->next=NULL;
fp=fopen("repairman_check.txt","a+");
fclose(fp);
if((fp=fopen("repairman_check.txt","r"))==NULL)
{
printf("\n--->没有找到文件!\n");
Sleep(1000);
exit(0);
}
ch=fgetc(fp);
if(ch==EOF)
{
w=0;
}
while(!feof(fp))
{
m=(NODE_REPAIRMAN *)malloc(LEN_);
m->next=NULL;
fscanf(fp," %s %s %s \n",m->name_repairman,m->number_repairman,m->mima_repairman);
m->next=head->next;
head->next=m;
}
fclose(fp);
return (head->next);
}
void submit()
{
int i;
system("cls");
printf("\n\n\n\n\t\t\t\t");
printf("★正在提交您的信息!★");
printf("\n\t\t\t ");
for(i=0;i<7;i++)
{
printf("-> ");
Sleep(300);
}
system("cls");
}
void goodbye()
{
int i;
system("cls");
printf("\n\n\n\n\t\t\t\t");
printf("★正在退出!★");
printf("\n\t\t\t ");
for(i=0;i<5;i++)
{
printf("-> ");
Sleep(300);
}
system("cls");
}
void show ()
{
printf("-->使用指南!\n\n");
printf(" 欢迎使用共享单车系统!该管理系统面向大众,可使用手机号自\n\n");
Sleep(500);
printf("行注册用户端以及维修员,用户完成注册后即可使用,维修员需要等\n\n");
Sleep(500);
printf("待管理员审核通过即可工作,每个手机号只能注册一次。\n\n\n");
Sleep(500);
printf(" 用户租车收费:每半个小时1元,不满半小时按照一小时计算。\n\n\n\n\n\n\n");
Sleep(500);
printf("感谢您的阅读。按任意键进入系统 ^_^ ");
getch();
}
void check ()
{
NODE_REPAIRMAN *d;
int flag;
int l = 8;
printf("\n");
printf("-->管理员端");
while (1)
{
Gotoxy(53, 8);
printf("1.待认证的维修员 ");
Gotoxy(53, 10);
printf("2.已注册的维修员");
Gotoxy(53, 12);
printf("3.返回上一层");
Gotoxy(52, l);
printf("★");
flag = _getch();
if (flag == Down)
{
l=l+2;
if (l == 14)
l = 8;
}
if (flag == Up)
{
l=l-2;
if (l == 6)
l = 12;
}
if (flag == 13)
{
if (l == 8)
{
system("cls");
d=readfile_repairman_check();
print_repairman_(d);
_getch();
}
if (l == 10)
{
system("cls");
d=readfile_repairman();
print_repairman_1(d);
printf("\n\n->按任意键继续!");
getch();
system("cls");
_getch();
}
if (l == 12)
{
system("cls");
return;
}
}
}
}
void menu_1 ()
{
printf("\t\t ----------------------------------------------------------- \t\t\t\n");
printf("\t\t| 共享单车 长安区停放地点 |\t\t\t\n");
printf("\t\t|-----------------------------------------------------------|\t\t\t\n");
printf("\t\t| 【0】:长安广场 【1】:南大学城 【2】:三森 |\t\t\t\n");
printf("\t\t| |\t\t\t\n");
printf("\t\t| 【3】:紫薇都市 【4】:韦曲西街 【5】:航天城 |\t\t\t\n");
printf("\t\t| |\t\t\t\n");
printf("\t\t| 【6】:韦曲南站 【7】:秦岭沿线 |\t\t\t\n");
printf("\t\t ----------------------------------------------------------- \t\t\t\n");
}
void sign_in ()
{
NODE_USER *n;
NODE_REPAIRMAN *l;
int flag;
int z = 8;
system("cls");
while (1)
{
Gotoxy(53, 8);
printf("1.管理员登陆");
Gotoxy(53, 10);
printf("2.用户登陆");
Gotoxy(53, 12);
printf("3.维修员登陆");
Gotoxy(53, 14);
printf("0.退出登录");
Gotoxy(52, z);
printf("★");
flag = _getch();
if (flag == Down)
{
z=z+2;
if (z == 16)
z = 8;
}
if (flag == Up)
{
z=z-2;
if (z == 6)
z = 14;
}
if (flag == 13)
{
if (z == 8)
{
system("cls");
admin();
_getch();
}
if (z == 10)
{
n=look_for2();
user (n);
system("cls");
_getch();
}
if (z == 12) //权限在老师端之上才能注册
{
l=look_for3();
repairman_(l);
_getch();
}
if (z == 14)
{
system("cls");
return;
}
}
}
}
void print () //输出单车信息
{
NODE *m;
m=readfile();
printf("车牌号 密码 停放地点\n\n");
while(m!=NULL)
{
printf("%s\t\t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
m=m->next;
printf("\n\n");
}
}
void print_user(NODE_USER *m)
{
int i=0;
while(m!=NULL)
{
i++;
printf("第%d个用户:\t",i);
printf("用户名:%-16s",m->name_user);
printf("账号:%-16s\t",m->number_user);
printf("密码:%-16s\t",m->mima_user);
printf("账户余额:¥ %d",m->purse);
m=m->next;
printf("\n\n");
}
printf("->按任意键继续!");
getch();
}
void print_repairman_(NODE_REPAIRMAN *m)
{
int i=0;
char n[10];
if(w==0)
{
printf("\n-->还没有人申请哦!\n");
printf("\n->请按任意键继续。");
return;
}
printf("-->正等待认证通过\n\n\n");
while(m!=NULL)
{
i++;
printf("第%d个申报维修人员:\t",i);
printf("用户名:%s\t\t",m->name_repairman);
printf("账号:%s\t\t",m->number_repairman);
printf("密码:%s\t\t",m->mima_repairman);
printf("\n\n是否通过?(y/n):");
scanf("%s",n);
if(strcmp(n,"y")==0 || strcmp(n,"Y")==0)
{
printf("\n\n->已通过认证!\n");
savefile_repairman(m);
}
if(strcmp(n,"n")==0 || strcmp(n,"N")==0)
{
printf("\n\n->已驳回申诉!\n");
}
m=m->next;
printf("\n\n");
}
savefile_repairman_check_1();
}
void print_repairman_1(NODE_REPAIRMAN *m)
{
int i=0;
while(m!=NULL)
{
i++;
printf("第%d个维修人员:",i);
printf("用户名:%-15s",m->name_repairman);
printf("账号:%-18s",m->number_repairman);
printf("密码:%s",m->mima_repairman);
m=m->next;
printf("\n\n");
}
}
void print_repairman () //输出报修单车信息
{
NODE *m;
m=readfile_user_bike();
if(k==0)
printf("车牌号 密码 停放地点\n\n");
while(m!=NULL)
{
printf("%s\t\t",m->number);
printf("%s\t ",m->mima);
if(strcmp(m->address,"0")==0)
printf("长安广场");
if(strcmp(m->address,"1")==0)
printf("南大学城");
if(strcmp(m->address,"2")==0)
printf("三森");
if(strcmp(m->address,"3")==0)
printf("紫薇都市");
if(strcmp(m->address,"4")==0)
printf("韦曲西街");
if(strcmp(m->address,"5")==0)
printf("航天城");
if(strcmp(m->address,"6")==0)
printf("韦曲南站");
if(strcmp(m->address,"7")==0)
printf("秦岭沿线");
m=m->next;
printf("\n\n");
}
}
void welcome() //输入密钥进入管理员
{
int i=0;
char c;
char password[100];
char num[100];
strcpy(num,"152323");
loopback3:
system("cls");
printf(" \n\n\n\n\n\n\n\n");
printf("\t\t\t\t欢迎使用共享单车管理系统!\n\n\n");
printf("\t\t\t\t请输入管理员密码:");
while((c=getch())!=13)
{
if(c==8)
{
printf("\b \b");
i--;
continue;
}
password[i++]=c;
putchar('*');
}
password[i]='\0';
if(strcmp(password,num)==0)
{
system("cls");
}
else
{
printf("\t\t\t\t 密码错误!"); //密码错误重新输出
Sleep(100);
system("cls");
goto loopback3;
}
}
void user (NODE_USER *l)
{
time_t first,second;
double s;
int p=1,q=0,t=0;
char n[100],yn[100],h[100];
NODE *m,*g,*v,*y;
NODE_USER *o,*k,*f;
int flag;
int z = 4,d;
f=k=o=readfile_user();
while(k!=NULL)
{
if(strcmp(l->number_user,k->number_user)==0)
break;
k=k->next;
}
printf("\n");
printf("-->用户端");
while (1)
{
q=0;
Gotoxy(53, 4);
printf("1.附近的车");
Gotoxy(53, 6);
printf("2.立即用车");
Gotoxy(53, 8);
printf("3.立即还车");
Gotoxy(53, 10);
printf("4.我要报修");
Gotoxy(53, 12);
printf("5.我的信息");
Gotoxy(53, 14);
printf("6.我去充值");
Gotoxy(53, 16);
printf("0.退出登录");
Gotoxy(52, z);
printf("★");
flag = _getch();
if (flag == Down)
{
z=z+2;
if (z == 18)
z = 4;
}
if (flag == Up)
{
z=z-2;
if (z == 2)
z = 16;
}
if (flag == 13)
{
if(z == 4)
{
system("cls");
menu_1();
printf("请选择您所在的地点代号:");
scanf("%s",h);
y=v=readfile();
while(y!=NULL)
{
if(strcmp(y->address,h)==0)
{
t++;
}
y=y->next;
}
if(t!=0)
printf("车牌号 密码 停放地点\n\n");
while(v!=NULL)
{
if(strcmp(v->address,h)==0)
{
q=1;
printf("%s\t \t",v->number);
printf("%s\t ",v->mima);
if(strcmp(v->address,"0")==0)
printf("长安广场");
if(strcmp(v->address,"1")==0)
printf("南大学城");
if(strcmp(v->address,"2")==0)
printf("三森");
if(strcmp(v->address,"3")==0)
printf("紫薇都市");
if(strcmp(v->address,"4")==0)
printf("韦曲西街");
if(strcmp(v->address,"5")==0)
printf("航天城");
if(strcmp(v->address,"6")==0)
printf("韦曲南站");
if(strcmp(v->address,"7")==0)
printf("秦岭沿线");
printf("\n");
}
v=v->next;
}
if(q==0)
{
printf("\n\n->这里的小车都被骑走啦!");
Sleep(500);
}
printf("\n");
getch();
system("cls");
}
if (z == 6)
{
system("cls");
if(k->h==1)
{
printf("->您已经在使用共享单车了!一个账号只能同时租一个哦!\n");
printf("->按任意键继续。。。\n");
getch();
}
else
{
system("cls");
g=look_for (k);
first=time(NULL);
printf("->按任意键继续。。。\n");
getch();
}
_getch();
}
if (z == 8)
{
system("cls");
if(k->h==1)
{
send_back(g);
second=time(NULL);
s=difftime(second,first);
k->h=0;
}
else
{
printf("还没有借车呐!快去骑共享单车哦!\n\n");
goto mn;
}
while(1)
{
if(s > 1800.0)
{
s=s-1800.0;
p++;
}
else
break;
}
system("cls");
if(p==1)
{
k->purse=k->purse-1;
printf("您总共骑行%0.1f秒,您需要支付 $1 yuan\n",s);
printf("\n\n账户余额%d元",k->purse);
savefile_user_(o);
}
else
printf("您总共骑行%0.1f秒,您需要支付 $%d yuan\n",s,p);
mn:
_getch();
}
if (z == 10)
{
system("cls");
loop__1:
while(1)
{
printf("请输入您要报修的共享单车的车牌号:");
scanf("%s",n);
m=look_for_bike (n);
if(m!=0)
{
break;
}
}
printf("您确定要报修吗?(y/n)");
scanf("%s",yn);
for(;;)
{
if(strcmp(yn,"y")==0||strcmp(yn,"Y")==0)
{
printf("感谢您的反馈!如果我们确认申报无误的话,会给您加分哦!\n");
savefile_user_bike(m);
break;
}
else if(strcmp(yn,"n")==0||strcmp(yn,"N")==0)
{
printf("->已取消操作!\n");
Sleep(500);
system("cls");
break;
}
else if(strcmp(yn,"y")!=0 && strcmp(yn,"Y")!=0 && strcmp(yn,"n")!=0 && strcmp(yn,"N")!=0)
{
printf("亲!只能输入y/n哦!手误的话重新输入吧!^_^\n");
Sleep(500);
system("cls");
goto loop__1;
}
}
_getch();
}
if (z == 12)
{
system("cls");
look_for_user (l);
printf("浏览完毕后,按任意键继续!\n");
_getch();
}
if (z == 14)
{
system("cls");
printf("您已绑定充值卡!请输入充值金额:");
scanf("%d",&d);
while(f!=NULL)
{
if(strcmp(l->number_user,f->number_user)==0)
break;
f=f->next;
}
printf("\n当前余额%d元,充值后为%d元",f->purse,f->purse+d);
f->purse=f->purse+d;
savefile_user_(o);
printf("\n\n->充值成功!");
Sleep(1000);
system("cls");
}
if (z == 16)
{
return;
}
}
}
}
void repairman_ (NODE_REPAIRMAN *l)
{
int flag;
int z = 8;
system("cls");
printf("\n->维修员端");
while (1)
{
Gotoxy(53, 8);
printf("1.我的信息");
Gotoxy(53, 10);
printf("2.用户报修车辆");
Gotoxy(53, 12);
printf("0.返回上一层");
Gotoxy(52, z);
printf("★");
flag = _getch();
if (flag == Down)
{
z=z+2;
if (z == 14)
z = 8;
}
if (flag == Up)
{
z=z-2;
if (z == 6)
z = 12;
}
if (flag == 13)
{
if (z == 8)
{
system("cls");
look_for_repairman (l);
_getch();
}
if (z == 10)
{
system("cls");
print_repairman ();
_getch();
}
if (z == 12) //权限在老师端之上才能注册
{
system("cls");
return;
}
}
}
}
void admin ()
{
NODE_USER *m;
welcome();
NODE *phead;
int flag;
int l = 4;
printf("\n");
printf("-->管理员端");
while (1)
{
Gotoxy(53, 4);
printf("1.添加单车");
Gotoxy(53, 6);
printf("2.删除单车");
Gotoxy(53, 8);
printf("3.修改单车密码");
Gotoxy(53, 10);
printf("4.查找单车");
Gotoxy(53, 12);
printf("5.所有单车及其盈利");
Gotoxy(53, 14);
printf("6.用户信息");
Gotoxy(53, 16);
printf("7.维修员信息");
Gotoxy(53, 18);
printf("0.退出登录");
Gotoxy(52, l);
printf("★");
flag = _getch();
if (flag == Down)
{
l=l+2;
if (l == 20)
l = 4;
}
if (flag == Up)
{
l=l-2;
if (l == 2)
l = 18;
}
if (flag == 13)
{
if (l == 4)
{
system("cls");
phead=input ();
printf("\a 保存成功!");
Sleep(500);
system("cls");
_getch();
}
if (l == 6)
{
system("cls");
delete_node ();
system("cls");
_getch();
}
if (l == 8)
{
system("cls");
modify ();
system("cls");
_getch();
}
if (l == 10)
{
system("cls");
look_for_0();
system("cls");
_getch();
}
if (l == 12)
{
system("cls");
printf("--->读取成功!\n\n");
print() ;
getch();
// system("cls");
_getch();
}
if (l == 14)
{
system("cls");
m=readfile_user();
print_user(m);
system("cls");
_getch();
}
if (l == 16)
{
system("cls");
check();
system("cls");
_getch();
}
if (l == 18)
{
system("cls");
return;
}
}
}
}
void choice()
{
char c[5];
int flag;
int z = 8;
while (1)
{
Gotoxy(53, 8);
printf("1.登录");
Gotoxy(53, 10);
printf("2.注册");
Gotoxy(53, 12);
printf("3.退出");
Gotoxy(52, z);
printf("★");
flag = _getch();
if (flag == Down)
{
z=z+2;
if (z == 14)
z = 8;
}
if (flag == Up)
{
z=z-2;
if (z == 6)
z = 12;
}
if (flag == 13)
{
if (z == 8)
{
sign_in ();
}
if (z == 10)
{
NODE_USER *m,*n;
m=(NODE_USER *)malloc(LEN_);
m->next=NULL;
NODE_REPAIRMAN *k,*l;
k=(NODE_REPAIRMAN *)malloc(LEN_1);
k->next=NULL;
system("cls");
printf("注册用户请按1\t注册维修员请按2(需要等待审核)\n\n");
printf("请选择:");
scanf("%s",c);
if(strcmp(c,"1")==0)
{
printf("★亲!请按照指示操作完成用户注册哦!\n");
for(;;)
{
printf("\n\n请输入绑定的手机号(账号):");
scanf("%s",m->number_user); //报修时查找单车信息
n=readfile_user();
while(n!=NULL)
{
if(strcmp(n->number_user,m->number_user)==0)
{
printf("亲!这个手机号已经被注册过了呦!");
break;
}
n=n->next;
}
if(n==NULL)
{
printf("\t\t\t\t\t-------这个账号还没有人注册过呢!");
break;
}
printf("\n");
}
for(;;)
{
printf("\n\n请设置密码:");
scanf("%s",m->mima_user);
if(strlen(m->mima_user)<=2)
printf("\t\t\t\t\t安全系数★★,很不安全哦!");
if(strlen(m->mima_user)<=6&&strlen(m->mima_user)>2)
printf("\t\t\t\t\t安全系数★★★,一般安全!");
if(strlen(m->mima_user)>7)
printf("\t\t\t\t\t安全系数★★★★★,非常安全!");
printf("\n\n请确认密码:");
scanf("%s",m->mima_user2);
printf("\n\n请输入您的年龄:");
scanf("%d",&m->age);
if(m->age <= 10)
{
printf("年龄过小哦!长大再骑吧!共享单车伴你成长!\n");
system("cls");
break;
}
if(m->age >= 65)
{
printf("您已超过使用年限!抱歉!\n");
system("cls");
break;
}
if(strcmp(m->mima_user,m->mima_user2)==0)
{
system("cls");
submit();
printf("\n->注册成功!");
printf("\n\n快为自己起一个霸气的用户名吧!\n");
scanf("%s",m->name_user);
printf("\n\n请先给自己钱包充值哦!(200元)");
printf("\n\n请输入充值卡号(系统将自动为您扣除):");
scanf("%s",m->bank_card);
m->purse=200;
savefile_user(m);
break;
}
if(strcmp(m->mima_user,m->mima_user2)!=0)
{
printf("\a亲,两次输入密码不一样哦!\n");
Sleep(500);
}
}
}
if(strcmp(c,"2")==0)
{
printf("★亲!请按照指示操作完成维修员注册哦!\n");
for(;;)
{
printf("\n\n请输入绑定的手机号(账号):");
scanf("%s",k->number_repairman);
getchar();
l=readfile_repairman();
while(l!=NULL)
{
if(strcmp(l->number_repairman,k->number_repairman)==0)
{
printf("亲!这个手机号已经被注册过了呦!");
break;
}
l=l->next;
}
if(l==NULL)
{
printf("\t\t\t\t\t-------这个账号还没有人注册过呢!");
break;
}
printf("\n");
}
for(;;)
{
printf("\n\n请设置密码:");
scanf("%s",k->mima_repairman);
getchar();
if(strlen(k->mima_repairman)<=2)
printf("\t\t\t\t\t安全系数★★,很不安全哦!");
if(strlen(k->mima_repairman)<=6&&strlen(k->mima_repairman)>2)
printf("\t\t\t\t\t安全系数★★★,一般安全!");
if(strlen(k->mima_repairman)>7)
printf("\t\t\t\t\t安全系数★★★★★,非常安全!");
printf("\n\n请确认密码:");
scanf("%s",k->mima_repairman2);
printf("\n\n请输入您的年龄:");
scanf("%d",&k->age);
getchar();
if(k->age <= 10)
{
printf("年龄过小哦!不能注册维修员,共享单车伴你成长!\n");
system("cls");
break;
}
if(k->age >= 65)
{
printf("您已超过使用年限!抱歉!\n");
system("cls");
break;
}
if(strcmp(k->mima_repairman,k->mima_repairman2)==0)
{
system("cls");
submit();
printf("\n->申请成功!等待管理员审核!");
printf("\n\n快为自己起一个霸气的用户名吧!\n");
scanf("%s",k->name_repairman);
savefile_repairman_check(k);
break;
}
if(strcmp(k->mima_repairman,k->mima_repairman2)!=0)
{
printf("\a亲,两次输入密码不一样哦!\n");
Sleep(500);
}
}
}
_getch();
}
if (z == 12)
{
goodbye();
exit(0);
}
}
}
}
// admin(); //管理员
// user(); //用户
//repairman(); //维修员
int main (void)
{
system("color F1");
show ();
system("cls");
choice();
}
|