您好,登錄后才能下訂單哦!
這篇“怎么用C語言實現(xiàn)共享單車管理系統(tǒng)”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“怎么用C語言實現(xiàn)共享單車管理系統(tǒng)”文章吧。
1.登陸:登陸分為用戶登陸,管理員登陸以及維修員登錄,登陸后不同的用戶所執(zhí)行的操作不同,權(quán)限不同。
(1)管理員登錄:管理員登陸之后,可使用鍵盤的上下鍵來控制菜單上的選項,管理員權(quán)限不多,可執(zhí)行最多的操作,可以對單車進(jìn)行投放,刪除,修改,查找,車牌號排序,查看所有單車信息,所有用戶信息,管理員能通過或駁回正在申請注冊的維修員,還可以查看完全通過認(rèn)證的維修員。
(2)用戶登錄:用戶登錄時需要輸入注冊時的賬號和密碼,或者是之前注冊的有效賬號及密碼,用戶可以查看自己附近的車,立即用車當(dāng)車密碼出現(xiàn)的時候就開始計時了,還車后停止計時,一個時間段內(nèi)沒有還車不能再借車了,另外還有報修,報修的信息會上傳到維修員那里,還可以查看自己的信息修改自己的信息,當(dāng)用戶賬號不足100元時不能再借車了,所以還有充值這一項功能。
(3)維修員登錄:維修員登錄時也需要賬戶和密碼(管理員認(rèn)證的),維修員權(quán)限較大,只可以查看自己的信息,修改自己的信息,以及查看用戶報修的單車信息。
2.注冊:注冊有用戶注冊和維修員注冊。
(1)用戶注冊:用戶注冊時,手機(jī)號即為登錄賬戶,有查重的功能,每個手機(jī)號只能注冊一個用戶,設(shè)置密碼時,系統(tǒng)會對你的密碼的安全系數(shù)進(jìn)行評分,以及需要確認(rèn)密碼,兩次不一致注冊失敗,輸入年齡,年齡不滿10歲不可注冊,注冊成功后需要起一個用戶名,需要綁定充值卡,首次充值200元,即可登錄。
(2)維修員注冊:維修員注冊時,手機(jī)號即為登錄賬戶,也有查重的功能,每個手機(jī)號只能注冊一個用戶,設(shè)置密碼時,系統(tǒng)會對你的密碼的安全系數(shù)進(jìn)行評分,以及需要確認(rèn)密碼,兩次不一致注冊失敗,后需要起一個用戶名,輸入年齡,年齡不滿18歲不可注冊,但此時并沒有注冊成功,只是完成了申請,不可登錄,等待管理員認(rèn)證,通過,注冊成功,即可登錄,駁回,注冊失敗。
3.增加:增加單車信息到文件 中。
4.修改:修改單車信息,修改用戶個人信息,修改維修員個人信息。
5.刪除:刪除單車。
6.查找:查找單車并按所選順序查看。
(1).功能函數(shù)的調(diào)用關(guān)系圖
(2).各功能函數(shù)的數(shù)據(jù)流程圖
a.(查找單車)
b.(增加單車)
c.(刪除單車)
d.(修改單車信息)
e.(查看所有用戶信息)
f.(查看所有維修員信息)
g.(注冊)
h.(登陸)
3.代碼:
#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; //**********************函數(shù)聲明************************** void Gotoxy(int x, int y); NODE *input (); void show (); //管理員創(chuàng)建單車信息 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(); //歡迎函數(shù) void send_back (NODE *d); void sort_num(); void sign_in (); void menu_1 (); //菜單 void choice (); void goodbye(); //******************************************************** void Gotoxy(int x, int y) //光標(biāo)移動 { HANDLE hout;//定義句柄變量 COORD coord;//定義結(jié)構(gòu)體 coord.X = x; coord.Y = y; hout = GetStdHandle(STD_OUTPUT_HANDLE);//獲得標(biāo)準(zhǔn)輸出句柄 SetConsoleCursorPosition(hout, coord);//移動光標(biāo) return; } NODE *input () //管理員創(chuàng)建單車信息 { char s[100]; NODE *phead,*pnew,*pend; phead=NULL; icount=0; pend=pnew=(NODE *)malloc(LEN); for(;;) { printf("\t\t\t共享單車的車牌號(數(shù)字):"); 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("車牌號只能為數(shù)字!重新輸入!\n"); break; } } if(strlen(pnew->number)<=8&&(size_t)j==strlen(s)) { break; } } printf("\n\n\t\t\t請為該共享單車設(shè)置密碼:"); 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("共享單車的車牌號(數(shù)字):"); 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("車牌號只能為數(shù)字!重新輸入!\n"); break; } } if(strlen(pnew->number)<=8&&(size_t)j==strlen(s)) { break; } } printf("請為該共享單車設(shè)置密碼:"); 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("您的金額已經(jīng)不足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("南大學(xué)城"); 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("南大學(xué)城"); 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("南大學(xué)城"); 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("南大學(xué)城"); 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(" 歡迎使用共享單車系統(tǒng)!該管理系統(tǒng)面向大眾,可使用手機(jī)號自\n\n"); Sleep(500); printf("行注冊用戶端以及維修員,用戶完成注冊后即可使用,維修員需要等\n\n"); Sleep(500); printf("待管理員審核通過即可工作,每個手機(jī)號只能注冊一次。\n\n\n"); Sleep(500); printf(" 用戶租車收費:每半個小時1元,不滿半小時按照一小時計算。\n\n\n\n\n\n\n"); Sleep(500); printf("感謝您的閱讀。按任意鍵進(jìn)入系統(tǒng) ^_^ "); getch(); } void check () { NODE_REPAIRMAN *d; int flag; int l = 8; printf("\n"); printf("-->管理員端"); while (1) { Gotoxy(53, 8); printf("1.待認(rèn)證的維修員 "); 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->按任意鍵繼續(xù)!"); getch(); system("cls"); _getch(); } if (l == 12) { system("cls"); return; } } } } void menu_1 () { printf("\t\t ----------------------------------------------------------- \t\t\t\n"); printf("\t\t| 共享單車 長安區(qū)停放地點 |\t\t\t\n"); printf("\t\t|-----------------------------------------------------------|\t\t\t\n"); printf("\t\t| 【0】:長安廣場 【1】:南大學(xué)城 【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) //權(quán)限在老師端之上才能注冊 { 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("南大學(xué)城"); 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("->按任意鍵繼續(xù)!"); getch(); } void print_repairman_(NODE_REPAIRMAN *m) { int i=0; char n[10]; if(w==0) { printf("\n-->還沒有人申請哦!\n"); printf("\n->請按任意鍵繼續(xù)。"); return; } printf("-->正等待認(rèn)證通過\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->已通過認(rè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("南大學(xué)城"); 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() //輸入密鑰進(jìn)入管理員 { 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歡迎使用共享單車管理系統(tǒng)!\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("南大學(xué)城"); 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("->您已經(jīng)在使用共享單車了!一個賬號只能同時租一個哦!\n"); printf("->按任意鍵繼續(xù)。。。\n"); getch(); } else { system("cls"); g=look_for (k); first=time(NULL); printf("->按任意鍵繼續(xù)。。。\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("感謝您的反饋!如果我們確認(rèn)申報無誤的話,會給您加分哦!\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("瀏覽完畢后,按任意鍵繼續(xù)!\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āng)前余額%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) //權(quán)限在老師端之上才能注冊 { 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請輸入綁定的手機(jī)號(賬號):"); scanf("%s",m->number_user); //報修時查找單車信息 n=readfile_user(); while(n!=NULL) { if(strcmp(n->number_user,m->number_user)==0) { printf("親!這個手機(jī)號已經(jīng)被注冊過了呦!"); break; } n=n->next; } if(n==NULL) { printf("\t\t\t\t\t-------這個賬號還沒有人注冊過呢!"); break; } printf("\n"); } for(;;) { printf("\n\n請設(shè)置密碼:"); scanf("%s",m->mima_user); if(strlen(m->mima_user)<=2) printf("\t\t\t\t\t安全系數(shù)★★,很不安全哦!"); if(strlen(m->mima_user)<=6&&strlen(m->mima_user)>2) printf("\t\t\t\t\t安全系數(shù)★★★,一般安全!"); if(strlen(m->mima_user)>7) printf("\t\t\t\t\t安全系數(shù)★★★★★,非常安全!"); printf("\n\n請確認(rè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請先給自己錢包充值哦?。?00元)"); printf("\n\n請輸入充值卡號(系統(tǒng)將自動為您扣除):"); 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請輸入綁定的手機(jī)號(賬號):"); scanf("%s",k->number_repairman); getchar(); l=readfile_repairman(); while(l!=NULL) { if(strcmp(l->number_repairman,k->number_repairman)==0) { printf("親!這個手機(jī)號已經(jīng)被注冊過了呦!"); break; } l=l->next; } if(l==NULL) { printf("\t\t\t\t\t-------這個賬號還沒有人注冊過呢!"); break; } printf("\n"); } for(;;) { printf("\n\n請設(shè)置密碼:"); scanf("%s",k->mima_repairman); getchar(); if(strlen(k->mima_repairman)<=2) printf("\t\t\t\t\t安全系數(shù)★★,很不安全哦!"); if(strlen(k->mima_repairman)<=6&&strlen(k->mima_repairman)>2) printf("\t\t\t\t\t安全系數(shù)★★★,一般安全!"); if(strlen(k->mima_repairman)>7) printf("\t\t\t\t\t安全系數(shù)★★★★★,非常安全!"); printf("\n\n請確認(rè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(); }
以上就是關(guān)于“怎么用C語言實現(xiàn)共享單車管理系統(tǒng)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。