『壹』 飛機訂票系統設計 c語言
(已修改,請用最新的代碼)代碼說明:
1級菜單:選擇購買的航班號,並顯示對應座位狀態。
(我只做測試,所以初始化initFlight函數中我只初始了2個航班,需要自己按照我的代碼添)
(注意:實際開發軟體,鏈表數據是從資料庫中讀取的,需要實時同步,如果要多次調用initFlight函數,記得自己寫一個釋放內存的函數,把所有鏈表「SINFO和FLINFO」節點都釋放掉,釋放函數我沒寫,需要你自己寫!!!)
2級菜單:選擇購買對應座位號,完成購買,並實時顯示購買結果。
位置編號、座位最大排數、艙室類型、折扣等參數均由常量參數空值,需要修改自行改常量。
注意:艙室類型(我默認3個類型頭等艙、公務艙、經濟艙)對應折扣參數:tDiscount二維數組。如要如要添加新的艙室類型,必須將參數常量TYPESIZE、typeName、types、tDiscount這4個同時修改,具體看代碼備注!!
座位票價=基礎票價*類型折扣*時段折扣。
因為飛機不讓吸煙,所以我沒做吸煙區(笑),如果你需要,可以作為類型自行添加!
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
#include<time.h>
//-----------------------相關參數,想改變,在這里修改!!!!!!!-----------------------------
constfloattimeDiscount=1;//時段折扣,影響所有航班最終價格,默認1
constcharcID[5]="ABCD";//位置編號
constintmaxRow=20;//位置最大排號
//注意:如果修改類型數量,types和tDiscount必須同時修改!!!
#defineTYPESIZE3//類型數量
constchartypeName[TYPESIZE][10]={"頭等艙","公務艙","經濟艙"};
constinttypes[TYPESIZE][2]={{1,2},{3,4},{5,20}};//排號對應類型。1~2排頭等艙,3~4排公務艙,5~20排經濟艙
constfloattDiscount[TYPESIZE]={1.5,1.3,1};//類型折扣。頭等艙1.5倍,公務艙1.3倍,經濟艙1倍
//-------------------------------------------------------------------------------
typedefstructseatInfo//座位信息,一條鏈表對應一個航班信息,鏈表順序從第一排左邊第一個開始往後A1~D1,A2~D2。。。
{
charcloID;//位置編號A、B、C、D
introw;//位置排號
inttype;//座位所屬類型:0:頭等艙、1:公務艙、2:經濟艙,不同類型對應不同的類型折扣tDiscount
intsell;//出售狀態,0:未出售;1:已出售
structseatInfo*next;
}SINFO;
typedefstructflightInfo//航班信息
{
charfid[10];//航班號
time_ttfTime;//起飛時間
time_tldTime;//降落時間
chartoCity[20];//抵達城市
floattPrice;//基礎票價,不同位置具有不同折扣,座位票價=基礎票價*類型折扣*時段折扣
structflightInfo*next;
structseatInfo*sHead;//對應座位鏈表的頭節點
}FLINFO;
voidmeError(void*p);
SINFO*getSINFO();//獲取座位鏈表
//addFLINFO:添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)
FLINFO*addFLINFO(FLINFO**ffHead,FLINFO*flinfoTail,FLINFOfNew);//返回尾節點
time_tgetTime_tfromStr(char*sTime);//將YYYY-MM-DDhh:mm:ss格式的時間字元串轉換成time_t型數值
FLINFO*initFlight();//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這里添加!!!正常軟體開發,這一步應該是從資料庫讀取!
char*getTString(structtm*tm0);//通過tm獲取時間字元串
voidshowSinfo(FLINFO*flinfo);//顯示航班對應座位信息
voidprintfFlinfo(FLINFO*flinfoHead);
FLINFO*selectFlinfo(FLINFO*flinfoHead,char*fid);//選擇航班號,返回節點
voidshowSinfo(FLINFO*flinfo);//顯示航班對應座位信息
SINFO*selectSinfo(FLINFO*flinfo,char*sid);//選擇座位,返回節點
intmain()
{
FLINFO*flinfoHead=initFlight(),*ffSelect=NULL;
SINFO*sfSelect=NULL;
charfid[10]={0},sid[10]={10};
while(1)
{
ffSelect=NULL;
sfSelect=NULL;
memset(fid,0,10);
memset(sid,0,10);
printfFlinfo(flinfoHead);
printf("請輸入要購買的航班號:");
scanf("%s",fid);
ffSelect=selectFlinfo(flinfoHead,fid);
if(!ffSelect)
{
printf("未找到對應航班,按任意鍵繼續-----
");
getch();
system("cls");
continue;
}
system("cls");
printf("航班號:%s座位信息如下:
",ffSelect->fid);
showSinfo(ffSelect);
printf("請輸入要購買的座位編號(輸入0返回主菜單):");
scanf("%s",sid);
if(!strcmp(sid,"0"))
{
system("cls");
continue;
}
else
{
sfSelect=selectSinfo(ffSelect,sid);
if(!sfSelect||sfSelect->sell)
{
printf("未找到對應座位或該座位已出售,請重新輸入!按任意鍵繼續-----
");
getch();
system("cls");
continue;
}
printf("購買成功!按任意鍵繼續-----");
sfSelect->sell=1;
getch();
system("cls");
}
}
return0;
}
SINFO*selectSinfo(FLINFO*flinfo,char*sid)//選擇座位,返回節點
{
SINFO*sinfoHead=flinfo->sHead;
while(sinfoHead->next)
{
if(sinfoHead->next->cloID==sid[0]&&sinfoHead->next->row==atoi(sid+1))
returnsinfoHead->next;
sinfoHead=sinfoHead->next;
}
returnNULL;
}
voidshowSinfo(FLINFO*flinfo)//顯示航班對應座位信息
{
SINFO*sinfoHead=flinfo->sHead,*sfp=NULL;
inti,j,k,row=maxRow,clo=strlen(cID);
chartypeStr[10]={0};
for(i=0;i<row;i++)
{
//---------讀取座位所屬艙室------------
memset(typeStr,0,10);
for(k=0;k<TYPESIZE;k++)
if(i+1>=types[k][0]&&i+1<=types[k][1])
strcpy(typeStr,typeName[k]);
//--------------------------------------
printf("
");
for(j=0;j<clo;j++)
printf("-------------");
printf("
");
sfp=sinfoHead;
for(j=0;j<clo;j++)
{
printf("|%c%02d|",sfp->next->cloID,sfp->next->row);
sfp=sfp->next;
}
printf("
");
sfp=sinfoHead;
for(j=0;j<clo;j++)
{
printf("|%c|",sfp->next->sell?2:1);
sfp=sfp->next;
}
printf("
");
sfp=sinfoHead;
for(j=0;j<clo;j++)
{
printf("|%6s:%4.0f|",typeStr,flinfo->tPrice*tDiscount[sfp->next->type]*timeDiscount);
sfp=sfp->next;
}
printf("
");
sinfoHead=sfp;
}
for(j=0;i<clo;j++)
printf("-------");
printf("
");
}
FLINFO*selectFlinfo(FLINFO*flinfoHead,char*fid)//選擇航班號,返回節點
{
while(flinfoHead->next)
{
if(!strcmp(flinfoHead->next->fid,fid))
returnflinfoHead->next;
flinfoHead=flinfoHead->next;
}
returnNULL;
}
voidprintfFlinfo(FLINFO*flinfoHead)
{
while(flinfoHead->next)
{
printf("目的地:%s,航班號:%s
----起飛時間:%s,抵達時間:%s
",flinfoHead->next->toCity,flinfoHead->next->fid,getTString(localtime(&flinfoHead->next->tfTime)),getTString(localtime(&flinfoHead->next->ldTime)));
flinfoHead=flinfoHead->next;
}
}
char*getTString(structtm*tm0)//通過tm獲取時間字元串
{
char*str=(char*)malloc(sizeof(char)*20),num[5]={0};
meError(str);
memset(str,0,20);
sprintf(num,"%4d",tm0->tm_year+1900);
strcat(str,num);
strcat(str,"-");
memset(num,0,5);
sprintf(num,"%02d",tm0->tm_mon);
strcat(str,num);
strcat(str,"-");
memset(num,0,5);
sprintf(num,"%02d",tm0->tm_mday);
strcat(str,num);
strcat(str,"");
memset(num,0,5);
sprintf(num,"%02d",tm0->tm_hour);
strcat(str,num);
strcat(str,":");
memset(num,0,5);
sprintf(num,"%02d",tm0->tm_min);
strcat(str,num);
strcat(str,":");
memset(num,0,5);
sprintf(num,"%02d",tm0->tm_sec);
strcat(str,num);
returnstr;
}
time_tgetTime_tfromStr(char*sTime)//將YYYY-MM-DDhh:mm:ss格式的時間字元串轉換成time_t型數值
{
time_trt;
structtm*tm1=NULL;
rt=time(NULL);
tm1=localtime(&rt);
sscanf(sTime,("%4d-%2d-%2d%2d:%2d:%2d"),&tm1->tm_year,&tm1->tm_mon,&tm1->tm_mday,&tm1->tm_hour,&tm1->tm_min,&tm1->tm_sec);
tm1->tm_year-=1900;
tm1->tm_mon--;
rt=mktime(tm1);
returnrt;
}
FLINFO*initFlight()//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這里添加!!!正常軟體開發,這一步應該是從資料庫讀取!
{
FLINFO*ffHead=NULL,*flinfoTail=NULL,fNew;
//--------添加一個航班信息----需要增加按照我下面調用方式寫--------------------------------
strcpy(fNew.fid,"CI502");
fNew.tfTime=getTime_tfromStr("2019-02-2003:30:30");
fNew.ldTime=getTime_tfromStr("2019-02-2005:20:30");
strcpy(fNew.toCity,"台北");
fNew.tPrice=1000;
fNew.next=NULL;
flinfoTail=addFLINFO(&ffHead,flinfoTail,fNew);
//--------------------------------------------------------------------------------------------
strcpy(fNew.fid,"9C8921");
fNew.tfTime=getTime_tfromStr("2019-02-2014:30:30");
fNew.ldTime=getTime_tfromStr("2019-02-2016:40:30");
strcpy(fNew.toCity,"香港");
fNew.tPrice=500;
fNew.next=NULL;
flinfoTail=addFLINFO(&ffHead,flinfoTail,fNew);
returnffHead;
}
FLINFO*addFLINFO(FLINFO**ffHead,FLINFO*flinfoTail,FLINFOfNew)//返回尾節點
//添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)
{
FLINFO*flinfoHead=*ffHead;
if(flinfoHead==NULL)
{
*ffHead=(FLINFO*)malloc(sizeof(FLINFO));
flinfoHead=*ffHead;
meError(flinfoHead);
flinfoHead->next=NULL;
}
FLINFO*flinfoNew=(FLINFO*)malloc(sizeof(FLINFO));
meError(flinfoNew);
flinfoNew->next=NULL;
flinfoNew->fid[0]=0;
strcpy(flinfoNew->fid,fNew.fid);
flinfoNew->ldTime=fNew.ldTime;
flinfoNew->tfTime=fNew.tfTime;
flinfoNew->toCity[0]=0;
strcpy(flinfoNew->toCity,fNew.toCity);
flinfoNew->tPrice=fNew.tPrice;
flinfoNew->sHead=getSINFO();
if(flinfoHead->next==NULL)
flinfoHead->next=flinfoNew;
else
flinfoTail->next=flinfoNew;
flinfoTail=flinfoNew;
returnflinfoTail;
}
SINFO*getSINFO()//獲取座位鏈表
{
intmaxClo=strlen(cID),cnt=maxClo*maxRow,clo=0,row=1,i;
SINFO*sinfoHead=(SINFO*)malloc(sizeof(SINFO)),*sinfoTail=NULL;
meError(sinfoHead);
sinfoHead->next=NULL;
SINFO*sinfoNew=NULL;
while(cnt--)//按順序生成對應數量的座位鏈表
{
if(clo==maxClo)
clo=0,row++;
if(row==maxRow+1)
row=1;
sinfoNew=(SINFO*)malloc(sizeof(SINFO));
meError(sinfoNew);
sinfoNew->cloID=cID[clo];
sinfoNew->row=row;
for(i=0;i<TYPESIZE;i++)
if(row>=types[i][0]&&row<=types[i][1])
{
sinfoNew->type=i;
break;
}
sinfoNew->sell=0;
sinfoNew->next=NULL;
if(sinfoHead->next==NULL)
sinfoHead->next=sinfoNew;
else
sinfoTail->next=sinfoNew;
sinfoTail=sinfoNew;
clo++;
}
returnsinfoHead;
}
voidmeError(void*p)//內存申請失敗
{
if(p==NULL)
{
printf("
異常:內存申請失敗!回車結束程序!
");
while(getch()!='
');
exit(0);
}
}
『貳』 幫忙編一道c語言程序題
#include <stdio.h>
#include <math.h>
int main()
{
double a = 0.0; // 加速度
double t = 0.0; // 加速時間
double v0 = 0.0, s = 94.0, v = 278.0; // 初速度,加速距離,起飛速度
printf("輸入起飛速度(km/h)、彈射距離(m),如輸入278km/h,94m:\n");
scanf("%lfkm/h,%lfm", &v, &s);
v = v / 3.6; // 轉換成m/s
a = pow(v, 2)/(2*s); // 計算加速度
t = sqrt(2*s/a); // 計算加速時間
printf("加速度a=%.3lf,加速時間t=%.3lf", a, t);
return 0;
}
『叄』 C語言初學者求教
1 首先定義結構體數組arr
struct time
{
int hour; // 起飛時間的小時
int min; // 起飛時間的分鍾
int arriveH; //到達的小時
int arriveM; //到達的分鍾
}arr[7];
2 按從小到大的順序給數組arr[]賦值,arr[] ={ {8,0,10,16},...};
3 接收輸入的時間,並保存;
4 for()循環,遍歷數組arr[],在這里比大小,得出結果
5 輸出結果。
=============================
提高2:
1 定義數組:
char* arr1[9] // 保存1-9的英文單詞;
char* arr10[10] //保存10 -19的英文單詞;
char* arr20[8] // 保存20,30,40等整十的英文。
2 接收輸入的數並保存到 a;
3 if(a<20) 遍歷數組arr10[] ,i = a%10;printf("%s", arr10[i]); //只考慮輸入的是兩位數。
else
{
i = a/10; //得到十位上的數,
j = a%10; //得到個位上的數,
if(j==0) //如果a =20,30之類的整數就在這輸出
printf(" %s\n", arr20[i-2]);
else
printf(" %s-%s\n", arr20[i-2],arr1[j-1]);
}
『肆』 c語言程序設計飛機訂票系統
呵呵 這個也是我在網上搜的 挺不錯 沒有錯誤
#include<stdio.h> //標准輸入、輸出頭文件
#include<string.h> //包含字元串函數處理頭文件
#include<stdlib.h> //包含動態存儲與釋放函數頭文件
#define N 10000
struct air //定義結構體數組
{
int num;
char start[20];
char over[20];
char time[10];
int count;
}s[N];
int i;
int m=0;
#define PRINT "%-d%12s%12s%10s%12d\n",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count //定義輸出格式
void input(); //輸入航班信息
void print(); //輸出航班信息
void save(); //保存航班信息
void read(); //讀取航班信息
void search(); //查找航班信息
void shanchu(); //刪除航班信息
void dingpiao(); //訂票信息
void tuipiao(); //退票信息
void xiugai(); //修改信息
void main()
{
int j;
printf(" ★---您好,歡迎進入中國民航管理系統!---★\n");
printf("================================================================================\n");
do
{
printf(" -------- ☆ 1.輸入航班信息 ☆-------- \n\n"
" -------- ☆ 2.瀏覽航班信息 ☆-------- \n\n"
" -------- ☆ 3.修改航班信息 ☆-------- \n\n"
" -------- ☆ 4.查找航班信息 ☆-------- \n\n"
" -------- ☆ 5.刪除航班信息 ☆-------- \n\n"
" -------- ☆ 6.訂票信息 ☆-------- \n\n"
" -------- ☆ 7.退票信息 ☆-------- \n\n"
" -------- ☆ 0.退出 ☆-------- \n\n");
printf("================================================================================\n");
printf("請在0-7中選擇以回車鍵結束:\n\n");
scanf("%d",&j);
switch(j)
{
case 1: input();//調用輸入模塊
break;
case 2:print();//調用列印模塊
break;
case 3:xiugai();//調用修改模塊
break;
case 4:search();//調用查找模塊
break;
case 5:shanchu(); //調用刪除模塊
break;
case 6:dingpiao();//調用訂票模塊
break;
case 7:tuipiao();//調用退票模塊
break;
case 0:;
break;
}
}while(j!=0); //判斷結束
printf("謝謝使用,再見!\n");
}//主函數結束
void input()//列印模塊程序
{
char f[]="2008china"; //設置密碼
int y;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f); //讀取密碼
if(strcmp(f,"2008china")==0)
{
printf("請依次輸入航班信息(機票數位0結束輸入):\n\n"
"完成輸入信息請鍵入w以回車鍵結束\n\n"); //列印提示信息
printf("--------------------------------------------------------------------------\n");
for(i=0;i<N;i++)
{
printf("請輸入航班號:\n");
scanf("%d",&s[i].num); //讀取航班號
printf("請輸入起始站:\n");
scanf("%s",s[i].start);//讀取起始站
printf("請輸入終點站:\n");
scanf("%s",s[i].over);//讀取終點站
printf("請輸入時間:\n");
scanf("%s",s[i].time);//讀取時間
printf("請輸入機票數(機票數為0結束輸入):\n",m);
scanf("%d",&s[i].count);//讀取機票數
m++;
printf("第%d個信息已經輸完是否繼續?按任意鍵繼續,按 0結束",m);
scanf("%d",&y);
if(y==0)
{
save();//將結構體信息存檔
print();//輸出輸入的航班信息
break;
}
}
}
else
printf("輸入密碼錯誤!請檢查您的密碼是否正確!謝謝!再見!\n\n");
}
void save()//保存模塊程序
{
FILE *fp,*fp1;//定義文件指針
if((fp=fopen("chen.dat","wb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}
if((fp1=fopen("hao.dat","wb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}
for(i=0;i<m;i++)
if(fwrite(&s[i],sizeof(struct air),1,fp)==0)//向文件寫入數據,並判斷是否出錯
printf("向文件輸入數據失敗!\n\n");
fprintf(fp1,"%d",m);
fclose(fp);//關閉文件
fclose(fp1);//關閉文件
}
void read()//從文件讀取信息模塊
{
FILE *fp,*fp1;//定義文件指針
if((fp=fopen("chen.dat","rb"))==NULL)//打開文件,並判斷是否出錯
{
printf("出錯,請檢查文件是否存在,按任意鍵返回住菜單");//列印出錯提示
getchar();
}
if((fp1=fopen("hao.dat","rb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}
fscanf(fp1,"%d",&m);
fclose(fp1);//關閉文件
for(i=0;i<m;i++)
{
fread(&s[i],sizeof(air),1,fp);//從文件中讀取信息
}
fclose(fp);//關閉文件
}
void print()//列印模塊
{
char w[10];
read();//調用讀取文件函數
printf("航班號 起始站 終點站 時間 機票數\n");
for(i=0;i<m;i++)
{
printf(PRINT);//列印信息
}
printf("請按任意鍵回車鍵結束返回上層菜單以:\n");
scanf("%s",w);
}
void search()//查詢模塊
{
char name1[20];
char name2[20];
char ii[10];
int n,no;
do
{
printf("請選擇查找方式:\n\n");//列印查詢方式菜單
printf("1.按航班號查找\n\n"
"2.按終點站查找\n\n"
"3.按航線查找\n\n"
"0.返回\n\n");
printf("請在0-3中選擇:\n\n"
"按其他鍵以回車鍵結束返回主菜單:\n\n");
scanf("%d",&n);//讀取查找方式
if(n==0)
break;
switch(n)
{
case 1:
printf("請輸入航班號:\n");
scanf("%d",&no);//航班號
break;
case 2:
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//讀取終點站
break;
case 3:
printf("請輸入起始站名稱:\n");
scanf("%s",name1);//讀取起始站
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//終點站
break;
}
read();//調用讀取函數
for(i=0;i<m;i++)
{
if(strcmp(s[i].over,name1)==0||strcmp(s[i].over,name2)==0)//按終點站起始站判斷輸出條件
{
printf("\n查找航班信息成功!\n");
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);//列印信息
break;
}
if(s[i].num==no)//按航班號判斷輸出條件
{
printf("\n查找航班信息成功!\n");
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);//列印信息
break;
}
}
no=0;//將航班號賦值為0
printf("沒有您需要的信息或查找完畢:\n\n"
"是否繼續查找?請鍵入yes或no以回車鍵結束\n");
scanf("%s",ii);
}while(strcmp(ii,"yes")==0);//判斷結束
}
void shanchu()//刪除模塊
{
char name1[20];
char name2[20];
char ii[10];
char f[]="2008china";//設置密碼
int no,n;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f);//讀取密碼
if(strcmp(f,"2008china")==0) //判斷密碼是否正確
{
do
{
printf("請選擇刪除以方式回車鍵結束:\n\n");//列印刪除方式菜單
printf("*1.按航班號刪除\n\n"
"*2.按航線刪除\n\n"
"*0.返回\n\n");
printf("請在0-2中選擇以回車鍵結束:\n");
scanf("%d",&n);//讀取刪除方式
if(n==0)
break; //跳出循環
switch(n)
{
case 1:
printf("請輸入航班號:\n");
scanf("%d",&no);//讀取航班號
read();//調用讀取函數
break;//跳出循環
case 2:
printf("請輸入起始站 名稱:\n");
scanf("%s",name1);//讀取起始站
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//讀取終點站
read();//調用讀取函數
break;//跳出循環
}
for(i=0;i<m;i++)
{
if(s[i].num==no||strcmp(s[i].start,name1)==0&&strcmp(s[i].over,name2)==0)//判斷輸入信息是否存在
{
s[i]=s[m-1];
m--;
}
}
printf("查找完畢或沒有這個信息\n\n");
printf("是否繼續刪除\n");
printf("請鍵入yes或no以回車鍵結束\n");
scanf("%s",ii); //讀取是否繼續信息
save(); //調用讀取函數
if(!strcmp(ii,"yes")) //判斷是否繼續刪除
printf("請按任意鍵以回車鍵結束返回上層菜單:\n");
break;
}while(n!=1&&n!=2&&n!=3&&n!=4&&n!=0); //判斷結束
}
else
printf("對不起密碼錯誤!您不是管理員,不能使用此項功能!謝謝!再見!\n\n");
}
void dingpiao()//訂票模塊
{
int n;
char a[10];
do
{
search();//調用查詢模塊
printf("請輸入您要訂的機票數以回車鍵結束:\n");
scanf("%d",&n);//讀取所訂機票數
if(n<0)
{
printf("請輸入有效的機票數!\n");//判斷機票數是否出錯
break;
}
if(s[i].count!=0&&s[i].count>=n)//判斷是否出錯
{
s[i].count=s[i].count-n;
save();//調用保存函數
printf("訂票成功!\n\n");
break;
}
if(s[i].count<n)//判斷是否出錯
{
printf("請輸入有效的機票數:\n");
break;
}
printf("是否繼續? 請輸入yes或no以回車鍵結束:\n");//判斷是否繼續訂票
scanf("%s",a);
}while(!strcmp(a,"yes"));//判斷結束
}
void tuipiao()//退票模塊
{
int n;
char a[10];
do
{
search();//調用查詢模塊
printf("請輸入您要退的機票數目:\n");
scanf("%d",&n);//輸入所退票數
if(n<0) //判斷票數是否有效
printf("請輸入有效的機票數!\n");
s[i].count=s[i].count+n;
save(); //調用保存模塊
printf("退票成功!\n\n");
printf("是否繼續? 請鍵入yes或no以回車鍵結束:\n\n");//判斷是否繼續退票
scanf("%s",a);
}while(!strcmp(a,"yes"));//判斷並跳出循環
getchar();
}
void xiugai() //修改模塊
{
struct xiu //定義結構體
{
int no;
char name1[20];
char name2[20];
char time[20];
int count;
}x[1];
char j[10];
char f[]="2008china";//設置密碼
int n;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f);//讀取密碼
if(strcmp(f,"2008china")==0)//判斷是否出錯
{
read();//調用讀取模塊
do
{
printf( "請選擇修改方式:\n\n"
"*1,按航班號修改:\n\n"
"*2,按航線修改: \n\n");
printf("請在1---2中修改以回車鍵結束:\n\n");
scanf("%d",&n);//讀取修改方式
switch(n)
{
case 1:printf("請輸入航班號:\n");
scanf("%d",&x[0].no);//讀取航班號
break;
case 2:printf("請輸入起始站:\n");
scanf("%s",x[0].name1);//讀取起始站
printf("請輸入終點站:\n");
scanf("%s",x[0].name2);//讀取終點站
break;
}
for(i=0;i<m;i++)
{
if(strcmp(s[i].over,x[0].name1)==0&&strcmp(s[i].over,x[0].name2)==0)//判斷輸出條件
{
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);
break;
}
if(s[i].num==x[0].no)//判斷輸出條件
{
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);
break;
}
}
x[0].no=0; //將結構體中的號為零
printf("請輸入新航班號、起始站、終點站、時間(星期幾)、機票數:\n");
scanf("%d%s%s%s%d",&x[0].no,x[0].name1,x[0].name2,x[0].time,&x[0].count);//定義輸入格式
s[i].num=x[0].no;//替換航班號
strcpy(s[i].start,x[0].name1);//替換其始站
strcpy(s[i].over,x[0].name2);//替換終點站
strcpy(s[i].time,x[0].time);//替換時間
s[i].count=x[0].count;//替換機票數
save();//調用保存模塊
printf("是否繼續?請鍵入yes或no以回車鍵結束:\n\n");
scanf("%s",j);
}while(strcmp(j,"yes")==0); //判斷結束
}
else
printf("對不起密碼錯誤!您不是管理員,不能使用此項功能!謝謝!再見!\n\n");
}
『伍』 c語言 vs2010 飛機從初速度0 到起飛速度v,起飛距離s,求加速度a,和起飛時間t
s=(v*v-0*0)/(2*a);
老兄這個公式也給忘啦啊 呵呵
//t=(7.2*s)/v;
a=(v*v)/(2*s);//求得加速度a
//a=v/(3.6*t);
t=v/a;//求得起飛時間
這就好了啊
『陸』 請用c語言用結構體或者二維數組完成航班信息管理系統
需要分析:
A.車尋航線:
1.根據旅客提出的起點站,終點站名輸出下列信息:航班號,票價,折扣,最多載客量,是否滿載,起飛時間,降落時間和飛行時間;
2.根據訂票乘客的姓名可以查詢所訂航班的航班號,座位號,飛行日期等信息;
3.根據航班號查詢航班的起點站,中轉站,終點站名,票價,折扣,最多載客量,是否滿載,起飛時間,降落時間和飛行時間;
B.承辦客戶提出的要求(航班號、訂票數額)查詢該航班票額情況,若有餘票,則為客戶辦理訂票手續,輸出座位號,需付款項信息;若已滿員或余票額少於盯票額,則需重新詢問客戶要求。若需要,可登記排隊候補;
C.根據客戶提供的情況(日期、航班),為客戶辦理退票手續。(然後查詢該航班是否有人排隊候補,首先詢問排第一的客戶,若所退票額所能滿足他的要求,則為他辦理訂票手續,否則依次詢問其他排隊候補客戶);
E.內部人員對航班情況的控制:
可以錄入航班信息,刪除航班信息,修改航班信息,查看基本航班信息。
概要設計:
因為每個客戶名單或查詢名單都包括多個數據域,這樣就需要有一個能存儲多個數據域的數據類型來存儲,因此採用單鏈表類型。由於航線的信息是固定的,可選用結構體數組,又因為訂票與預約人數無法預計,可選用鏈表存儲信息。
線性表的單鏈表存儲結構:typedef struct LNode{
ElemType;
Struct Lnode*next;}LNode,*LinkList;
a.抽象數據類型順序表的定義如下:
ADT SqList{
數據對象:D={ai|ai∈數據類型,i=1,2,3...,n}
數據關系:R1={<ai-1,ai>|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_Sq(&L)
操作結果:創建空的順序表。
CreatList_Sq(&L)
操作結果:建立順序表。
}ADT SqList
b.抽象數據類型單鏈表的定義如下:
ADT LinkList{
數據對象:D={ai|ai∈結構類型,i=1,2,3...,n,n>0}
數據關系:R1={<ai-1,ai>|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_L(&L)
操作結果:創建空的順序表。
}ADT LinkList
在main()里調用各個函數
2.主程序
void main(){
初始化;
do{
接受命令;
處理命令;
}while(「命令」!=「退出」);
}
3.程序的模塊調用:
三.詳細設計:
1.所有數據類型:
struct plan /*航班數據*/
{
『柒』 C語言編寫一個簡單的航空管理系統
需要分析:
A.車尋航線:
1.根據旅客提出的起點站,終點站名輸出下列信息:航班號,票價,折扣,最多載客量,是否滿載,起飛時間,降落時間和飛行時間;
2.根據訂票乘客的姓名可以查詢所訂航班的航班號,座位號,飛行日期等信息;
3.根據航班號查詢航班的起點站,中轉站,終點站名,票價,折扣,最多載客量,是否滿載,起飛時間,降落時間和飛行時間;
B.承辦客戶提出的要求(航班號、訂票數額)查詢該航班票額情況,若有餘票,則為客戶辦理訂票手續,輸出座位號,需付款項信息;若已滿員或余票額少於盯票額,則需重新詢問客戶要求。若需要,可登記排隊候補;
C.根據客戶提供的情況(日期、航班),為客戶辦理退票手續。(然後查詢該航班是否有人排隊候補,首先詢問排第一的客戶,若所退票額所能滿足他的要求,則為他辦理訂票手續,否則依次詢問其他排隊候補客戶);
E.內部人員對航班情況的控制:
可以錄入航班信息,刪除航班信息,修改航班信息,查看基本航班信息。
概要設計:
因為每個客戶名單或查詢名單都包括多個數據域,這樣就需要有一個能存儲多個數據域的數據類型來存儲,因此採用單鏈表類型。由於航線的信息是固定的,可選用結構體數組,又因為訂票與預約人數無法預計,可選用鏈表存儲信息。
線性表的單鏈表存儲結構:typedef struct LNode{
ElemType;
Struct Lnode*next;}LNode,*LinkList;
a.抽象數據類型順序表的定義如下:
ADT SqList{
數據對象:D={ai|ai∈數據類型,i=1,2,3...,n}
數據關系:R1={<ai-1,ai>|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_Sq(&L)
操作結果:創建空的順序表。
CreatList_Sq(&L)
操作結果:建立順序表。
}ADT SqList
b.抽象數據類型單鏈表的定義如下:
ADT LinkList{
數據對象:D={ai|ai∈結構類型,i=1,2,3...,n,n>0}
數據關系:R1={<ai-1,ai>|ai-1,ai∈D,i=1,2,3...,n}
基本操作:
InitList_L(&L)
操作結果:創建空的順序表。
}ADT LinkList
在main()里調用各個函數
2.主程序
void main(){
初始化;
do{
接受命令;
處理命令;
}while(「命令」!=「退出」);
}
3.程序的模塊調用:
三.詳細設計:
1.所有數據類型:
struct plan /*航班數據*/
{
char num[5];/*航班號碼*/
char city[10];/*到達城市*/
char up[8];/*航班起飛時間*/
char down[8];/*航班到達時間*/
int pric ;/*航班價格*/
int rshu ;/*人數*/
int zheg[4];/*價格折扣*/
}
;
struct man/*定票人數據*/
{
char num[10];/*身份證號碼*/
char nam[10];/*姓名*/
int demand ;/*定票數量*/
}
;
typedef struct node/*航班數據結點*/
{
struct plan data ;
struct node*next ;
}
Node,*Link ;
typedef struct people/*乘客數據結點*/
{
struct man data ;
struct people*next ;
}
peo,*LIN ;
2.程序所用函數:
void print()/*界面輸出*/
{
printf("============================System of book ticket===============================\n");
printf("\n");
printf("\t***********************************************************\n");
printf("\t*\t1---Bookticket \t2---Dishonorbill *\n");
printf("\t*\t3---Adding flight\t4---Adding flight *\n");
printf("\t*\t5---Modify \t6---Advice *\n");
printf("\t*\t7---Save \t8---exit *\n");
printf("\t##########################################################\n");
}
添加航班模塊
void add(Link l)/*添加航班數據*/
{
Node*p,*r,*s ;
char num[10];
r=l ;
s=l->next ;
while(r->next!=NULL)
r=r->next ;
while(1)
{
printf("please input the number of the plan(0-return)");/*輸入0就返回*/
scanf("%s",num);
if(strcmp(num,"0")==0)
break ;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====tip:the number'%s'has been born!\n",num);
return ;
}
s=s->next ;
}
p=(Node*)malloc(sizeof(Node));/*航班數據輸入*/
strcpy(p->data.num,num);
printf("Input the city where the plan will reach:");/*飛機到達地城市*/
scanf("%s",p->data.city);
getchar();
printf("Input the time which the plan take off:");/*起飛時間*/
scanf("%s",p->data.up);
getchar();
printf("Input the time which the plan reach:");/*降落時間*/
scanf("%s",&p->data.down);
getchar();
printf("Input the price of ticket:$");/*機票價格*/
scanf("%d",&p->data.pric);
getchar();
printf("Input the number of people who have booked ticket:");/*定票數量*/
scanf("%d",&p->data.rshu);
getchar();
printf("Input the agio of the ticket:");
scanf("%s",&p->data.zheg);
getchar();
p->next=NULL ;
r->next=p ;
r=p ;
shoudsave=1 ;
}
}
輸出模塊
void pri(Node*p)/*輸出函數*/
{
printf("\n\t\t\tThe following is the record you want:\n");
printf("\nnumber of plan: %s",p->data.num);
printf("\ncity the plan will reach: %s",p->data.city);
printf("\nthe time the plan take off: %s\nthe time the plan reach: %s",p->data.up,p->data.down);
printf("\nthe price of the ticket: %d",p->data.pric);
printf("\nthe number of people who have booked ticket: %d",p->data.rshu);
printf("\nthe agio of the ticket:%s",p->data.zheg);
}
退出函數模塊
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 qur(Link l)/*航班信息查詢*/
{
Node*p ;
int sel ;
char str1[5],str2[10];
if(!l->next)
{
printf("TIP:there are not any record to be inquired for you!");
return ;
}
printf("Choose the way:(1->according to the number of plan;2->according to the city):");/*選擇航班號查詢和終點城市查詢*/
scanf("%d",&sel);
if(sel==1)
{
printf("Input the the number of plan:");
scanf("%s",str1);
p=Locate1(l,str1,"num");
if(p)
{
printf("the following is what you want:\n");
pri(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)
{
printf("the following is what you want:\n");
pri(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
}
定票模塊
void buy(Link l,LIN k)/*定票函數*/
{
Node*r[10],*p ;
int ch,dem ;
peo*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;t<i;t++)
pri(r[t]);
if(i==0)
printf("\n\tSorry!Can't find the plan for you!\n");
else
{
printf("\ndo you want to book it?<1/0>\n");
printf("please choose: ");
scanf("%d",&ch);
if(ch==1)
{
h=(peo*)malloc(sizeof(peo));/*重新分配空間*/
printf("Input your name: ");
scanf("%s",&str1);
strcpy(h->data.nam,str1);
printf("Input your id: ");
scanf("%s",&str2);
strcpy(h->data.num,str2);
printf("Input your demand: ");
scanf("%d",&dem);
h->data.demand=dem ;
h->next=NULL ;
v->next=h ;
v=h ;
printf("\n\tLucky!Success in booking ticket!");
getch();
shoudsave=1 ;
}
}
}
peo*Locate2(LIN k,char findmess[])
{
peo*r ;
r=k->next ;
while(r)
{
if(strcmp(r->data.num,findmess)==0)
{
mark=1 ;
return r ;
}
r=r->next ;
}
return 0 ;
}
退票模塊
void tui(LIN k)/*退票函數*/
{
char str[10];
peo*p,*r ;
int ch2=0 ;
printf("Input your id: ");/*輸入身份證號*/
scanf("%s",&str);
p=Locate2(k,str);
if(mark!=1)
printf("can't find the people!");
else if(mark==1)
{
mark=0 ;
printf("\t\t\tthe following is the record you want:\n");
printf("your id:%s\n",p->data.num);
printf("name:%s\n",p->data.nam);
printf("your denmand:%d",p->data.demand);
printf("\ndo you want to refund the ticket?<1/0>");
scanf("%d",&ch2);
if(ch2==1)
{
if(p)
{
r=k ;
while(r->next!=p)
r=r->next ;
r->next=p->next ;
free(p);
}
count2--;
printf("\nyou have sucessed in refunding ticket!");
shoudsave=1 ;
}
}
}
void Modify(Link l)/*修改航班信息*/
{
Node*p ;
char findmess[20],ch ;
if(!l->next)
{
printf("\n=====tip:there isn't record for you to modify!\n");
return ;
}
else
{
qur(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 plan:");
scanf("%s",findmess);
p=Locate1(l,findmess,"num");
if(p)
{
printf("Input another number of plan:");
scanf("%s",&p->data.num);
getchar();
printf("Input another city the plan will reach:");
scanf("%s",&p->data.city);
getchar();
printf("Input another time the plan take off");
scanf("%s",&p->data.up);
printf("Input another time the plan reach:");
scanf("%s",&p->data.down);
printf("Input another price of the ticket::");
scanf("%d",&p->data.pric);
printf("Input another number of people who have booked ticket:");
scanf("%d",&p->data.rshu);
printf("Input another agio of the ticket:");
scanf("%s",&p->data.zheg);
printf("\n=====>tip:modifying record is sucessful!\n");
shoudsave=1 ;
}
else
printf("\tcan't find the flight!");
}
}
else
mark1=0 ;
}
}
void advice(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)==0&&r->data.rshu<200)
{
mar=1 ;
printf("\nyou can select the following plan!\n");
printf("\n\nplease select the fourth operation to book the ticket!\n");
pri(r);
}
r=r->next ;
}
if(mar==0)
printf("\n\t\t\tyou can't book any ticket now!\n");
}
void save1(Link l)/*保存數據*/
{
FILE*fp ;
Node*p ;
int count=0,flag=1 ;
fp=fopen("g:\\data1","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 save2(LIN k) /*保存數據*/
{
FILE*fp ;
peo*p ;
int count=0,flag=1 ;
fp=fopen("g:\\data2","wb");/*文件連接*/
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=k->next ;
while(p)
{
if(fwrite(p,sizeof(peo),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);
}
四.主函數模塊:
main()
{
FILE*fp1,*fp2 ;
Node*p,*r ;
char ch1,ch2 ;
Link l ;
LIN k ;
peo*t,*h ;
int sel ;
l=(Node*)malloc(sizeof(Node));
l->next=NULL ;
r=l ;
k=(peo*)malloc(sizeof(peo));
k->next=NULL ;
h=k ;
fp1=fopen("g:\\data1","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("g:\\data2","ab+");
if((fp2==NULL))
{
printf("can't open the file!");
return 0 ;
}
while(!feof(fp2))
{
t=(peo*)malloc(sizeof(peo));
if(fread(t,sizeof(peo),1,fp2)==1)
{
t->next=NULL ;
h->next=t ;
h=t ;
count2++;
}
}
fclose(fp2);
while(1)
{
getch();
clrscr();
print();
printf("please choose the operation(1-8): ");
scanf("%d",&sel);
if(sel==8)
{
if(shoudsave==1)
{
getchar();
printf("\n=====tip:the file have been changed!do you want to save it(y/n)?\n");
scanf("%c",&ch1);
if(ch1=='y'||ch1=='Y')
{
save2(k);
save1(l);
}
}
printf("\n\tyou have exited! Happy serve for you");
break ;
}
switch(sel)
{
case 1 :
buy(l,k);
break ;
case 2 :
tui(k);
break ;
case 3 :
qur(l);
break ;
case 4 :
add(l);
break ;
case 5 :
Modify(l);
break ;
case 6 :
advice(l);
break ;
case 7 :
{
save1(l);
save2(k);
break ;
}
case 8 :
exit(0);
}
}
getch();
}
『捌』 C語言的題目---試設計一個航空客運訂票系統
白痴,這個問題至少200分,我以前的比這個簡單的200分也沒人回答
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>//overflow
#define ok 1
typedef struct Yidingkehu
{//單鏈表
char name[15];//已訂票的客戶姓名
int dingpiaoshu;//已訂票數量
struct Yidingkehu *next1;//
}Yidingkehu,*Link;
typedef struct Weidingkehu
{//單鏈隊
char name[15];//預訂票的客戶姓名
int yudingpiao;// 要訂票數量
struct Weidingkehu *next2;//下一個鏈隊結點指針
}Weidingkehu,*Qptr;
typedef struct Hangxian
{//創建一個含有六個信息的結構體
char hangbanhao[15];//航班號-
char feijihao[15];//飛機號
int feixingriqi;//起飛時間
int chenkerenshu;//座位數
int yupiao;//余票
char zhongdianzhai[15];//降落城市
struct Hangxian *next;//指向下一個鏈結點的指針
struct Yidingkehu *yiding;//定義一個指向已訂票客戶的頭結點指針
struct Weidingkehu *yudingqueue;
}Hangxian,*Linklist;
Linklist InitLinklist();//01
int InsertLinklist(Linklist &head1);//02
void hbhchaxun();//通過航班號查詢
void mddchaxun();//通過目的地查詢
void lurugongneng();//初始化錄入功能
void chaxungongnen();//查詢功能
void dingpiaogongnen();//訂票功能
void tuipiaogongnen();//退票功能
void main()
{
int n;
do{ //列印主界面
printf("\t 歡迎使用航空客運訂票系統\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t==>1. 錄入功能 ==\n");
printf("\t==>2. 查詢功能 ==\n");
printf("\t==>3. 訂票功能 ==\n");
printf("\t==>4. 退票功能 ==\n");
printf("\t==>5. 退出 ==\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t請選擇:");
scanf("%d",&n);printf("\n");
switch(n)
{
case 1: lurugongneng();//錄入功能
break;
case 2: chaxungongnen();//查詢功能
break;
case 3: dingpiaogongnen();//訂票功能
break;
case 4:tuipiaogongnen();//退票功能
break;
default :exit(0);//退出
}
}while(n==1||n==2||n==3||n==4);
}
void lurugongneng()//初始化的單鏈表*********************************************************錄入功能
{
Linklist p;
//int m,n;
if(!p) exit(OVERFLOW);
printf("\t請依次輸入下面幾項內容:\n\n");//這里的輸入採用一個個單獨輸入,避免了亂賦值的現象
printf("航班號\n");
gets(p->hangbanhao);//這里的二個gets主要是因為在回車鍵的輸入,其中的第一個是來接收上次的回車
gets(p->hangbanhao);
printf("飛機號\n");
gets(p->feijihao);
printf("終點站\n");
gets(p->zhongdianzhai);
printf("飛行日期\n");
scanf("%d",&p->feixingriqi);
printf("乘客總數\n");
scanf("%d",&p->chenkerenshu);
printf("余票數\n");
scanf("%d",&p->yupiao);
}
void chaxungongnen()//******************************************************************查詢功能
{
int n;
printf("\t 查 找 航 線 信 息 \n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t==>1. 通過目的地查詢 ==\n");
printf("\t==>2. 通過航班號查詢 ==\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t請選擇:");
scanf("%d",&n);
printf("\n");//格式化
switch(n)
{
case 1:mddchaxun();
break;
case 2:hbhchaxun();
break;
default :break;
}
}
void mddchaxun()//通過目的地查詢
{
char c[15];
int m;
Linklist p=L;
printf("\t請輸入要查詢的目的地:");
gets(c);
gets(c);//原因同上
do{
p=p->next;
if(p)
{
m=strcmpi((*p).zhongdianzhai,c);//如果==的話則m=0;
if(m==0)
{
printf("\t航班信息:\n");
printf("\t航班號:%s\n",p->hangbanhao);
printf("\t飛機號:%s\n",p->feijihao);
printf("\t飛行時間:周%d\n",p->feixingriqi);
printf("\t余票量:%d\n",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf("\t對不起沒有你要找的目的地:\n\n"); m=0;
}
}while(m!=0);
}
void hbhchaxun()//通過目的地查詢
{
char c[15];
int m;
Linklist p=L;
printf("\t請輸入要查詢的航班號:");
gets(c); gets(c);printf("\n");
do{
p=p->next;
if(p)
{
m=strcmpi((*p).hangbanhao,c);//如果==的話則m=0;這里的(*p).與p->的作用是一樣的
if(m==0)
{
printf("\t航班信息:\n");
printf("\t航班號:%s\n",p->hangbanhao);
printf("\t飛機號:%s\n",p->feijihao);
printf("\t飛行時間:周%d\n",p->feixingriqi);
printf("\t余票量:%d\n\n",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf("\t對不起沒有你要找的航班號:\n"); m=0;
}
}while(m!=0);
}
void dingpiaogongnen()//***************************************************************訂票功能
{
char c[15];
int m=1,piao,ydpiao=0,yd=0,n;//
gets(c);
printf("請輸入終點站名:"); gets(c); printf("\n");
p=L->next;
if(p) {
do{//查找一下,是否有這個航班
if(!p)
{
printf("對不起,沒有你要找的航班:\n\n");
goto loop1;
}
m=strcmpi(p->zhongdianzhai,c);
if(m==0)
{
printf("航班信息:\n");
printf("航班號:%s\n",p->hangbanhao);
printf("飛機號:%s\n",p->feijihao);
printf("飛行時間:周%d\n",p->feixingriqi);
printf("余票量:%d\n",p->yupiao);}
else p=p->next;
}while(m!=0);
if(m==0)
{
do{
printf("\n請輸入你要訂的票數:"); scanf("%d",&piao);
if(piao<=p->yupiao)
{
h=p->yiding;
if(h)
{
h1=h;
h=h->next1;
h=(struct Yidingkehu*)malloc(sizeof(Yidingkehu));
printf("請輸入你的名字:");
gets(h->name);gets(h->name);
h->dingpiaoshu=piao;
h->next1=h1->next1;
h1->next1=h;
p->yupiao=p->yupiao-piao;
printf("訂票成功:\n"); m=2;
}
}
else
{
printf("余票量:%d\n",p->yupiao);
printf("對不起,余票 %d 張不足,不能完成訂票\n\n",p->yupiao);
printf(" 是否要重新訂票?\n");
printf("需要請輸入1 否則請按2 預訂請輸入3 : ");
scanf("%d",&m);
printf("\n");
if(m==3) goto loop3;
}
}while(m==1);
}
}
else if(!p)
{
loop3: struct Weidingkehu *q3;
printf("對不起,該航班的票已售完\n");
q.front=p->yudingqueue;
if(q.front==q.rear) printf("沒有人預訂票,是否要預訂?\n");
else if(q.front!=q.rear) printf("已有人預訂票,是否要預訂?\n");
printf("預訂請輸入1 否則輸入2 : ");
scanf("%d",&n);
printf("\n");
if(n==1)
{
printf("請輸入你的姓名"); gets(q3->name); gets(q3->name);//q3不能指向name???
printf("請輸入訂票數"); scanf("%d",&q3->yudingpiao);
q3->next2=NULL;
q.rear->next2=q3;
q.rear=q3;
printf(" 你已經預訂了 !\n");
}
}
loop1:;
}
void tuipiaogongnen()//***************************************************************退票功能
{
}
『玖』 利用日期、經緯度求日出日落時間 C語言程序代碼
#definePI3.1415926
#include<math.h>
#include<iostream>
usingnamespacestd;
intdays_of_month_1[]={31,28,31,30,31,30,31,31,30,31,30,31};
intdays_of_month_2[]={31,29,31,30,31,30,31,31,30,31,30,31};
longdoubleh=-0.833;
//定義全局變數
voidinput_date(intc[]){
inti;
cout<<"Enterthedate(form:20090310):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//輸入日期
voidinput_glat(intc[]){
inti;
cout<<"Enterthedegreeoflatitude(range:0°-60°,form:404040(means40°40′40″)):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//輸入緯度
voidinput_glong(intc[]){
inti;
cout<<"Enterthedegreeoflongitude(westisnegativ,form:404040(means40°40′40″)):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//輸入經度
intleap_year(intyear){
if(((year%400==0)||(year%100!=0)&&(year%4==0)))return1;
elsereturn0;
}
//判斷是否為閏年:若為閏年,返回1;若非閏年,返回0
intdays(intyear,intmonth,intdate){
inti,a=0;
for(i=2000;i<year;i++){
if(leap_year(i))a=a+366;
elsea=a+365;
}
if(leap_year(year)){
for(i=0;i<month-1;i++){
a=a+days_of_month_2[i];
}
}
else{
for(i=0;i<month-1;i++){
a=a+days_of_month_1[i];
}
}
a=a+date;
returna;
}
//求從格林威治時間公元2000年1月1日到計算日天數days
longdoublet_century(intdays,longdoubleUTo){
return((longdouble)days+UTo/360)/36525;
}
//求格林威治時間公元2000年1月1日到計算日的世紀數t
longdoubleL_sun(longdoublet_century){
return(280.460+36000.770*t_century);
}
//求太陽的平黃徑
longdoubleG_sun(longdoublet_century){
return(357.528+35999.050*t_century);
}
//求太陽的平近點角
longdoubleecliptic_longitude(longdoubleL_sun,longdoubleG_sun){
return(L_sun+1.915*sin(G_sun*PI/180)+0.02*sin(2*G_sun*PI/180));
}
//求黃道經度
longdoubleearth_tilt(longdoublet_century){
return(23.4393-0.0130*t_century);
}
//求地球傾角
longdoublesun_deviation(longdoubleearth_tilt,longdoubleecliptic_longitude){
return(180/PI*asin(sin(PI/180*earth_tilt)*sin(PI/180*ecliptic_longitude)));
}
//求太陽偏差
longdoubleGHA(longdoubleUTo,longdoubleG_sun,longdoubleecliptic_longitude){
return(UTo-180-1.915*sin(G_sun*PI/180)-0.02*sin(2*G_sun*PI/180)+2.466*sin(2*ecliptic_longitude*PI/180)-0.053*sin(4*ecliptic_longitude*PI/180));
}
//求格林威治時間的太陽時間角GHA
longdoublee(longdoubleh,longdoubleglat,longdoublesun_deviation){
return180/PI*acos((sin(h*PI/180)-sin(glat*PI/180)*sin(sun_deviation*PI/180))/(cos(glat*PI/180)*cos(sun_deviation*PI/180)));
}
//求修正值e
longdoubleUT_rise(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){
return(UTo-(GHA+glong+e));
}
//求日出時間
longdoubleUT_set(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){
return(UTo-(GHA+glong-e));
}
//求日落時間
longdoubleresult_rise(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){
longdoubled;
if(UT>=UTo)d=UT-UTo;
elsed=UTo-UT;
if(d>=0.1){
UTo=UT;
UT=UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));
result_rise(UT,UTo,glong,glat,year,month,date);
}
returnUT;
}
//判斷並返回結果(日出)
longdoubleresult_set(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){
longdoubled;
if(UT>=UTo)d=UT-UTo;
elsed=UTo-UT;
if(d>=0.1){
UTo=UT;
UT=UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));
result_set(UT,UTo,glong,glat,year,month,date);
}
returnUT;
}
//判斷並返回結果(日落)
intZone(longdoubleglong){
if(glong>=0)return(int)((int)(glong/15.0)+1);
elsereturn(int)((int)(glong/15.0)-1);
}
//求時區
voidoutput(longdoublerise,longdoubleset,longdoubleglong){
if((int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<10)
cout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":0"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";
elsecout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";
if((int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<10)
cout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";
elsecout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";
}
//列印結果intmain(){
longdoubleUTo=180.0;
intyear,month,date;
longdoubleglat,glong;
intc[3];
input_date(c);
year=c[0];
month=c[1];
date=c[2];
input_glat(c);
glat=c[0]+c[1]/60+c[2]/3600;
input_glong(c);
glong=c[0]+c[1]/60+c[2]/3600;
longdoublerise,set;
rise=result_rise(UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);
set=result_set(UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);
output(rise,set,glong);
system("pause");
return0;
}