人人范文网 范文大全

火车票查询系统代码(全文)

发布时间:2020-03-03 13:53:28 来源:范文大全 收藏本文 下载本文 手机版

#include #include #include #include int shoudsave=0 ,mark=0 ; cla train { char num[10]; // 列车号 char city[10]; // 目的城市 char chufatime[10]; // 出发时间 char daodatime[10]; // 到达时间 double price; // 票价 int booknum ; // 票数 public:

ime);

ime);

num;} city;}

*getchufatime(){return chufatime;}

*getdaodatime(){return daodatime;} price;}

(){return booknum;}

train() { }

train(train &t) { strcpy(num,t.num); strcpy(city,t.city); strcpy(chufatime,t.chufat

strcpy(daodatime,t.daodat price=t.price; booknum=t.booknum;

}

~train(){}

char *getnum(){return char *getcity(){return char char

double getprice(){return int

getbooknum void fuzhi(char *num2,char *city2,char *chufa, char *daoda,double price2,int booknum2) { strcpy(num,num2); strcpy(city,city2); strcpy(chufatime,chufa); strcpy(daodatime,daoda); price=price2; booknum=booknum2; }

};

typedef struct node // 定义火车信息链表的结点结构 { train data ; struct node * next ; }Node,*Link ;

void tianjiatrain(Link linkhead) //添加火车信息 { char num[10]; // 列车号 char city[10]; // 目的城市 char chufatime[10]; // 出发时间 char daodatime[10]; // 到达时间 double price; // 票价 int booknum ; struct node *p,*r,*s ;//定义指向火车信息链表的3个指针

r = linkhead ; s = linkhead->next ; while(r->next!=NULL) r=r->next ; while(1) { cout>num; if(strcmp(num,\"0\")==0) //strcmp,串比较函数,用于判断num是否为0 break ; while(s) // 判断是否已经存在 { if(strcmp(s->data.getnum(),num)==0)//strcmp,串比较函数,用于判断data->num是否与num相同

{ coutnext ; } p = (struct node*)malloc(sizeof(struct node)); //malloc,内存分配函数 cout>city; cout>chufatime; cout>daodatime; cout>price; cout>booknum; p->data.fuzhi(num,city,chufatime,daodatime,price,booknum); p->next=NULL ; r->next=p ; r=p ; shoudsave = 1 ; } }

void showtrainxinxi(struct node*p) // 输出火车票信息 { coutdata.getnum()data.getcity()data.getchufatime()data.getdaodatime()data.getprice()data.getbooknum()

struct node * Locate1(Link l,char findme[],char numorcity[])//查询方式子函数 { Node*r ; if(strcmp(numorcity,\"num\")==0) //strcmp,串比较函数,用于判断 { r=l->next ; while(r) { if(strcmp(r->data.getnum(),findme)==0) return r ; r=r->next ; } } else if(strcmp(numorcity,\"city\")==0) { r=l->next ; while(r) { if(strcmp(r->data.getcity(),findme)==0) return r ; r=r->next ; } } return 0 ; }

void chaxuntrain(Link l) // 查询火车信息 { char t=\'y\'; while(t==\'y\') { Node *p ; int sel ; //查询方式代号(1和2) char str1[5],str2[10]; if(!l->next) //指向链表的最后尾段,即没有记录

{cout> sel; if(sel==1) { cout>str1; p=Locate1(l,str1,\"num\"); if(p) {showtrainxinxi(p); } else {mark=1 ; cout>str2; p=Locate1(l,str2,\"city\"); if(p) {showtrainxinxi(p); } else {mark=1 ; cout>t; }}

void baocuntrain(Link l) // 保存火车信息 { FILE*fp ; Node*p ; int count=0,flag=1 ; fp=fopen(\"E: rain.txt\",\"wb\"); //打开文件train.txt if(fp==NULL) { coutnext ; while(p) { if(fwrite(p,sizeof(Node),1,fp)==1) //fwrite,写内容(Node)到流中,c库函数,

{ p=p->next ; count++; } else { flag=0 ; break ; } } if(flag) { cout

int main() { FILE*fp1 ; Node*p,*r ; Link l ; int sel ; l=(Node*)malloc(sizeof(Node)); //malloc,内存分配函数,c库函数 l->next=NULL ; r=l ;

fp1=fopen(\"E: rain.txt\",\"ab+\");//fopen,打开一个流,c库函数 if((fp1==NULL)) { coutnext=NULL ; r->next=p ; r=p ;

} } fclose(fp1); while(1) {cout

\\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3\"

\\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3 \\3\\3\">sel; switch(sel) {case 1 :

tianjiatrain(l);break ; case 2 : baocuntrain(l);break ; chaxuntrain(l);break ; case 4 :return 0; } } return 0; }

case 3 :

火车票售票系统

火车票订票系统

火车票代售点查询接口 全国火车票代售点查询

电话查询系统

驾驶证查询系统

系统档案查询

软件工程 通讯录查询系统

发票验证查询系统

自助语音查询系统

C++同学录查询系统

火车票查询系统代码(全文)
《火车票查询系统代码(全文).doc》
将本文的Word文档下载到电脑,方便编辑。
推荐度:
点击下载文档
点击下载本文文档