?? 航班輸入.cpp
字號(hào):
#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct flight
{
char num[20];
char startcity[20];
char arrivecity[20];
char starttime[20];
char arrivetime[20];
float price;
int totaltickets,left;
float discount;
struct flight *next;
};
struct person
{char name[30][20];
char ID[30][30];
int tickets[30];
char ticketsid[30];
struct person *next;
};
struct flight *first,*p,*q;
struct person *first1,*j,*k;
int m=0;
void input();
void save();
void input()
{int i,y;
printf("請(qǐng)依次輸入航班信息,完成輸入信息后請(qǐng)按照提示鍵入0以回車鍵結(jié)束\n");
first=(struct flight*)malloc(sizeof(struct flight));
first1=(struct person*)malloc(sizeof(struct person));
p=first;
j=first1;
for(i=0;i<30;i++)
{ q=(struct flight*)malloc(sizeof(struct flight));
k=(struct person*)malloc(sizeof(struct person));
printf("請(qǐng)輸入航班號(hào): ");
scanf("%s",p->num);
printf("請(qǐng)輸入起始城市: ");
scanf("%s",p->startcity);
printf("請(qǐng)輸入抵達(dá)城市: ");
scanf("%s",p->arrivecity);
printf("請(qǐng)輸入起始時(shí)間: ");
scanf("%s",p->starttime);
printf("請(qǐng)輸入到達(dá)時(shí)間: ");
scanf("%s",p->arrivetime);
printf("請(qǐng)輸入機(jī)票價(jià)格: ");
scanf("%d",&p->price);
printf("請(qǐng)輸入機(jī)票折扣: ");
scanf("%d",&p->discount);
printf("請(qǐng)輸入總的機(jī)票數(shù)(機(jī)票數(shù)為0結(jié)束輸入): ");
scanf("%d",&p->totaltickets);
p->left=p->totaltickets;
p->next=q;
p=p->next;
j->next=k;
j=j->next;
m++;
printf("第%d個(gè)信息已經(jīng)輸完是否繼續(xù)?按任意鍵繼續(xù),按0結(jié)束",m);
scanf("%d",&y);
if(y==0) break;
}
save();
}
void save()
{int i;
FILE *fp,*fp1,*fp2;
if((fp=fopen("f:\\flight.txt","wb+"))==NULL)
{
printf("創(chuàng)建文件失敗! ");
getchar();
exit(0);
}
if((fp1=fopen("f:\\person.txt","wb+"))==NULL)
{
printf("創(chuàng)建文件失敗! ");
getchar();
exit(0);
}
if((fp2=fopen("f:\\m.txt","wb+"))==NULL)
{
printf("創(chuàng)建文件失敗! ");
getchar();
exit(0);
}
p=first;
j=first1;
for(i=0;i<m;i++)
{
fwrite(p,sizeof(struct flight),1,fp);
fwrite(j,sizeof(struct person),1,fp1);
p=p->next;
j=j->next;
}
fwrite(&m,sizeof(int),1,fp2);
fclose(fp);
fclose(fp1);
fclose(fp2);
}
void main()
{printf("請(qǐng)輸入航班初始數(shù)據(jù)建立航班信息數(shù)據(jù)庫(kù):\n");
input();
};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -