?? 11.c
字號:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
#define LEN 50
int n,m;
char choicen1,choicen2,choicen3;
struct data /*利用結構體數組臨時儲存車輛信息*/
{
int number;
int time;
char strat_position[50];
char end_position[50];
int long1;
int capacity;
int sell_ticket;
struct data *next;
}*head,datas,*p;
void mmenu()
{
void judge1(int y,char x[5]);
void judge2(int y,char x[5]);
int d;
char f,e[5];
system("cls"); /*清屏*/
printf("\n******歡迎來到汽車票管理系統******\n"); /*登陸界面*/
printf("**********************************\n");
printf("** **\n");
printf("** 1.管理員登陸 **\n");
printf("** 2.售票員登陸 **\n");
printf("** 3.退出 **\n");
printf("** **\n");
printf("**********************************\n");
printf("**********************************\n");
printf("請選擇:");
scanf("%c",&f); /*根據提示輸入f值,判斷進入子菜單。*/
if(f=='1') /*進入管理員登錄的密碼保護系統*/
{
printf("\n請輸入您的帳號:");
scanf("%s",e);
printf("請輸入您的密碼:");
scanf("%d",&d);
judge1(d,e);
}
else if(f=='2') /*進入售票員登錄的密碼保護系統*/
{
printf("\n請輸入您的帳號:");
scanf("%s",e);
printf("請輸入您的密碼:");
scanf("%d",&d);
judge2(d,e);
}
else if(f=='3') exit(0); /*退出*/
else /*防錯處理,若輸入錯誤則返回至mmenu()函數*/
{
printf("沒有這個選項,請重新選擇");
mmenu();
}
}
void judge1(int y,char x[5]) /*確定是否登錄正確*/
{
void manager();
int d;
char e[5];
if(y==131&&strcmp(x,"sj")==0) /*若登錄信息正確則進入管理員界面*/
manager();
else /*若登錄信息不正確則返回judge1函數重新輸入*/
{
fflush stdin; /*由于會出現帳號與密碼在同一行出現的bug,所以清內存解決*/
printf("您輸入的帳號或密碼貌似有誤~好好想想,再試試?");
printf("\n請輸入您的帳號:");
scanf("%s",&e);
fflush stdin;
printf("請輸入您的密碼:");
scanf("%d",&d);
fflush stdin;
judge1(d,e);
}
}
void manager()
{
char choicen=0;
void mmenu();
void print(struct data *head);
char menu();
FILE *fp;
struct data *a();
struct data *b(struct data *head);
struct data *c(struct data *head);
struct data *insert(struct data *head);
while(choicen!='F')
{
choicen=menu();
if (choicen=='A')
head=a(head);
else if(choicen=='B')
head=b(head);
else if (choicen=='C')
head=c(head);
else if (choicen=='D')
head=insert(head);
else if (choicen=='E')
print(head);
}
fp=fopen("c:\\bus.txt","w");
p=head;
printf("信息:\n");
if(head!=NULL)
do
{
fprintf(fp,"%d %d %s %s %d %d %d\n",p->number,p->time,p->strat_position,p->end_position,p->long1,p->capacity,p->sell_ticket);
p=p->next;
m++;
}
while(p!=NULL);
fclose(fp);
mmenu();
}
void judge2(int y,char x[5]) /*確定登陸是否正確*/
{
void solder();
int d;
char e[5];
if(y==181&&strcmp(x,"xbf")==0) /*若登錄信息正確則進入售票員界面*/
solder();
else /*若登錄信息不正確則返回judge2函數重新輸入*/
{
fflush stdin;
printf("您輸入的帳號或密碼貌似有誤~好好想想,再試試?");
printf("\n請輸入您的帳號:");
scanf("%s",e);
fflush stdin;
printf("請輸入您的密碼:");
scanf("%d",&d);
judge2(d,e);
fflush stdin;
}
}
void solder()
{
void mmenu();
void search();
void tickets();
char menu2();
choicen2=menu2(); /*將menu2()值賦給choicen2*/
if (choicen2=='A') /*進入查詢系統函數*/
search();
else if(choicen2=='B') /*進入售票系統函數*/
tickets();
else if(choicen2=='C') /*返回主菜單函數*/
mmenu();
else /*防錯處理,若輸入錯誤則返回至售票員系統函數*/
{
printf("沒有這個選項,請重新選擇");
solder();
}
}
char menu()
{
printf("\n*******歡迎來到車次管理中心*******\n"); /*子菜單*/
printf("**********************************\n");
printf("** **\n");
printf("** A---登錄車次信息 **\n");
printf("** B---刪除車次信息 **\n");
printf("** C---更改車次信息 **\n");
printf("** D---添加車次信息 **\n");
printf("** E---顯示車次信息 **\n");
printf("** F---返回主菜單 **\n");
printf("** **\n");
printf("**********************************\n");
printf("**********************************\n");
printf("請選擇:");
fflush stdin;
scanf("%c",&choicen1);
return (choicen1);
}
char menu2()
{
system("cls");
printf("\n*********歡迎來到售票中心*********\n"); /*售票中心子菜單*/
printf("**********************************\n");
printf("** **\n");
printf("** A---線路查詢 **\n");
printf("** B---售出車票 **\n");
printf("** C---返回主菜單 **\n");
printf("** **\n");
printf("**********************************\n");
printf("**********************************\n");
printf("請選擇:");
fflush stdin;
scanf("%s",&choicen2);
return(choicen2);
}
char smenu()
{
system("cls");
printf("\n*******歡迎來到線路查詢中心*******\n"); /*線路查詢子菜單*/
printf("**********************************\n");
printf("** **\n");
printf("** a---按車號查詢 **\n");
printf("** b---按始發站查詢 **\n");
printf("** c---按終點站查詢 **\n");
printf("** d---返回上級菜單 **\n");
printf("** **\n");
printf("**********************************\n");
printf("**********************************\n");
printf("請選擇:");
scanf("%s",&choicen3);
return(choicen3);
}
void search() /*查找車次信息*/
{
char smenu();
char menu2();
void solder();
void return1();
FILE *fp;
int x,i,e1[20],e2[20],e5[20],e6[20],e7[20];
char y[50],y0[50],f3[20][50],f4[20][50];
choicen3=smenu();
if (choicen3=='a') /*通過車號查找*/
{
printf("\n請輸入車號:");
scanf("%d",&x);
fp=fopen("c:\\bus.txt","r");
printf("\n**********車次信息**********\n");
for(i=0;i<m+1;i++)
{
fscanf(fp,"%d %d %s %s %d %d %d",&e1[i],&e2[i],&f3[i],&f4[i],&e5[i],&e6[i],&e7[i]); /*從文件讀入車次信息*/
if (x==e1[i])
{ /*若查找到則輸出相應車次信息*/
printf("班次:");
printf("%d\n",e1[i]);
printf("發車時間:");
printf("%d\n",e2[i]);
printf("始發站:");
printf("%s\n",f3[i]);
printf("終點站:");
printf("%s\n",f4[i]);
printf("行車時間:");
printf("%d\n",e5[i]);
printf("額定載客數:");
printf("%d\n",e6[i]);
printf("已售出票數:");
printf("%d\n",e7[i]);
}
}
fclose(fp);
return1();
}
else if(choicen3=='b') /*通過始發站查找*/
{
printf("\n請輸入始發站:");
scanf("%s",&y0);
fp=fopen("c:\\bus.txt","r");
printf("\n**********車次信息**********\n");
for(i=0;i<m+1;i++)
{
fscanf(fp,"%d %d %s %s %d %d %d",&e1[i],&e2[i],&f3[i],&f4[i],&e5[i],&e6[i],&e7[i]);
if (strcmp(y0,f3[i])==0)
{
printf("班次:");
printf("%d\n",e1[i]);
printf("發車時間:");
printf("%d\n",e2[i]);
printf("始發站:");
printf("%s\n",f3[i]);
printf("終點站:");
printf("%s\n",f4[i]);
printf("行車時間:");
printf("%d\n",e5[i]);
printf("額定載客數:");
printf("%d\n",e6[i]);
printf("已售出票數:");
printf("%d\n",e7[i]);
}
}
fclose(fp);
return1();
}
else if(choicen3=='c') /*通過終點站查找*/
{
printf("\n請輸入終點站:");
scanf("%s",&y);
fp=fopen("c:\\bus.txt","r");
printf("\n**********車次信息**********\n");
for(i=0;i<m+1;i++)
{
fscanf(fp,"%d %d %s %s %d %d %d",&e1[i],&e2[i],&f3[i],&f4[i],&e5[i],&e6[i],&e7[i]);
if (strcmp(y,f4[i])==0)
{
printf("班次:");
printf("%d\n",e1[i]);
printf("發車時間:");
printf("%d\n",e2[i]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -