logo资料库

c语言编写的售票系统.doc

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
#include #include #include #include #include #include #define K 4 struct record { char NO[10]; char name[20]; char time[15]; int total; int sell; char leave[10]; /*起用宏定义变量 K*/ /*定义结构体类型变量*/ }QC[K]={ /*用 QC[K]表示*/ /*给数组 QC[K]赋值*/ {"A","钢铁侠 3","18:30",150,0,0}, {"B","致青春","19:30",150,0,0}, {"C","姜戈","20:00",150,0,0}, {"D","生化危机 4","20:20",150,0,0}, /*定义子函数*/ }; FILE *fp; void search(); void sell(); void tongji(); void leave(); int menu(); void writetofile(); void readfromfile(); int one(); int two(); int three(); int four(); int menu() { \n"); int c; printf(" printf(" printf(" printf(" printf(" printf(" do /*声明 fp 是一个指向 FILE 类型变量的指针*/ /*定义菜单*/ ******* 欢 迎 使 用 本 电 影 院 售 票 系 统 ******* 1.查询当前的电影及售票数\n"); 2.售票\n"); 3.退票\n"); 4.统计满座率\n"); 5.退出\n");
/*清空缓冲区*/ 请选择(1-5) !:"); /*把输入的值赋给 c*/ ******* 错 误 !******** { fflush(stdin); printf(" scanf("%d",&c); if(c<1||c>5) printf( "\n \n"); } while(c<1||c>5); return (c); } void main() { readfromfile(); for(;;) { /*主函数*/ /*打开文件*/ switch(menu()) { case 1:search(); break; case 2:sell();break; case 3:leave();break; case 4:tongji();break; case 5:exit(0); } } } void search() { int i; printf("\n\n \n"); 票数 printf(" \n"); /*查询当前的电影及售票数*/ ********** 查 询 当 前 的 电 影 及 售 票 数 ********** 场次 电影名称 放映时间 座位数量 已售 for(i=0;i
{ 已售票数 printf("\n\n printf(" \n"); 场次 for(i=0;i=0) { /*对 QC[i].NO 和 b 进行比较*/ /*判断能否买票*/ QC[i].sell=QC[i].sell+m; QC[i].total=QC[i].total-m; printf("\n******买票成功!******\n"); t--; /*更新售票数量*/ /*更新座位数量*/ } } } if(t>0) printf("\n******买票失败!******\n"); printf(" 票数 \n"); 场次 电影名称 放映时间 座位数量 已售 for(i=0;i
printf("%8s %14s %14s %14d %12d %17s\n", QC[i].NO,QC[i].name,QC[i].time,QC[i].total,QC[i].sell,QC[i].leave); } printf("请选择要退票的场次(例如:A):\n"); scanf("%s",b); printf("请输入要退的张数(例如:3):\n"); scanf("%d",&m); for(i=0;i0) { if(QC[i].sell-m>=0) { /*判断能否退票*/ QC[i].total=QC[i].total+m; QC[i].sell=QC[i].sell-m; printf("\n******退票成功!******\n"); t--; /*更新座位数量*/ /*更新售票数量*/ } } } } if(t>0) printf("\n******退票失败!******\n"); printf(" 票数 \n"); 场次 电影名称 放映时间 座位数量 已售 for(i=0;i
int i; float m; for(i=0;i0) /*文件不为空*/ { rewind(fp); /*文件位置指针移动到文件开始位置*/ for (num=0;!feof(fp) && fread(&QC[num],sizeof(struct record),1,fp);num++); return; } getch(); return; } void writetofile()//写入文件 { int i; if ((fp=fopen("p.txt","wb"))==NULL) { printf("\n\t\t 文件打开失败"); } for (i=0;i<4;i++)
{ if (fwrite(&QC[i],sizeof(struct record),1,fp)!=1) { printf("\n\t\t 写入文件错误!\n"); } } fclose(fp); } int one(void) /*与 A 场电影的时间判断*/ { int w=1; char b[20]; time_t t = time(NULL); struct tm* currentTime = localtime( &t ); if(currentTime->tm_hour*60+currentTime->tm_min-18*60-30>=10) { w--; printf("\n 钢铁侠 3 已停止退票\n"); } return w; } int two(void) /*与 B 场电影的时间判断*/ { int w=1; char b[20]; time_t t = time(NULL); struct tm* currentTime = localtime( &t ); if(currentTime->tm_hour*60+currentTime->tm_min-19*60-30>=10) { w--; printf("\n 致青春已停止退票\n"); } return w; } int three(void)/*与 C 场电影的时间判断*/ { int w=1; char b[20]; time_t t = time(NULL); struct tm* currentTime = localtime( &t ); if(currentTime->tm_hour*60+currentTime->tm_min-20*60>=10) { w--;
printf("\n 姜戈已停止退票\n"); } return w; } int four(void)/*与 D 场电影的时间判断*/ { int w=1; char b[20]; time_t t = time(NULL); struct tm* currentTime = localtime( &t ); if(currentTime->tm_hour*60+currentTime->tm_min-20*60-20>=10) { w--; printf("\n 生化危机 4 已停止退票\n"); } return w; }
分享到:
收藏