⑴ 設計一個火車訂票系統(c語言程序)求大神幫忙!
你這要求也太復雜了,等著吧
⑵ C語言問題---設計車票售票系統
4565463v剎徐州
⑶ C語言課程設計 簡單的汽車售票系統 幫忙啊!!!!!
本來想向你多勒索點分再給你發,沒想到你的積分是-6分,無語了。
使用的時候先在D盤根目錄下建一個空文件file.dat,應該就可以用了。第四項和第五項你自己想法做吧。
#include<stdio.h>
int showmenu()
{
int a;
printf("**********************\n");
printf("1、訂票\n");
printf("2、退票\n");
printf("3、顯示訂票情況\n");
printf("4、保存當天數據\n");
printf("5、退出\n");
printf("**********************\n");
printf("請選擇操作\n");
scanf("%d",&a);
return a;
}
void display(int*bus)
{
printf("車次 發車時間 載客量 已售票\n");
printf("1、 06:40 50 %d\n",*bus);
printf("2、 09:30 40 %d\n",*(bus+1));
printf("3、 13:00 40 %d\n",*(bus+2));
printf("4、 16:00 40 %d\n",*(bus+3));
printf("5、 20:50 50 %d\n",*(bus+4));
}
void order(int*bus)
{
int a;
int capacity[5]={50,40,40,40,50};
display(bus);
printf("請選擇要訂的車次\n");
scanf("%d",&a);
if(a>5||a<1)
printf("你選擇了錯誤的序號\n");
else if(*(bus+a-1)>=capacity[a-1])
printf("該路車的票已售罄\n");
else
{
*(bus+a-1)+=1;
printf("訂票成功\n");
}
}
void cancel(int*bus)
{
int a;
display(bus);
printf("請選擇要取消訂票的車次\n");
scanf("%d",&a);
if(a>5||a<1)
printf("你選擇了錯誤的序號\n");
else if(*(bus+a-1)<1)
printf("該路車尚無人訂票\n");
else
{
*(bus+a-1)-=1;
printf("退票成功\n");
}
}
void writefile(int*bus)
{
FILE *fp;
if((fp=fopen("D:\\file.dat","wb"))==0)
{
printf("打不開文件\n");
exit(0);
}
fwrite(bus,sizeof(int),5,fp);
fclose(fp);
}
void readfile(int*bus)
{
int i;
FILE *fp;
if((fp=fopen("D:\\file.dat","rb"))==0)
{
printf("打不開文件\n");
exit(0);
}
for(i=0;i<5;i++)
{
if(!feof(fp))
fread(bus+i,sizeof(int),1,fp);
}
fclose(fp);
}
void main()
{
int bus[5]={0,0,0,0,0};
int a;
readfile(bus);
a=showmenu();
while(a!=5)
{
switch(a)
{
case 1:order(bus);break;
case 2:cancel(bus);break;
case 3:display(bus);break;
case 4:writefile(bus);break;
default:printf("你選擇了錯誤的序號\n");break;
}
a=showmenu();
}
writefile(bus);
}
⑷ c語言程序設計 民航訂票系統
//#include<stdafx.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef int status;
typedef struct airline
{
char flight_num[8]; /*航班號*/
char plane_num[8]; /*飛機號*/
char destination[20]; /*目的地*/
int total; /*座位總數*/
int left; /*剩餘座位*/
struct airline *next; /*下一個結點*/
}airline;
typedef struct customer
{
char name[9]; /*顧客名*/
char flight_num[8]; /*航班號*/
int seat_num; /*座位號*/
struct customer *next; /*下一個結點*/
}customer;
airline *init_airline()
{ /*初始化鏈表*/
airline *l;
l=(airline*)malloc(sizeof(airline));
if(l==NULL)
{ exit(0);
}
l->next=NULL;
return l;
}
customer * init_customer()
{ /*初始化鏈表*/
customer *l;
l=(customer*)malloc(sizeof(customer));
if(l==NULL){
exit(0);
}
l->next=NULL;
return l;
}
status insert_airline(airline **p,char *flight_num,char *plane_num,char *destination,int total,int left)
{ /*airline鏈表插入操作*/
airline *q;
q=(airline*)malloc(sizeof(airline)); /*初始化*/
strcpy(q->flight_num , flight_num); /*拷貝信息*/
strcpy(q->plane_num , plane_num);
strcpy(q->destination , destination);
q->total =total;
q->left =left;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return 1;
}
status insert_customer(customer **p,char *name,char *flight_num,int seat)
{ /*customer信息插入操作*/
customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name , name); /*顧客信息拷貝*/
strcpy(q->flight_num , flight_num);
q->seat_num =seat;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return 1;
}
airline *modefy_airline(airline *l,char *flight_num) /*修改airline中的數據*/
{ airline *p;
p=l->next ;
for(;p!=NULL;p=p->next )
{ if(strcmp(flight_num,p->flight_num )==0) /*查找*/
{ p->left ++;
return l;
}
}
printf("No this flight,can't make correction!\n"); /*查找失敗*/
return 0;
}
status delete_airline(airline *h,char *flight_num) /*刪除航班*/
{ airline *p,*pr;
pr=h;
p=pr->next ;
while(p!=NULL)
{ if(strcmp(flight_num,p->flight_num )==0) /*信息匹配*/
{ pr->next =p->next ;
printf("Delete %s flight\n",p->flight_num );
return 1;
}
pr=pr->next ;
p=pr->next ;
}
printf("No this flight,can't delete!\n"); /*無該信息*/
return 0;
}
status delete_customer(customer *h,char *flight_num) /*顧客信息刪除*/
{ customer *p,*pr;
pr=h;
p=pr->next ;
while(p!=NULL)
{ if(strcmp(flight_num,p->flight_num )==0) /*信息匹配*/
{ pr->next =p->next ; }
pr=pr->next ;
p=pr->next ;
}
return 1;
}
status delete_cus(customer *h,airline *l,char *name) /*顧客退票*/
{ customer *p,*pr;
char flight_num[8];
pr=h;
p=pr->next ;
while(p!=NULL)
{ if(strcmp(name,p->name )==0) /*找顧客姓名*/
{ strcpy(flight_num,p->flight_num ); /*找航班號*/
l=modefy_airline(l,flight_num); /*修改該航班信息*/
pr->next =p->next ;
printf("Customer %s return tickets successed!\n",p->name );
return 1;
}
pr=pr->next ;
p=pr->next ;
}
printf("No this customer,can't return!\n");
return 0;
}
status save_airline(airline *l) /*保存airline.dat*/
{ FILE *fp_airline;
char ch='#';
airline *p=l->next ;
char filename[]="c:\\airline.dat"; /*尋找C盤中的航班信息文件*/
if((fp_airline=fopen(filename,"wb"))==NULL)
{ printf("can not open file to write:%s\n",filename);
return 0;
}
for(;p!=NULL;p=p->next )
{ fprintf(fp_airline,"%s,%s,%s,%d,%d,%c",p->flight_num,p->plane_num,p->destination,p->total,p->left,ch);
fflush(stdin);
}
fclose(fp_airline);
return 1;
}
status save_customer(customer *l) /*保存顧客信息 customer.dat*/
{ FILE *fp_customer;
char ch='#';
customer *p=l->next ;
char filename[]="c:\\customer.dat"; /*尋找C盤中的顧客信息文件*/
if((fp_customer=fopen(filename,"wb"))==NULL)
{ printf("can not open file to write:%s\n",filename);
return 0;
}
for(;p!=NULL;p=p->next )
{ fprintf(fp_customer,"%s,%s,%d%c",p->name ,p->flight_num ,p->seat_num ,ch);
}
fclose(fp_customer);
return 1;
}
int changStrInt(char *ch) //把字元串轉化為整型
{ int a=1,b=0,c=0,i;
for (i=strlen(ch)-1;i>=0;i--)
{ if (ch[i]<='9'&&ch[i]>='0')
{ b=a*(ch[i]-'0');
a=a*10;
c=c+b;
}
else
{ printf("%c不合法,無法將此字元轉化為整形!\n",ch[i]);
return 0;
}
}
return c;
}
status insert_air(airline *l,char *flight_num,char *plane_num,char *destination,int total,int left)
{ /*airline鏈表插入操作*/
airline *q;
q=(airline*)malloc(sizeof(airline));
strcpy(q->flight_num , flight_num);
strcpy(q->plane_num , plane_num);
strcpy(q->destination , destination);
q->total =total;
q->left =left;
q->next=l->next ;
l->next=q;
return 1;
}
status insert_cus(customer *l,char *name,char *flight_num,int seat)
{ /*customer鏈表插入操作*/
customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name , name);
strcpy(q->flight_num , flight_num);
q->seat_num =seat;
q->next=l->next ;
l->next=q;
return 1;
}
status load_airline(airline *l) /*讀入文件中航班信息*/
{ FILE *fp_airline;
int flag=0,i=0;
char ch;
char flight_num[8]="\0"; /*航班號*/
char plane_num[8]="\0"; /*飛機號*/
char destination[20]="\0"; /*目的地*/
char total_str[5]="\0";
char left_str[5]="\0";
int total; /*座位總數*/
int left; /*剩餘座位*/
char filename[]="c:\\airline.dat";
if((fp_airline=fopen(filename,"r"))==NULL)
{ printf("can not open file to load:%s\n",filename);
return 0;
}
while(!feof(fp_airline))
{ ch=fgetc(fp_airline);
if(ch!='#')
{ if(flag==0&&ch!=',')
{ flight_num[i]=ch; i++; }
else if(flag==1&&ch!=',')
{ plane_num[i]=ch; i++; }
else if(flag==2&&ch!=',')
{ destination[i]=ch; i++; }
else if(flag==3&&ch!=',')
{ total_str[i]=ch; i++; }
else if(flag==4&&ch!=',')
{ left_str[i]=ch; i++; }
else if (ch==',')
{
if(flag==0)
flight_num[i]='\0';
else if(flag==1)
plane_num[i]='\0';
else if(flag==2)
destination[i]='\0';
else if(flag==3)
total_str[i]='\0';
else
left_str[i]='\0';
flag++; i=0;
}
}
else
{ flag=0; i=0;
total=changStrInt(total_str);
left=changStrInt(left_str);
printf("%8s%8s%8s%9d%9d\n",flight_num ,plane_num ,destination ,total ,left );
fflush(stdin);
////insert_air(l,flight_num,plane_num,destination,total,left);
}
}
fclose(fp_airline);
return 1;
}
status load_customer(customer *l) /*從文件讀入顧客信息*/
{ FILE *fp_customer;
int flag=0,i=0;
char ch;
char name[9]="\0";
char flight_num[8]="\0"; /*航班號*/
char seat_num_str[5]="\0";
int seat_num; /*座位*/
char filename[50]="c:\\customer.dat";
if((fp_customer=fopen(filename,"r"))==NULL)
{ printf("can not open file to load:%s\n",filename);
return 0;
}
while(!feof(fp_customer))
{ ch=fgetc(fp_customer);
if(ch!='#')
{ if(flag==0&&ch!=',')
{ name[i]=ch; i++; }
else if(flag==1&&ch!=',')
{ flight_num[i]=ch; i++; }
else if(flag==2&&ch!=',')
{ seat_num_str[i]=ch; i++; }
else if (ch==',')
{ if(flag==0)
name[i]='\0';
else if(flag==1)
flight_num[i]='\0';
else seat_num_str[i]='\0';
flag++; i=0;
}
else
{ printf("ERROR\n"); return 0; }
}
else
{ flag=0; i=0;
seat_num=changStrInt(seat_num_str);
printf("%15s %15s %10d\n",name ,flight_num ,seat_num );
fflush(stdin);
////insert_cus(l,name,flight_num,seat_num);
}
}
fclose(fp_customer);
return 1;
}
status creat_airline(airline **l) /*創建airline單鏈表*/
{ airline *p=*l;
int i=0;
char *flight_num[3]={"bjnc01","bjsh02","shgz03"};
char *plane_num[3]={"plane1","plane2","plane3"};
char *destination[3]={"nc","sh","gz"};
int total[3]={100,100,100};
int left[3]={51,50,78};
for (i=0;i<3;i++){
insert_airline(&p,flight_num[i],plane_num[i],destination[i],total[i],left[i]);
}
return 1;
}
status creat_customer(customer **l) /*創建customer單鏈表*/
{ customer *p=*l;
int i=0;
char *name[3]={"yuyang","lucy","fanhong"};
char *flight_num[3]={"bjnc01","bjsh02","shgz03"};
int seat_num[3]={19,15,10};
for (i=0;i<3;i++){
insert_customer(&p,name[i],flight_num[i],seat_num[i]);
}
return 1;
}
status increase_air(airline *l,char *flight_num,char *plane_num,char *destination,int total) /*增加航線*/
{ airline *p=l->next ;
for(;p->next !=NULL;p=p->next){}
insert_airline(&p,flight_num,plane_num,destination,total,total);
printf("Adding flight %s successed!\n",flight_num);
return 1;
}
status book(airline *l,char *flight_num,customer *c,char *name) /*訂票函數*/
{ airline *p=l;
customer *q=c->next ;
p=l->next ;
for(;q->next !=NULL;q=q->next){}
for(;p!=NULL;p=p->next )
{ if(strcmp(flight_num,p->flight_num )==0)
{ if(p->left >0)
{ printf("Congratulations!Tickets booked!\n");
printf("Your seat_number is: %d\n",(p->total -p->left +1));
insert_customer(&q,name,flight_num,p->total -p->left +1);
p->left --;
return 1;
}
else printf("Sorry!Seats full!\n");
return 0;
}
}
printf("Sorry!No this flight!\n");
return 0;
}
status print_airline(airline *l) /*列印航線信息*/
{ airline *p=l->next ;
for(;p!=NULL;p=p->next )
{ printf("%8s%8s%8s%9d%9d\n",p->flight_num ,p->plane_num ,p->destination ,p->total ,p->left );
}
return 1;
}
status print_customer(customer *l) /*列印顧客信息*/
{
customer *p=l->next ;
for(;p!=NULL;p=p->next )
{ printf("%10s %10s %d\n",p->name ,p->flight_num ,p->seat_num );
}
return 1;
}
void main()
{ char choice,name[9],flight_num[8];
int t=1,k=1;
airline *air=init_airline();
customer *cus=init_customer();
printf("Airline Tickets Book System\n");
printf(" \n");
creat_airline(&air);
creat_customer(&cus);
while(t==1)
{ printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
printf("**Welcome To Airline Tickets Book System**\n");
printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
printf("########################################\n");
printf("----++++++++-------主菜單-----++++++++++-------\n");
printf("# 訂票-------0 #\n");
printf("# 退票-------1 #\n");
printf("#查詢-------2 #\n");
printf("#信息載入---3 #\n");
printf("#退出------4 #\n");
printf("###################################\n");
if(k) { printf("請選擇相應操作: \n"); k=0; }
else printf("請選擇相應操作:\n");
choice = getch();
printf("%c\n",choice);
if(choice=='0')
{ printf("Please input your flight number: ");
scanf( "%s",flight_num);
printf("Please input your name: ");
scanf( "%s",name);
book(air,flight_num,cus,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='1')
{ printf("\nPlease input your name: ");
scanf( "%s",name);
delete_cus(cus,air,name);
save_airline(air);
save_customer(cus);
}
else if(choice=='2')
{ printf("\n flight_number plane_number destination total tickets_num left tickets_num\n");
print_airline(air);
printf(" name flight_number seat_number\n");
print_customer(cus);
}
else if(choice=='3')
{ printf("flight_num plane_num destination total left\n" );
load_airline(air);
printf("\t name \t\tflight_num\tseat_num \n");
load_customer(cus);
}
else if(choice=='4')
{ printf("Good bye!Please enjoy your travel!");
t=0;
}
else
{ printf("Input error!\n");
}
}
getch();
}
代碼全給你了,課設自己寫,呵呵
⑸ 一個非常簡單的C語言編程題目(車票售票系統),可加分
做這個要花製作人好幾天的時間啊。我是會做,並且還可以根據需要美化界面等等,只是耗時間來做東西傷不起啊。
⑹ 飛機訂票系統設計 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語言實現。
有啊,但很長
這里有個文檔,你參考一下:
一個簡單的火車票售票管理系統
http://wenku..com/view/1fd7a1707fd5360cba1adb72.html
⑻ 用C語言編寫火車售票系統
如果誰能用C語言能把這么題目就這樣順利的編出來的話,他已經是編程高手了,這太高級了
⑼ 求c語言,電影院售票管理系統的設計與實現的代碼
#include<stdio.h>
#include<stdlib.h>
structcell
{
char*name;
inttime;
intseat;
intsaled;
}a,b,c,d;
intsel=0;
voidtitle();
voidsaleproc();
intsaleThread(structcell*ce,intdd);
voidtiupiaoproc();
inttiupiaoThread(structcell*ce);
voidcount();
intinit(structcell*ce,char*name,inttime,intseat)
{
ce->name=name;
ce->time=time;
ce->seat=seat;
ce->saled=0;
return1;
}
intsaleThread(structcell*ce,intdd)
{
if((ce->seat-ce->saled)>=dd)
{
ce->saled+=dd;
printf("售票成功!按ESC鍵返回主菜單 ");
fflush(stdin);
intcc=_getche();
return1;
}
else
{
printf("售票失敗---余票不足!按ESC鍵返回主菜單 ");
fflush(stdin);
intcc=_getche();
return0;
}
}
voidsaleproc()
{
intf=1;
while(f)
{
system("cls");
printf("*********************************** ");
printf("** ");
printf("*廳影片時間余票* ");
printf("** ");
printf("*A%s%d:%d%3d* ",a.name,a.time/60,a.time%60,a.seat-a.saled);
printf("** ");
printf("*B%s%d:%d%3d* ",b.name,b.time/60,b.time%60,b.seat-b.saled);
printf("** ");
printf("*C%s%d:%d%3d* ",c.name,c.time/60,c.time%60,c.seat-c.saled);
printf("** ");
printf("*D%s%d:%d%3d* ",d.name,d.time/60,d.time%60,d.seat-d.saled);
printf("** ");
printf("*********************************** ");
printf("請選擇放映廳(a,b,c,d)和要購的票數(按ESC鍵返回主菜單)(格式:a5): ");
fflush(stdin);
charcc;
intdd;
dd=_getche();
if(dd==27)
{
f=0;
break;
}
else
{
cc=(char)dd;
}
scanf("%d",&dd);
switch(cc)
{
case'a':
saleThread(&a,dd);
f=0;
break;
case'b':
saleThread(&b,dd);
f=0;
break;
case'c':
saleThread(&c,dd);
f=0;
break;
case'd':
saleThread(&d,dd);
f=0;
break;
default:
break;
}
}
title();
}
inttiupiaoThread(structcell*ce)
{
if(ce->saled==0)
{
printf("撞尼瑪鬼了老子一張票都沒賣,哪來的退票??? ");
fflush(stdin);
intcc=_getche();
return0;
}
ce->saled--;
printf("退票成功!按任意鍵返回主菜單 ");
fflush(stdin);
intcc=_getche();
return1;
}
voidtiupiaoproc()
{
intf=1;
while(f)
{
system("cls");
printf("*********************************** ");
printf("** ");
printf("*退票* ");
printf("** ");
printf("*A%-20s* ",a.name);
printf("** ");
printf("*B%-20s* ",b.name);
printf("** ");
printf("*C%-20s* ",c.name);
printf("** ");
printf("*D%-20s* ",d.name);
printf("** ");
printf("*********************************** ");
printf("請輸入要退的廳(a,b,c,d): ");
charcc;
fflush(stdin);
scanf("%c",&cc);
if(cc=='')
{
f=0;
break;
}
switch(cc)
{
case'a':
tiupiaoThread(&a);
f=0;
break;
case'b':
tiupiaoThread(&b);
f=0;
break;
case'c':
tiupiaoThread(&c);
f=0;
break;
case'd':
tiupiaoThread(&d);
f=0;
break;
default:
break;
}
}
title();
}
voidcountproc()
{
intf=1;
while(f)
{
system("cls");
printf("*********************************** ");
printf("** ");
printf("*統計* ");
printf("** ");
printf("*A廳:余票%3d上座率%5.2f%%* ",a.seat-a.saled,(((float)a.saled/(float)a.seat)*100));
printf("** ");
printf("*B廳:余票%3d上座率%5.2f%%* ",b.seat-b.saled,(((float)b.saled/(float)b.seat)*100));
printf("** ");
printf("*C廳:余票%3d上座率%5.2f%%* ",c.seat-c.saled,(((float)c.saled/(float)c.seat)*100));
printf("** ");
printf("*D廳:余票%3d上座率%5.2f%%* ",d.seat-d.saled,(((float)d.saled/(float)d.seat)*100));
printf("** ");
printf("*********************************** ");
printf("按ESC鍵返回主菜單! ");
fflush(stdin);
intcc=_getche();
if(cc==27)
{
f=0;
break;
}
}
title();
}
voidtitle()
{
intf=1;
while(f)
{
system("cls");
printf("*********************************** ");
printf("** ");
printf("*歡迎光臨牛B電影院* ");
printf("** ");
printf("*1.售票* ");
printf("** ");
printf("*2.退票* ");
printf("** ");
printf("*3.統計* ");
printf("** ");
printf("*4.退出* ");
printf("** ");
printf("*********************************** ");
printf("請選擇:(1,2,3,4) ");
fflush(stdin);
scanf("%d",&sel);
getchar();
switch(sel)
{
case1:
saleproc();
f=0;
break;
case2:
tiupiaoproc();
f=0;
break;
case3:
countproc();
f=0;
break;
case4:
system("exit");
f=0;
break;
default:
break;
}
}
}
intmain(intargc,char*argv[])
{
init(&a,"鋼鐵俠3",18*60+30,150);
init(&b,"致青春",19*60+30,150);
init(&c,"姜戈",20*60+30,150);
init(&d,"生化危機4",20*60+20,100);
title();
return0;
}
⑽ C語言程序設計之航空售票系統
你用什麼編輯C?可以支持中文操作嗎?