?? 11.c
字號:
printf("始發(fā)站:");
printf("%s\n",f3[i]);
printf("終點站:");
printf("%s\n",f4[i]);
printf("行車時間:");
printf("%d\n",e5[i]);
printf("額定載客數(shù):");
printf("%d\n",e6[i]);
printf("已售出票數(shù):");
printf("%d\n",e7[i]);
}
}
fclose(fp);
return1(); /*進入返回函數(shù)*/
}
else if(choicen3=='d') /*返回至售票員系統(tǒng)函數(shù)*/
solder();
else /*防錯處理,若輸入錯誤則返回至查找函數(shù)*/
{
printf("沒有這個選項,請重新選擇");
search();
}
}
void return1()
{
void search();
char j[1];
printf("是否返回上一級菜單( y or n ):");
scanf("%s",&j);
if(strcmp("y",j)==0) /*返回至查找函數(shù)*/
search();
else if(strcmp("n",j)==0) /*退出程序*/
exit(0);
else /*防錯處理,若輸入錯誤則返回至return1函數(shù)*/
{
printf("沒有這個選項,請重新輸入\n");
return1();
}
}
void tickets() /*追加售出車票*/
{
FILE *fp;
void solder();
void return2();
int x,y,i,e1[20],e2[20],e5[20],e6[20],e7[20];
char f3[20][50],f4[20][50];
fp=fopen("c:\\bus.txt","r");
printf("請輸入售出車票的車號:");
scanf("%d",&x);
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("發(fā)車時間:");
printf("%d\n",e2[i]);
printf("始發(fā)站:");
printf("%s\n",f3[i]);
printf("終點站:");
printf("%s\n",f4[i]);
printf("行車時間:");
printf("%d\n",e5[i]);
printf("額定載客數(shù):");
printf("%d\n",e6[i]);
printf("已售出票數(shù):");
printf("%d\n",e7[i]);
fclose(fp);
printf("\n請追加售出的車票數(shù):");
scanf("%d",&y);
if(e7[i]+y<=e6[i]) /*判斷是否超過額定載客數(shù)*/
{
fp=fopen("c:\\bus.txt","w");
e7[i]+=y;
fprintf(fp,"%d %d %s %s %d %d %d",e1[i],e2[i],f3[i],f4[i],e5[i],e6[i],e7[i]);
printf("\n**********車次信息**********\n");
printf("班次:");
printf("%d\n",e1[i]);
printf("發(fā)車時間:");
printf("%d\n",e2[i]);
printf("始發(fā)站:");
printf("%s\n",f3[i]);
printf("終點站:");
printf("%s\n",f4[i]);
printf("行車時間:");
printf("%d\n",e5[i]);
printf("額定載客數(shù):");
printf("%d\n",e6[i]);
printf("已售出票數(shù):");
printf("%d\n",e7[i]);
fclose(fp);
}
else /*若超出額定載客數(shù)則返回至售票函數(shù)*/
{
printf("超出額定載客數(shù),請重新輸入!\n");
tickets();
}
}
}
return2(); /*進入返回函數(shù)*/
}
void return2()
{
void solder();
char j[1];
printf("是否返回上一級菜單( y or n ):");
scanf("%s",&j);
if(strcmp("y",j)==0) /*返回至售票函數(shù)*/
solder();
else if(strcmp("n",j)==0) /*退出程序*/
exit(0);
else /*防錯處理,若輸入錯誤則返回至return2函數(shù)*/
{
printf("沒有這個選項,請重新輸入\n");
return2();
}
}
struct data *a(struct data *head) /*登錄車次信息*/
{
struct data *p1,*p2;
int m=0;
n=0;
p1=(struct data*)malloc(LEN);
p2=(struct data*)malloc(LEN);
p1=p2;
system("cls");
printf("請輸入您要登錄的車次號:");
scanf("%d",&p1->number);
printf("請輸入出發(fā)時間:");
scanf("%d",&p1->time);
printf("請輸入始發(fā)站:");
scanf("%s",p1->strat_position);
printf("請輸入終點站:");
scanf("%s",p1->end_position);
printf("請輸入行駛時間:");
scanf("%d",&p1->long1);
printf("請輸入載客量:");
scanf("%d",&p1->capacity);
printf("請輸入賣出車票數(shù):");
scanf("%d",&p1->sell_ticket);
head=NULL;
while (p1->number!=0)
{
n=n+1;
if(n==1)
head=p1;
else p2->next=p1;
p2=p1;
p1=(struct data*) malloc(LEN);
printf("請輸入您要添加的車次號:");
scanf("%d",&p1->number);
printf("請輸入出發(fā)時間:");
scanf("%d",&p1->time);
printf("請輸入始發(fā)站:");
scanf("%s",p1->strat_position);
printf("請輸入終點站:");
scanf("%s",p1->end_position);
printf("請輸入行駛時間:");
scanf("%d",&p1->long1);
printf("請輸入載客量:");
scanf("%d",&p1->capacity);
printf("請輸入賣出車票數(shù):");
scanf("%d",&p1->sell_ticket);
}
p2->next=NULL;
printf("已成功建立!");
return(head);
}
struct data *insert(struct data *head) /*插入車次信息*/
{
struct data *p0,*p1,*p2;
system("cls");
printf("歡迎來到車次信息添加系統(tǒng)!\n");
printf("請輸入您要添加的車次號:");
scanf("%d",&datas.number);
printf("請輸入出發(fā)時間:");
scanf("%d",&datas.time);
printf("請輸入始發(fā)站:");
scanf("%s",datas.strat_position);
printf("請輸入終點站:");
scanf("%s",datas.end_position);
printf("請輸入行駛時間:");
scanf("%d",&datas.long1);
printf("請輸入載客量:");
scanf("%d",&datas.capacity);
printf("請輸入賣出車票數(shù):");
scanf("%d",&datas.sell_ticket);
p1=head;
p0=&datas;
if
(head==NULL)
{head=p0;
p0->next=NULL;}
else
{
while((p0->number>p1->number)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->number<=p1->number)
{
if (head==p1)head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;p0->next=NULL;
}
}
n=n+1;
printf("已成功插入!");
return (head);
}
struct data *b(struct data *head) /*刪除已登錄的車次信息*/
{
struct data *p3=NULL,*p4=NULL;
int n2;
system("cls");
printf("歡迎來到刪除車次信息系統(tǒng)!\n");
printf("請輸入您要刪除的車次:\n");
scanf("%d",&n2);
if (head==NULL)
printf("錯誤!\n");
p3=head;
while (n2!=p3->number&&p3->next!=NULL)
{
p4=p3;
p3=p3->next;
}
if(n2==p3->number)
{
if(p3==head)
head=p3->next;
else p4->next=p3->next;
printf("已成功刪除:%d 號車次信息!",n2);
n2=n2-1;
}
else printf("沒有找到該車次信息!\n",n2);
return (head);
}
struct data *c(struct data *head) /*更改已登錄的車次信息*/
{
int n3;
system("cls");
printf("歡迎來到更改信息系統(tǒng)!\n");
printf("請輸入您要更改的車次號:\n");
scanf("%d",&n3);
p=head;
while(p!=NULL)
{
if(n3==p->number)
{
printf("請輸入出發(fā)時間:");
scanf("%d",&p->time);
printf("請輸入始發(fā)站:");
scanf("%s",p->strat_position);
printf("請輸入終點站:");
scanf("%s",p->end_position);
printf("請輸入行駛時間:");
scanf("%d",&p->long1);
printf("請輸入載客量:");
scanf("%d",&p->capacity);
printf("請輸入賣出車票數(shù):");
scanf("%d",&p->sell_ticket);
break;
}
p=p->next;
}
printf("已成功更改車次信息!");
return (head);
}
void print(struct data *head)
{
p=head;
system("cls");
if(head!=NULL)
printf("\n******************************車次信息******************************\n");
printf("********************************************************************\n");
do
{
printf("**車號**發(fā)車時間**始發(fā)站**終點站**行車時間**額定載客數(shù)**已售出票數(shù)**\n");
printf("** %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;
}
while(p!=NULL);
printf("********************************************************************\n");
printf("********************************************************************\n");
}
void main ()
{
void mmenu();
mmenu();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -