列車c語言查詢,火車票務系統C語言

本文目錄一覽:

用C語言寫火車訂票系統

#include conio.h

#include stdio.h

#include stdlib.h

#include string.h

int shoudsave=0 ;

int count1=0,count2=0,mark=0,mark1=0 ;

/*定義存儲火車信息的結構體*/

struct train

{

char num[10];/*列車號*/

char city[10];/*目的城市*/

char takeoffTime[10];/*發車時間*/

char receiveTime[10];/*到達時間*/

int price;/*票價*/

int bookNum ;/*票數*/

};

/*訂票人的信息*/

struct man

{

char num[10];/*ID*/

char name[10];/*姓名*/

int bookNum ;/*需求的票數*/

};

/*定義火車信息鏈表的結點結構*/

typedef struct node

{

struct train data ;

struct node * next ;

}Node,*Link ;

/*定義訂票人鏈表的結點結構*/

typedef struct people

{

struct man data ;

struct people*next ;

}bookMan,*bookManLink ;

/* 初始界面*/

void printInterface()

{

puts(“********************************************************”);

puts(“* Welcome to use the system of booking tickets *”);

puts(“********************************************************”);

puts(“* You can choose the operation: *”);

puts(“* 1:Insert a train information *”);

puts(“* 2:Inquire a train information *”);

puts(“* 3:Book a train ticket *”);

puts(“* 4:Update the train information *”);

puts(“* 5:Advice to you about the train *”);

puts(“* 6:save information to file *”);

puts(“* 7:quit the system *”);

puts(“********************************************************”);

}

/*添加一個火車信息*/

void InsertTraininfo(Link linkhead)

{

struct node *p,*r,*s ;

char num[10];

r = linkhead ;

s = linkhead-next ;

while(r-next!=NULL)

r=r-next ;

while(1)

{

printf(“please input the number of the train(0-return)”);

scanf(“%s”,num);

if(strcmp(num,”0″)==0)

break ;

/*判斷是否已經存在*/

while(s)

{

if(strcmp(s-data.num,num)==0)

{

printf(“the train ‘%s’has been born!\n”,num);

return ;

}

s = s-next ;

}

p = (struct node*)malloc(sizeof(struct node));

strcpy(p-data.num,num);

printf(“Input the city where the train will reach:”);

scanf(“%s”,p-data.city);

printf(“Input the time which the train take off:”);

scanf(“%s”,p-data.takeoffTime);

printf(“Input the time which the train receive:”);

scanf(“%s”,p-data.receiveTime);

printf(“Input the price of ticket:”);

scanf(“%d”,p-data.price);

printf(“Input the number of booked tickets:”);

scanf(“%d”,p-data.bookNum);

p-next=NULL ;

r-next=p ;

r=p ;

shoudsave = 1 ;

}

}

/*打印火車票信息*/

void printTrainInfo(struct node*p)

{

puts(“\nThe following is the record you want:”);

printf(“number of train: %s\n”,p-data.num);

printf(“city the train will reach: %s\n”,p-data.city);

printf(“the time the train take off: %s\nthe time the train reach: %s\n”,p-data.takeoffTime,p-data.receiveTime);

printf(“the price of the ticket: %d\n”,p-data.price);

printf(“the number of booked tickets: %d\n”,p-data.bookNum);

}

struct node * Locate1(Link l,char findmess[],char numorcity[])

{

Node*r ;

if(strcmp(numorcity,”num”)==0)

{

r=l-next ;

while(r)

{

if(strcmp(r-data.num,findmess)==0)

return r ;

r=r-next ;

}

}

else if(strcmp(numorcity,”city”)==0)

{

r=l-next ;

while(r)

{

if(strcmp(r-data.city,findmess)==0)

return r ;

r=r-next ;

}

}

return 0 ;

}

/*查詢火車信息*/

void QueryTrain(Link l)

{

Node *p ;

int sel ;

char str1[5],str2[10];

if(!l-next)

{

printf(“There is not any record !”);

return ;

}

printf(“Choose the way:\n1:according to the number of train;\n2:according to the city:\n”);

scanf(“%d”,sel);

if(sel==1)

{

printf(“Input the the number of train:”);

scanf(“%s”,str1);

p=Locate1(l,str1,”num”);

if(p)

{

printTrainInfo(p);

}

else

{

mark1=1 ;

printf(“\nthe file can’t be found!”);

}

}

else if(sel==2)

{

printf(“Input the city:”);

scanf(“%s”,str2);

p=Locate1(l,str2,”city”);

if(p)

{

printTrainInfo(p);

}

else

{

mark1=1 ;

printf(“\nthe file can’t be found!”);

}

}

}

/*訂票子模塊*/

void BookTicket(Link l,bookManLink k)

{

Node*r[10],*p ;

char ch,dem ;

bookMan*v,*h ;

int i=0,t=0 ;

char str[10],str1[10],str2[10];

v=k ;

while(v-next!=NULL)

v=v-next ;

printf(“Input the city you want to go: “);

scanf(“%s”,str);

p=l-next ;

while(p!=NULL)

{

if(strcmp(p-data.city,str)==0)

{

r[i]=p ;

i++;

}

p=p-next ;

}

printf(“\n\nthe number of record have %d\n”,i);

for(t=0;ti;t++)

printTrainInfo(r[t]);

if(i==0)

printf(“\n\t\t\tSorry!Can’t find the train for you!\n”);

else

{

printf(“\ndo you want to book it?1/0\n”);

scanf(“%d”,ch);

if(ch == 1)

{

h=(bookMan*)malloc(sizeof(bookMan));

printf(“Input your name: “);

scanf(“%s”,str1);

strcpy(h-data.name,str1);

printf(“Input your id: “);

scanf(“%s”,str2);

strcpy(h-data.num,str2);

printf(“Input your bookNum: “);

scanf(“%d”,dem);

h-data.bookNum=dem ;

h-next=NULL ;

v-next=h ;

v=h ;

printf(“\nLucky!you have booked a ticket!”);

getch();

shoudsave=1 ;

}

}

}

bookMan*Locate2(bookManLink k,char findmess[])

{

bookMan*r ;

r=k-next ;

while(r)

{

if(strcmp(r-data.num,findmess)==0)

{

mark=1 ;

return r ;

}

r=r-next ;

}

return 0 ;

}

/*修改火車信息*/

void UpdateInfo(Link l)

{

Node*p ;

char findmess[20],ch ;

if(!l-next)

{

printf(“\nthere isn’t record for you to modify!\n”);

return ;

}

else

{

QueryTrain(l);

if(mark1==0)

{

printf(“\nDo you want to modify it?\n”);

getchar();

scanf(“%c”,ch);

if(ch==’y’);

{

printf(“\nInput the number of the train:”);

scanf(“%s”,findmess);

p=Locate1(l,findmess,”num”);

if(p)

{

printf(“Input new number of train:”);

scanf(“%s”,p-data.num);

printf(“Input new city the train will reach:”);

scanf(“%s”,p-data.city);

printf(“Input new time the train take off”);

scanf(“%s”,p-data.takeoffTime);

printf(“Input new time the train reach:”);

scanf(“%s”,p-data.receiveTime);

printf(“Input new price of the ticket::”);

scanf(“%d”,p-data.price);

printf(“Input new number of people who have booked ticket:”);

scanf(“%d”,p-data.bookNum);

printf(“\nmodifying record is sucessful!\n”);

shoudsave=1 ;

}

else

printf(“\t\t\tcan’t find the record!”);

}

}

else

mark1=0 ;

}

}

/*系統給用戶的提示信息*/

void AdvicedTrains(Link l)

{

Node*r ;

char str[10];

int mar=0 ;

r=l-next ;

printf(“Iuput the city you want to go: “);

scanf(“%s”,str);

while(r)

{

if(strcmp(r-data.city,str)==0r-data.bookNum200)

{

mar=1 ;

printf(“\nyou can select the following train!\n”);

printf(“\n\nplease select the fourth operation to book the ticket!\n”);

printTrainInfo(r);

}

r=r-next ;

}

if(mar==0)

printf(“\n\t\t\tyou can’t book any ticket now!\n”);

}

/*保存火車信息*/

void SaveTrainInfo(Link l)

{

FILE*fp ;

Node*p ;

int count=0,flag=1 ;

fp=fopen(“c:\\train.txt”,”wb”);

if(fp==NULL)

{

printf(“the file can’t be opened!”);

return ;

}

p=l-next ;

while(p)

{

if(fwrite(p,sizeof(Node),1,fp)==1)

{

p=p-next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf(“the number of the record which have been saved is %d\n”,count);

shoudsave=0 ;

}

fclose(fp);

}

/*保存訂票人的信息*/

void SaveBookmanInfo(bookManLink k)

{

FILE*fp ;

bookMan*p ;

int count=0,flag=1 ;

fp=fopen(“c:\\man.txt”,”wb”);

if(fp==NULL)

{

printf(“the file can’t be opened!”);

return ;

}

p=k-next ;

while(p)

{

if(fwrite(p,sizeof(bookMan),1,fp)==1)

{

p=p-next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf(“the number of the record which have been saved is %d\n”,count);

shoudsave=0 ;

}

fclose(fp);

}

int main()

{

FILE*fp1,*fp2 ;

Node*p,*r ;

char ch1,ch2 ;

Link l ;

bookManLink k ;

bookMan*t,*h ;

int sel ;

l=(Node*)malloc(sizeof(Node));

l-next=NULL ;

r=l ;

k=(bookMan*)malloc(sizeof(bookMan));

k-next=NULL ;

h=k ;

fp1=fopen(“c:\\train.txt”,”ab+”);

if((fp1==NULL))

{

printf(“can’t open the file!”);

return 0 ;

}

while(!feof(fp1))

{

p=(Node*)malloc(sizeof(Node));

if(fread(p,sizeof(Node),1,fp1)==1)

{

p-next=NULL ;

r-next=p ;

r=p ;

count1++;

}

}

fclose(fp1);

fp2=fopen(“c:\\man.txt”,”ab+”);

if((fp2==NULL))

{

printf(“can’t open the file!”);

return 0 ;

}

while(!feof(fp2))

{

t=(bookMan*)malloc(sizeof(bookMan));

if(fread(t,sizeof(bookMan),1,fp2)==1)

{

t-next=NULL ;

h-next=t ;

h=t ;

count2++;

}

}

fclose(fp2);

while(1)

{

system(“cls”);

printInterface();

printf(“please choose the operation: “);

scanf(“%d”,sel);

system(“cls”);

if(sel==8)

{

if(shoudsave==1)

{

getchar();

printf(“\nthe file have been changed!do you want to save it(y/n)?\n”);

scanf(“%c”,ch1);

if(ch1==’y’||ch1==’Y’)

{

SaveBookmanInfo(k);

SaveTrainInfo(l);

}

}

printf(“\nThank you!!You are welcome too\n”);

break ;

}

switch(sel)

{

case 1 :

InsertTraininfo(l);break ;

case 2 :

QueryTrain(l);break ;

case 3 :

BookTicket(l,k);break ;

case 4 :

UpdateInfo(l);break ;

case 5 :

AdvicedTrains(l);break ;

case 6 :

SaveTrainInfo(l);SaveBookmanInfo(k);break ;

case 7 :

return 0;

}

printf(“\nplease press any key to continue…….”);

getch();

}

return 0;

}

高分求:C語言的和鐵路有關的程序(越簡單越好)

下面是一個火車票的程序,希望能幫到你

#include conio.h

#include stdio.h

#include stdlib.h

#include string.h

int shoudsave=0 ;

int count1=0,count2=0,mark=0,mark1=0 ;

/*定義存儲火車信息的結構體*/

struct train

{

char num[10];/*列車號*/

char city[10];/*目的城市*/

char takeoffTime[10];/*發車時間*/

char receiveTime[10];/*到達時間*/

int price;/*票價*/

int bookNum ;/*票數*/

};

/*訂票人的信息*/

struct man

{

char num[10];/*ID*/

char name[10];/*姓名*/

int bookNum ;/*需求的票數*/

};

/*定義火車信息鏈表的結點結構*/

typedef struct node

{

struct train data ;

struct node * next ;

}Node,*Link ;

/*定義訂票人鏈表的結點結構*/

typedef struct people

{

struct man data ;

struct people*next ;

}bookMan,*bookManLink ;

/* 初始界面*/

void printInterface()

{

puts(“********************************************************”);

puts(“* Welcome to use the system of booking tickets *”);

puts(“********************************************************”);

puts(“* You can choose the operation: *”);

puts(“* 1:Insert a train information *”);

puts(“* 2:Inquire a train information *”);

puts(“* 3:Book a train ticket *”);

puts(“* 4:Update the train information *”);

puts(“* 5:Advice to you about the train *”);

puts(“* 6:save information to file *”);

puts(“* 7:quit the system *”);

puts(“********************************************************”);

}

/*添加一個火車信息*/

void InsertTraininfo(Link linkhead)

{

struct node *p,*r,*s ;

char num[10];

r = linkhead ;

s = linkhead-next ;

while(r-next!=NULL)

r=r-next ;

while(1)

{

printf(“please input the number of the train(0-return)”);

scanf(“%s”,num);

if(strcmp(num,”0″)==0)

break ;

/*判斷是否已經存在*/

while(s)

{

if(strcmp(s-data.num,num)==0)

{

printf(“the train ‘%s’has been born!\n”,num);

return ;

}

s = s-next ;

}

p = (struct node*)malloc(sizeof(struct node));

strcpy(p-data.num,num);

printf(“Input the city where the train will reach:”);

scanf(“%s”,p-data.city);

printf(“Input the time which the train take off:”);

scanf(“%s”,p-data.takeoffTime);

printf(“Input the time which the train receive:”);

scanf(“%s”,p-data.receiveTime);

printf(“Input the price of ticket:”);

scanf(“%d”,p-data.price);

printf(“Input the number of booked tickets:”);

scanf(“%d”,p-data.bookNum);

p-next=NULL ;

r-next=p ;

r=p ;

shoudsave = 1 ;

}

}

/*打印火車票信息*/

void printTrainInfo(struct node*p)

{

puts(“\nThe following is the record you want:”);

printf(“number of train: %s\n”,p-data.num);

printf(“city the train will reach: %s\n”,p-data.city);

printf(“the time the train take off: %s\nthe time the train reach: %s\n”,p-data.takeoffTime,p-data.receiveTime);

printf(“the price of the ticket: %d\n”,p-data.price);

printf(“the number of booked tickets: %d\n”,p-data.bookNum);

}

struct node * Locate1(Link l,char findmess[],char numorcity[])

{

Node*r ;

if(strcmp(numorcity,”num”)==0)

{

r=l-next ;

while(r)

{

if(strcmp(r-data.num,findmess)==0)

return r ;

r=r-next ;

}

}

else if(strcmp(numorcity,”city”)==0)

{

r=l-next ;

while(r)

{

if(strcmp(r-data.city,findmess)==0)

return r ;

r=r-next ;

}

}

return 0 ;

}

/*查詢火車信息*/

void QueryTrain(Link l)

{

Node *p ;

int sel ;

char str1[5],str2[10];

if(!l-next)

{

printf(“There is not any record !”);

return ;

}

printf(“Choose the way:\n1:according to the number of train;\n2:according to the city:\n”);

scanf(“%d”,sel);

if(sel==1)

{

printf(“Input the the number of train:”);

scanf(“%s”,str1);

p=Locate1(l,str1,”num”);

if(p)

{

printTrainInfo(p);

}

else

{

mark1=1 ;

printf(“\nthe file can’t be found!”);

}

}

else if(sel==2)

{

printf(“Input the city:”);

scanf(“%s”,str2);

p=Locate1(l,str2,”city”);

if(p)

{

printTrainInfo(p);

}

else

{

mark1=1 ;

printf(“\nthe file can’t be found!”);

}

}

}

/*訂票子模塊*/

void BookTicket(Link l,bookManLink k)

{

Node*r[10],*p ;

char ch,dem ;

bookMan*v,*h ;

int i=0,t=0 ;

char str[10],str1[10],str2[10];

v=k ;

while(v-next!=NULL)

v=v-next ;

printf(“Input the city you want to go: “);

scanf(“%s”,str);

p=l-next ;

while(p!=NULL)

{

if(strcmp(p-data.city,str)==0)

{

r[i]=p ;

i++;

}

p=p-next ;

}

printf(“\n\nthe number of record have %d\n”,i);

for(t=0;ti;t++)

printTrainInfo(r[t]);

if(i==0)

printf(“\n\t\t\tSorry!Can’t find the train for you!\n”);

else

{

printf(“\ndo you want to book it?1/0\n”);

scanf(“%d”,ch);

if(ch == 1)

{

h=(bookMan*)malloc(sizeof(bookMan));

printf(“Input your name: “);

scanf(“%s”,str1);

strcpy(h-data.name,str1);

printf(“Input your id: “);

scanf(“%s”,str2);

strcpy(h-data.num,str2);

printf(“Input your bookNum: “);

scanf(“%d”,dem);

h-data.bookNum=dem ;

h-next=NULL ;

v-next=h ;

v=h ;

printf(“\nLucky!you have booked a ticket!”);

getch();

shoudsave=1 ;

}

}

}

bookMan*Locate2(bookManLink k,char findmess[])

{

bookMan*r ;

r=k-next ;

while(r)

{

if(strcmp(r-data.num,findmess)==0)

{

mark=1 ;

return r ;

}

r=r-next ;

}

return 0 ;

}

/*修改火車信息*/

void UpdateInfo(Link l)

{

Node*p ;

char findmess[20],ch ;

if(!l-next)

{

printf(“\nthere isn’t record for you to modify!\n”);

return ;

}

else

{

QueryTrain(l);

if(mark1==0)

{

printf(“\nDo you want to modify it?\n”);

getchar();

scanf(“%c”,ch);

if(ch==’y’);

{

printf(“\nInput the number of the train:”);

scanf(“%s”,findmess);

p=Locate1(l,findmess,”num”);

if(p)

{

printf(“Input new number of train:”);

scanf(“%s”,p-data.num);

printf(“Input new city the train will reach:”);

scanf(“%s”,p-data.city);

printf(“Input new time the train take off”);

scanf(“%s”,p-data.takeoffTime);

printf(“Input new time the train reach:”);

scanf(“%s”,p-data.receiveTime);

printf(“Input new price of the ticket::”);

scanf(“%d”,p-data.price);

printf(“Input new number of people who have booked ticket:”);

scanf(“%d”,p-data.bookNum);

printf(“\nmodifying record is sucessful!\n”);

shoudsave=1 ;

}

else

printf(“\t\t\tcan’t find the record!”);

}

}

else

mark1=0 ;

}

}

/*系統給用戶的提示信息*/

void AdvicedTrains(Link l)

{

Node*r ;

char str[10];

int mar=0 ;

r=l-next ;

printf(“Iuput the city you want to go: “);

scanf(“%s”,str);

while(r)

{

if(strcmp(r-data.city,str)==0r-data.bookNum200)

{

mar=1 ;

printf(“\nyou can select the following train!\n”);

printf(“\n\nplease select the fourth operation to book the ticket!\n”);

printTrainInfo(r);

}

r=r-next ;

}

if(mar==0)

printf(“\n\t\t\tyou can’t book any ticket now!\n”);

}

/*保存火車信息*/

void SaveTrainInfo(Link l)

{

FILE*fp ;

Node*p ;

int count=0,flag=1 ;

fp=fopen(“c:\\train.txt”,”wb”);

if(fp==NULL)

{

printf(“the file can’t be opened!”);

return ;

}

p=l-next ;

while(p)

{

if(fwrite(p,sizeof(Node),1,fp)==1)

{

p=p-next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf(“the number of the record which have been saved is %d\n”,count);

shoudsave=0 ;

}

fclose(fp);

}

/*保存訂票人的信息*/

void SaveBookmanInfo(bookManLink k)

{

FILE*fp ;

bookMan*p ;

int count=0,flag=1 ;

fp=fopen(“c:\\man.txt”,”wb”);

if(fp==NULL)

{

printf(“the file can’t be opened!”);

return ;

}

p=k-next ;

while(p)

{

if(fwrite(p,sizeof(bookMan),1,fp)==1)

{

p=p-next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf(“the number of the record which have been saved is %d\n”,count);

shoudsave=0 ;

}

fclose(fp);

}

int main()

{

FILE*fp1,*fp2 ;

Node*p,*r ;

char ch1,ch2 ;

Link l ;

bookManLink k ;

bookMan*t,*h ;

int sel ;

l=(Node*)malloc(sizeof(Node));

l-next=NULL ;

r=l ;

k=(bookMan*)malloc(sizeof(bookMan));

k-next=NULL ;

h=k ;

fp1=fopen(“c:\\train.txt”,”ab+”);

if((fp1==NULL))

{

printf(“can’t open the file!”);

return 0 ;

}

while(!feof(fp1))

{

p=(Node*)malloc(sizeof(Node));

if(fread(p,sizeof(Node),1,fp1)==1)

{

p-next=NULL ;

r-next=p ;

r=p ;

count1++;

}

}

fclose(fp1);

fp2=fopen(“c:\\man.txt”,”ab+”);

if((fp2==NULL))

{

printf(“can’t open the file!”);

return 0 ;

}

while(!feof(fp2))

{

t=(bookMan*)malloc(sizeof(bookMan));

if(fread(t,sizeof(bookMan),1,fp2)==1)

{

t-next=NULL ;

h-next=t ;

h=t ;

count2++;

}

}

fclose(fp2);

while(1)

{

clrscr();

printInterface();

printf(“please choose the operation: “);

scanf(“%d”,sel);

clrscr();

if(sel==8)

{

if(shoudsave==1)

{

getchar();

printf(“\nthe file have been changed!do you want to save it(y/n)?\n”);

scanf(“%c”,ch1);

if(ch1==’y’||ch1==’Y’)

{

SaveBookmanInfo(k);

SaveTrainInfo(l);

}

}

printf(“\nThank you!!You are welcome too\n”);

break ;

}

switch(sel)

{

case 1 :

InsertTraininfo(l);break ;

case 2 :

QueryTrain(l);break ;

case 3 :

BookTicket(l,k);break ;

case 4 :

UpdateInfo(l);break ;

case 5 :

AdvicedTrains(l);break ;

case 6 :

SaveTrainInfo(l);SaveBookmanInfo(k);break ;

case 7 :

return 0;

}

printf(“\nplease press any key to continue…….”);

getch();

}

return 0;

}

用C語言寫一個模擬火車票管理系統。

#includestdio.h

#includestring.h

#includestdlib.h

#includetime.h

#includeconio.h

#define N 1000

typedef struct TICKET

{

char num[10];

char hour[3];

char min[3];

char from[10];

char to[10];

float hours;

int max;

int now;

}CLASS;

int class_num=0;

CLASS records[N];

int system_time();

void NewMessage();

void ShowTable1();

void ShowTable2(int i);

void Display();

void add();

void save();

void load();

void search();

void change();

void quit();

void Ticketorder();

void Ticketdelete();

int menu_select();

int whether(int);

void find(char s1[],char s2[]);

void deletemessage();

int findnum(char s1[]);

void get(int,int);

char *menu[]={“*****************歡迎使用車票管理系統*****************”,

“\n*******************MENU功能菜單***********************”,

“\n 1. 錄入班次 “,

“\n 2. 顯示所有班次 “,

“\n 3. 查詢班次 “,

“\n 4. 增加班次 “,

“\n 5. 售票 “,

“\n 6. 退票 “,

“\n 7. 修改班次 “,

“\n 8. 刪除班次 “,

“\n 9. 退出 “};

/**主函數**/

void main()

{

system(“cls”);

while(1)

{

switch(menu_select())

{

case 1: NewMessage();break;

case 2: Display();break;

case 3: search();break;

case 4: add();break;

case 5: Ticketorder();break;

case 6: Ticketdelete();break;

case 7: change();break;

case 8: deletemessage();break;

case 9: quit();break;

}

}

}

/**菜單函數**/

int menu_select()

{

char s[5];

int c,i;

system(“cls”);

for(i=0;i11;i++)

{

printf(“%s”,menu[i])) ;

}

i=0;

printf(“\n”);

printf(“******************************************************”);

printf(“\n請選擇(1-9):”);

scanf(“%s”,s);

c=atoi(s);

while(i0||i9)

{

printf(“\n”);

printf(“******************************************************”);

printf(“\n請選擇(1-9):”);

scanf(“%s”,s);

c=atoi(s);

}

return c;

}

void NewMessage()

{

int i=0,j=5,h;

char s[5];

FILE *fp;

system(“cls”);

if((fp=fopen(“d:number.dat”,”rb”))!=NULL)

{

printf(“車票信息已經存在請選擇增加功能!\n”);

printf(“任意輸入則返回菜單\n”);

scanf(“%s”,s);

i=1; //通過是1

}

if(i==0)

{

system(“cls”);

printf(“請輸入要錄入班次總數:\n”);

scanf(“%d”,class_num);

system(“cls”);

for(i=0;iclass_num;i++)

{

system(“cls”);

printf(“請輸入第%d個班次信息:\n”,i+1);

h=-1;

for(;h!=i;)

{

printf(“請輸入班次:”);

scanf(“%s”,records[i].num);

for(h=0;hi;h++)

if(strcmp(records[h].num,records[i].num)==0)

//判斷字符串比較是否相等,, 待比較的字符串

{

printf(“輸入錯誤!該班次已存在!\n”);

break;

}

}

get(i,j);

j=5;

}

save();

}

}

void Display() //顯示所有函數

{

int i,j;

system(“cls”); //刷屏

load(); // 調用按班次查詢函數

ShowTable1(); //線框調用1,,,不用每次輸

for(i=0,j=0;iclass_num;i++,j+=2) /////按班次順序輸出

{

printf(“\n|———-|———-|———-|———-|——–|——–|——–|\n”);

if(whether(i))

printf(“|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,records[i].hour,

records[i].min, records[i].from,records[i].to,records[i].hours,

records[i].max,records[i].now);

else

printf(“|%10s| 已發車 |%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,

records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);

}

ShowTable2(j); //線框調用2

printf(“\n按任意鍵繼續….\n”);

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

}

/**打印表頭**/

void ShowTable1()

{

int i=2;

system(“cls”);

printf(“**************************車票信息系統**********************************\n”);

printf(“\n|———-|———-|———-|———-|——–|——–|——–|\n”);

printf(“\n| 班次 | 發車時間 | 起點站 | 終點站 |行車時間|額定載量| 已售票 |\n”);

}

void ShowTable2(int i)

{

printf(“\n|———-|———-|———-|———-|——–|——–|——–|\n”);

}

void search()

{

int i;

char s1[10]={‘\0’},s2[10]={‘\0’};

system(“cls”);

printf(“1. 按班次查詢\n”)

printf(“2. 按終點站查詢\n”);

printf(“3. 退出\n”);

printf(“請選擇(1-3):\n”);

scanf(“%d”,i);

load();

switch(i)

{

case 1: printf(“請輸入要查詢的班次:”);

scanf(“%s”,s1);

find(s1,s2);

break;

case 2: printf(“請輸入要查詢終點站:”);

scanf(“%s”,s2);

find(s1,s2);

break;

case 3: break;

default : printf(“輸入錯誤!\n”);

break;

}

printf(“按任意鍵繼續….\n”);

getch();

}

void find(char s1[],char s2[])

{

int i,h=0,m;

ShowTable1();

if(s2[0]==’\0′)

m=1;

else m=0;

for(i=0;iclass_num;i++)

if(strcmp(s1,records[i].num)==0||strcmp(s2,records[i].to)==0)

{

printf(“\n|———-|———-|———-|———-|——–|——–|——–|\n”);

printf(“|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,records[i].hour,records[i].min,

records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);

h+=1;

if(m==1)

break;

}

ShowTable2(h);

if(h==0)

printf(“要查找的班次不存在!\n”);

}

/**增加函數**/

void add()

{

int i,j=5;

load();

system(“cls”);

printf(“1. 增加班次”);

printf(“2. 返回\n”);

printf(“請選擇(1-2)\n”);

scanf(“%d”,i);

if(i==1)

{

system(“cls”); //刷屏

printf(“1. 請輸入要增加的班次:”);

scanf(“%s”,records[class_num].num);

for(i=0;iclass_num;i++)

if(strcmp(records[class_num].num,records[i].num)==0)

//判斷字符串比較是否相等,待比較的字符串,判斷車次沒重複

{

printf(“輸入錯誤!\n”);

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

break;

}

if(i==class_num)

{

get(i,j); ////修改及增加班次*

class_num++; ///使班次數加1

save(); //調用保存函數

}

}

}

/**售票函數**/

void Ticketorder() //*售票函數

{

int i;

char num[10];

system(“cls”); //刷屏

printf(“1. 售票\n”);

printf(“2. 返回\n”);

printf(“請選擇(1-2):\n”);

scanf(“%d”,i);

if(i==1)

{

load(); // 加載函數

search(); //查找函數

printf(“請輸入要訂票的班次(若無請輸入0):”);

scanf(“%s”,num);

for(i=0;iclass_num;i++)

if(strcmp(num,records[i].num)==0)//判斷字符串比較是否相等,, 待比較的字符串

if(records[i].maxrecords[i].nowwhether(i)==1)

//判斷時間是否超出函數並且沒超出最大客量

{

records[i].now++; ///使已售票加1

printf(“通向%s班次為%s的票訂票成功!\n”,records[i].to,records[i].num);

save(); //調用保存函數

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

break;

}

else

{

printf(“該班次已滿或已發出!\n”);

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

}

}

}

/**退票函數**/

void Ticketdelete() //刪除函數*

{

int i;

char num[10];

system(“cls”); //刷屏

printf(“1. 退票\n”);

printf(“2. 返回\n”);

printf(“請選擇(1-2)\n:”);

scanf(“%d”,i);

if(i==1)

{

system(“cls”); //刷屏

load(); // 調用按班次查詢函數

printf(“請輸入要退票的班次:\n”);

scanf(“%s”,num);

i=findnum(num); //調用班次查詢函數

if(strcmp(num,records[i].num)==0) //判斷字符串比較是否相等 待比較的字符串

if(whether(i)) //判斷時間是否超出函數***

{

printf(“確定(Y/N)?”);

scanf(“%s”,num);

if(num[0]==’y’||num[0]==’Y’)

{

records[i].now–; //使已售票減1

printf(“退票成功!\n”);

save(); //調用保存函數

getch(); //從控制台讀取一個字符,但不顯示在屏幕上

}

}

else

{

printf(“該班車已發出,無法退票!\n”);

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

}

if(i==class_num)

{ printf(“輸入錯誤!\n”);

getch(); /////從控制台讀取一個字符,但不顯示在屏幕上

}

}

}

字數超了。。。。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/304812.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2025-01-01 11:06
下一篇 2025-01-01 11:06

相關推薦

  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論