c语言车票系统报告
int FixedNumber; /*已定票数*/
struct information *next;
}INFORMATION,*PINF;
void main() /*主函数*/
{
switch(i){ case 1:{
Insert(); printf("\n按任意键回主菜单......\n");getchar();getchar();}break;/*录入*/
case 2:{Scan();printf("\n按任意键回主菜单......\n");getchar();getchar();}break;/*浏览*/
case 3:SearchMenu();break;/*查询*/
case 4:Buyticket();break;/*订票*/
case 5:TicketDelete();break;/*退票*/
p=p->next;
}
fclose(fp);
}
void Scan()
{
PINF p=head->next;
printf("\n各班次信息如下:\n");
printf("\n班次号\t出发时间\t起点\t终点\t行车时间额定载客量已订票人数\n");
printf("____________________________________________________________________________\n");
void Save_In(); //把数据重新保存到文件中
void exit(); //退出该系统
input();
int i=0;
while(i!=6)
{
printf("********************************************************\n");
printf("* Welcome to use the system of booking tickets *\n");
(5)退票:退票时,输入退票班次,当本班次未出发时才能退票,自动更新已售票人数
二.概要设计:
系统总体设计框架(系统功能模块图):
系统模块图
其中:
信息输入模块完成班次信息的输入功能,输入信息包括班次、发车时间、起点站、终点站、行车时间、额定载量、定票人数等;
信息浏览模块完成已录入信息的显示;
信息查询模块完成班次信息的查询,查询时对应有按班次查询和按终点站查询两种方式;
printf("* 2:浏览信息(scan the information)*\n");
printf("* 3:查询信息(Inquire a train information)*\n");
printf("* 4:预订车票(Book a train ticket)*\n");
printf("* 5:退订车票(quit a train ticket)*\n");
Save_In(); //保存信息
system("pause");
return 0;
}
void Insert()
{
FILE *fp;
fp=fopen("ticket.txt","r+");
INFORMATION *q;
q=(INFORMATION *)malloc(sizeof(INFORMATION));
printf("* 6:退出系统(quit the system) *\n");
printf("********************************************************\n");
//总菜单
printf("请选择你所需要的功能:");
scanf("%d",&i);
{
INFORMATION *p;
p=(INFORMATION *)malloc(sizeof(INFORMATION)); //开辟内存空间
fscanf(fp,"%d%s%s%s%f%d%d\n",&p->numb,&p->starttime,&p->begin,&p->end,&p->lasttime,&p->FixNumber,&p->FixedNumber);
exit(0);
}
PINF p=head->next;
while(p!=NULL)
{
fprintf(fp,"%d\t%s\t%s\t%s\t%.2f\t%d\t%d\n",p->numb,p->starttime,p->begin,p->end,p->lasttime,p->FixNumber,p->FixedNumber);
while(p!=NULL)
{
printf("%d\t%s\t\t%s\t%s\t%.2f\t\t%d\t\t%d\n",p->numb,p->starttime,p->begin,p->end,p->lasttime,p->FixNumber,p->FixedNumber);
p=p->next; } printf("____________________________________________________________________________\n");
{
int numb; //列车号
char starttime[10];
char begin[21];
char end[21];
float lasttime;
int FixNumber;
int FixedNumber;
struct information *next;
}INFORMATION,*PINF; //结构体类型指针
printf("请选择查询方式:");
scanf("%d", &i);
switch(i)
{
case 1: SearchbyNum(); break;
case 2: SearchbyEnd(); break;
default : printf("\n输入错误,请确保你的输入为1--2.\n");
case 6:exit();break;/*退出*/
default:printf("输入错误,请确保你的输入为1--6.\n");break;} }
系统工作程序流程:
系统的执行应从功能菜单的选择开始,依据用户的选择来进行后续的处理,直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处理。算法的流程图如下:
车票系统:
typedef struct information
{ int numb; /*列车号*/
char starttime[10]; /*发车时间*/
char begin[21]; /*起点*/
char end[21]; /*终点*/
float lasttime; /*行车时间*/
int FixNumber; /*额定载客量*/
switch(i)
{
case 1:{Insert(); printf("\n按任意键回主菜单......\n");getchar
();getchar();}break;
case 2:{Scan();printf("\n按任意键回主菜单......\n");getchar();getchar
();}break;
售票和退票模块完成车票的购买和退订的功能;
菜单选择模块完成用户命令的接收,此模块也是车票管理系统的入口,用户所要进行的各种操作均需在此模块中进行选择并进而调用其他模块实现相应的功能;
三.详细设计
数据结构:本系统中主要的数据结构就是车次的信息,包括班次、发车时间、起点站、终点站、行车时间、额定载量、定票人数等,在处理过程中各项可以作为车次的不同属性来处理。
rear->next=p; //在INFORMATION单链表中依次插入下一结点
rear=p;
rear->next=NULL;
}
fclose(fp);
}
void Save_In() //保存数据
{
FILE *fp;
if((fp=fopen("ticket.txt", "r+"))==0)
{
printf("\n打开文件错误!\n");
程序流程图
四.主要源程序代码
#include<stdio.h>
#include<stdlib.h> //标准库文件
#include<dos.h>
#include<time.h>
#include<conio.h>
#include<string.h>
typedef struct information //用typedef定义结构体为INFORMATION
printf("********************************************************\n");
printf("* You can choose the operation: *\n");