發新話題

[問題] 定機位系統如何修改

定機位系統如何修改

(航空訂位系統)某家小型的航空公司新買了一部新電腦  
來負責新的自動訂位系統  
總經理要求你寫新的程式系統  
你必須寫出一個程式為機場中的
一架飛機來安排座位(容量:10個座位)

你的程式應顯示出下列選單以供選擇:
please type 1 for "first class"
Please type 2 for "economy"

如果鍵入1
你的程式應為他安排頭等艙的座位(座位1-5)
如果鍵入2
你的程式應為他安排經濟艙的座位(座位6-10)
然後你的程式應該印出機票
上面註明此位旅客的座位號碼
以及位於頭等艙或是經濟艙

請使用一個一維陣列來表示飛機的座位表
開始時將這個陣列的所有元素的初始值均設成零
表示所有座位都是空的
每劃一個機位後
便將相對應的陣列元素設為1
表示這個座位已訂走了

當然
你的程式不能允許重複劃位
當頭等艙客滿時
應詢問旅客是否可以改劃經濟艙(反之亦然)
如果回答是的話
便幫他劃一個位置
否則
即印出訊息Next flight leaves in 3 hours.


這是我自己寫的但是寫一寫不知道如何修改  有高手能幫幫修改嗎

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int t, u, i, a[10], s;

for(t=0; t<10; t )
a[t]=0;
while(1)
{
s=0;
u=0;
printf("please type 1 for first class\n");
printf("please type 2 for economy\n");
printf("pleast type 3 for exit program");
scanf("%d",&i);

if(i==1)
{
for(t=0; t<5; t )
if(a[t]==0)
{
a[t]=1;
printf("Your site is No.%d.\n",t 1);
printf("it's first class.\n");
printf("Thank you.\n");
s=1;
break;
}
if(s==1) continue;
printf("All site in first class has been sold.\n");
printf("Would you want to buy site in economy?\n");
printf("type 1 for yes, type 2 for no.");
scanf("%d",&u);
if(u==1)
{
for(int t=5; t<10; t )
if(a[t]==0)
{
a[t]=1;
printf("Your site is No.%d.\n",t 1);
printf("it's economy.\n");
printf("Thank you.\n");
s=1;
break;
}
if(s==1) continue;
printf("Sorry, all site in this plane has all sold.\n");
printf("Next flight leaves in 3 hours.\n");
continue;
}
else if(u==2)
{
printf("Next flight leaves in 3 hours.\n");
continue;
}
}

else if(i==2)
{
for(int t=5; t<10; t++)
if(a[t]==0)
{
a[t]=1;
printf("Your site is No.%d.\n",t+1);
printf("it's economy.\n");
printf("Thank you.\n");
s=1;
break;
}
if(s==1) continue;
printf("All site in economy has been sold.\n");
printf("Would you want to buy site in first class?\n");
printf("type 1 for yes, type 2 for no.");
scanf("%d",&u);
if(u==1)
{
for(int t=0; t<5; t++)
if(a[t]==0)
{
a[t]=1;
printf("Your site is No.%d.\n",t+1);
printf("it's first class.\n");

printf("Thank you.\n");
s=1;
break;
}
if(s==1) continue;
printf("Sorry, all site in this plane has all sold.\n");
printf("Next flight leaves in 3 hours.\n");

continue;
}
else if(u==2)
{
printf("Next flight leaves in 3 hours.\n");
continue;
}
}
else if(i==3)
{
printf("See you next time.\n");
exit(1);
}
}
}
system("PAUSE");   
return 0;
}

TOP

我上學期C語言被當掉.....
所以這學期專心學C++ 老師說C學低好C++不一定學低好.....所以我打算試試看~~~

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。