数据结构课设-订票系统源代码
- 格式:docx
- 大小:22.07 KB
- 文档页数:16
#include
#include
#include
#include
#define maxrailway 100
#define maxorder 1000
typedef struct Time
{
int month; //月
int day; //日
int hour; //小时
int minute; //分钟
}Time, *Ptime;
typedef struct Railway
{
char Num[15]; //列车号
char corp[15]; //铁路公司名称
char rail[15]; //列车车型
char from[15]; //始发站点
char to[15]; //终点站
Ptime takeoff; //发车时间
Ptime arrive; //到站时间
int price; //票价
float discount; //折扣,小于100大于0的浮点数
int vaculmn; //乘客容量
int rest; //剩余座位数
struct Railway *next;
}Railway, *Pst_Rail;
typedef struct Order
{
char Num[15]; //列车号
char cusname[20]; //乘客姓名
char IDcardnum[20];//乘客身份证号
int ticketnum; //订票总数
int num; //订单编号
struct Order *next;
}Order, *Pst_Order;
FILE *data, *order; //分别保存列车线路记录和订单记录
Pst_Rail head_rail; //列车链表表头
Pst_Order head_order; //订单链表表头 int flag; //退出操作的标记
int numofrail; //记录列车线路数目
int numoforder; //记录订单数目
int lastorder; //记录最后一个订单的序号
void pause()
{
int t, now_time;
now_time = clock(); //取出当前时间
for(;(t = (clock() - now_time)) < 2 * (CLOCKS_PER_SEC););
system("cls"); //在pause()函数中放一个清屏函数
}
//时钟程序,用来控制用户界面的输出,每两个界面中间暂停2秒钟
void Inuput()
{
int i;
Pst_Rail p, q;
p = head_rail;
for(i = 0;i < numofrail;i++)p = p->next;
q = (Pst_Rail)malloc(sizeof(Railway));
q->takeoff = (Ptime)malloc(sizeof(Time));
q->arrive = (Ptime)malloc(sizeof(Time));
p->next = q;
// 为记录开辟空间
printf("Please input Railway information:\n");
printf("Number:\tCorparation:\tType of railway:\n");
scanf("%s%s%s",q->Num,q->corp,q->rail);
//输入列车线路的车号、铁路公司名称、列车车型
printf("\nPassenger vaculmn:\tTake off position:\tArrive position:\n");
scanf("%d%s%s",&q->vaculmn,q->from,q->to);
//输入列车的乘客容量、始发、终点
q->rest = q->vaculmn;
//剩余的座位初始时为乘客容量
printf("\nTake off time:\tArrive time:\tPrice:\tDiscount:\nTime e.g.:6/25 12:30\n");
scanf("%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeoff->minute);
scanf("%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->minute);
//输入列车发车的时间和到站时间
scanf("%d%f",&q->price,&q->discount);
//输入车票价格和折扣
numofrail += 1;
}
void File_Scanf_Data()
{
Pst_Rail p, q;
p = head_rail;
while(!feof(data))
{
q = (Pst_Rail)malloc(sizeof(Railway));
q->takeoff = (Ptime)malloc(sizeof(Time));
q->arrive = (Ptime)malloc(sizeof(Time)); // 为记录开辟空间
fscanf(data,"%s%s%s",q->Num,q->corp,q->rail);
fscanf(data,"%d%s%s",&q->vaculmn,q->from,q->to);
fscanf(data,"%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeoff->minute);
fscanf(data,"%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->minute);
fscanf(data,"%d%f%\n",&q->price,&q->discount);
q->next = NULL;
numofrail += 1;
p->next = q;
p = p->next;
} //从文件中读取列车线路记录
}
void File_Scanf_Order()
{
Pst_Order p, q;
p = head_order;
while(!feof(order))
{
q = (Pst_Order)malloc(sizeof(Order)); // 为记录开辟空间
fscanf(order,"NO.%d: %s\t%s\t%d tickets for
railway :%s\n",&q->num,q->cusname,q->IDcardnum,&q->ticketnum,q->Num);
q->next = NULL;
numofrail += 1;
p->next = q;
p = p->next;
} //从文件中读取订单记录
}
void File_write()
{
Pst_Rail p;
Pst_Order q;
p = head_rail;
q = head_order;
while(p->next != NULL)
{
p = p->next;
fprintf(data,"%s %s %s\n",p->Num,p->corp,p->rail);
fprintf(data,"%d %s %s\n",p->vaculmn,p->from,p->to);
fprintf(data,"%d/%d %d:%d -
",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);
fprintf(data,"%d/%d %d:%d",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute);
fprintf(data,"%d %.2f%%\n",p->price,p->discount);
}
while(q->next!=NULL)
{
q = q->next;
fprintf(order,"NO.%d: %s\t%s\t%d tickets for
railway :%s\n",q->num,q->cusname,q->IDcardnum,q->ticketnum,q->Num);
}
} //向文件中写入数据
void Change_item(int n)
{
int i, choose;
Pst_Rail p;
p = head_rail;
for(i = 0;i < n;i++)p = p->next;
printf("Which item do you want to change?\n");
printf("0: Number\n1: Corparation\n2: Type of railway\n3: Passenger vaculmn\n\
4: Take off position\n5: Arrive position\n6: Take off time\n7: Arrive time\n\
8: Price\n9: Discount\n\n");
scanf("%d",&choose);
system("cls");
switch(choose)
{
case 0:
{
printf("The old Number is %s\nPlease input the new one:\n",p->Num);