C地铁自动售票机.docx

上传人:b****2 文档编号:12652450 上传时间:2023-04-21 格式:DOCX 页数:14 大小:18.76KB
下载 相关 举报
C地铁自动售票机.docx_第1页
第1页 / 共14页
C地铁自动售票机.docx_第2页
第2页 / 共14页
C地铁自动售票机.docx_第3页
第3页 / 共14页
C地铁自动售票机.docx_第4页
第4页 / 共14页
C地铁自动售票机.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

C地铁自动售票机.docx

《C地铁自动售票机.docx》由会员分享,可在线阅读,更多相关《C地铁自动售票机.docx(14页珍藏版)》请在冰豆网上搜索。

C地铁自动售票机.docx

C地铁自动售票机

《地铁站售票机售票过程的模拟》 

 1.本题内容为:

用C语言编写一个模拟广州市地铁一号线某车站自动售票机售单程票的过程的程序。

 

 2.要求按“选到达站”→“投币“→“出票”的过程准确无误地完成一次购票操作。

 

 选到达站:

用显示菜单方式显示各车站名,然后按相应的车站编号选择; 

 投币:

按到达站的票价,可用按下一次空格键代表投入一枚一元硬币。

(不要直接按数字键); 

 出票:

用给出文字信息表示出票操作(包括退还多投的硬币信息)。

 

 3.要求能对乘客购票步骤给予提示,4.对错误操作给予提醒。

(如在规定的时间快到时未能投入足够的币额则显示催促信息,而5.规定的时间到后未能投入足够的币额者则取消本次购票操作并退还已投款项)。

 

 6.操作简便、可靠性好(7.不能遇误操作就出现退出运行程序或死机)。

 

 可以不用链表吗?

 

可以给你做个参考,有什么问题可以邮cloud_leonhart@ 

  

 #include "graphics.h" 

 #include "stdio.h" 

 #include "conio.h" 

 #include "bios.h" 

 #include "dos.h" 

 #define ENTER 7181 

 #define SPACE 14624 

 #define UP    18432 

 #define DOWN  20480 

 #define LEFT  19200 

 #define RIGHT 19712 

 #define ESC   283 

  

 int pos=0, value=1,val=1, num=0; 

 main() 

 { 

    initgraphics(); 

    initmenu(0); 

    clrwnd(180,280,500,340); 

    helpwnd(180,280,500,340, "","PRESS ANY KEY TO START...",""); 

    getche(); 

    getmenu

(1); 

    getch(); 

    closegraph(); 

 } 

 initgraphics() 

 { 

    int gmode, gdriver=DETECT; 

    initgraph(&gdriver, &gmode, "c:

\\tc"); 

 } 

 selectbox( int tx, 

    int ty, 

    int bx, 

    int by, 

    int bkcolor, 

    int bodrcolor, 

    char *num, 

    char *title, 

    char *price) 

 { 

    int lenth; 

    setviewport(tx, ty, bx, by, 0); 

    settextstyle(3,0,2); 

    setfillstyle(1,bkcolor); 

    rectangle(0,0,bx-tx, by-ty); 

    floodfill(1,1,bodrcolor); 

    outtextxy(5,6,num); 

    outtextxy(65,6,title); 

    outtextxy(250,6,price); 

 } 

 helpwnd(int tx, 

 int ty, 

 int bx, 

 int by, 

 char *helpinfo, 

 char *info, 

 char *warninfo 

 ) 

 { 

    setviewport(tx, ty, bx, by,0); 

    setfillstyle(1,BLUE); 

    settextstyle(2,0,5); 

    rectangle(0,0,bx-tx, by-ty); 

    floodfill(1,1,WHITE); 

    outtextxy(5,5,helpinfo); 

    outtextxy(5,20,info); 

    outtextxy(5,40,warninfo); 

    outtextxy(280,10,"SEC"); 

 } 

 clrwnd(int tx, int ty, int bx, int by) 

 { 

    setviewport(tx, ty, bx, by, 0); 

    clearviewport(); 

 } 

 initmenu(int posl,int bkcolor) 

 { 

    switch(posl) 

    { 

       case 0 :

 

  selectbox(180,100,500,135,GREEN,WHITE,"<1>","Rail Station A","¥1 RMB"); 

  selectbox(180,140,500,175,GREEN,WHITE,"<2>","Rail Station B","¥2 RMB"); 

  selectbox(180,180,500,215,GREEN,WHITE,"<3>","Rail Station C","¥3 RMB"); 

  selectbox(180,220,500,255,GREEN,WHITE,"<4>","Rail Station D","¥4 RMB"); 

  pos=1; 

  break; 

       case 1 :

 

  selectbox(180,100,500,135,bkcolor,WHITE,"<1>","Rail Station A","¥1 RMB"); 

  break; 

       case 2 :

 

  selectbox(180,140,500,175,bkcolor,WHITE,"<2>","Rail Station B","¥2 RMB"); 

  break; 

       case 3 :

 

  selectbox(180,180,500,215,bkcolor,WHITE,"<3>","Rail Station C","¥3 RMB"); 

  break; 

       case 4 :

 

  selectbox(180,220,500,255,bkcolor,WHITE,"<4>","Rail Station D","¥4 RMB"); 

  break; 

    } 

 } 

  

 getmenu(int sta) 

 { 

    static int start, pause=30, cur_time; 

    char str[3]; 

    struct time ti; 

    gettime(&ti); 

    if(sta==1) 

    { 

       start=ti.ti_sec+(ti.ti_min)*60; 

       cur_time=ti.ti_min*60+ti.ti_sec; 

       sta=2; 

    } 

    clrwnd(180,280,500,340); 

    helpwnd(180,280,500,340,"Please Select The Station","","You have 30 sec to control"); 

    while(value && (ti.ti_sec+ti.ti_min*60)-start < pause) 

    { 

  

       if(bioskey

(1)!

=0) 

       { 

       switch(bioskey(0)) 

       { 

  case UP :

 

     if(pos==1) 

     { 

        initmenu(4,MAGENTA); 

        initmenu(1,GREEN); 

        pos=4; 

     } 

     else 

     { 

        pos--; 

        initmenu(pos, MAGENTA); 

        initmenu(pos+1,GREEN); 

     } 

     break; 

  case DOWN :

 

     if(pos==4) 

     { 

        initmenu(1,MAGENTA); 

        initmenu(4,GREEN); 

        pos=1; 

     } 

     else 

     { 

        ++pos; 

        initmenu(pos,MAGENTA); 

        initmenu(pos-1,GREEN); 

     } 

     break; 

  case ESC :

 

       main(); 

  case ENTER :

 

     switch(pos) 

     { 

        case 1 :

 

   clrwnd(180,280,500,340); 

   helpwnd(180,280,500,340,"Station A Please Pitch ¥1 RMB","SPACE pitch coin  ESC to cancel","You have 30 sec to control"); 

   break; 

        case 2 :

 

   clrwnd(180,280,500,340); 

   helpwnd(180,280,500,340,"Station B Please Pitch ¥2 RMB","SPACE pitch coin  ESC to cancel","You have 30 sec to control"); 

   break; 

        case 3 :

 

   clrwnd(180,280,500,340); 

   helpwnd(180,280,500,340,"Station C Please Pitch ¥3 RMB","SPACE pitch coin  ESC to cancel","You have 30 sec to control"); 

   break; 

        case 4 :

 

   clrwnd(180,280,500,340); 

   helpwnd(180,280,500,340,"Station D Please Pitch ¥4 RMB","SPACE pitch coin  ESC to cancel","You have 30 sec to control"); 

   break; 

        default :

 break; 

     } 

     while(val && (ti.ti_sec+ti.ti_min*60)-start < pause) 

     { 

        gotoxy(34,21); 

        printf("%d", num); 

        if(bioskey

(1)!

=0) 

        { 

   switch(bioskey(0)) 

   { 

      case SPACE :

 

 num++; 

 if(pos==1) 

 { 

    clrwnd(180,280,500,340); 

    helpwnd(180,280,500,340,"Station A Please Pitch ¥1 RMB","SPACE pitch coin  ESC to cancel","You picth 1 coin The ticket is out"); 

    sleep

(2); 

    num=0; 

    main(); 

    break; 

 } 

 else if(pos==2) 

 { 

    if(num==2) 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station B Please Pitch ¥2 RMB","SPACE pitch coin  ESC to cancel","The ticket is out"); 

       sleep

(2); 

       num=0; 

       main(); 

       break; 

    } 

    else 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station B Please Pitch ¥2 RMB","SPACE pitch coin  ESC to cancel","You pitch   coin"); 

       break; 

    } 

 } 

 else if(pos==3) 

 { 

    if(num==3) 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station C Please Pitch ¥3 RMB","SPACE pitch coin  ESC to cancel","The ticket is out"); 

       sleep

(2); 

       num=0; 

       main(); 

       break; 

    } 

    else 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station C Please Pitch ¥3 RMB","SPACE pitch coin  ESC to cancel","You pitch   coin"); 

       break; 

    } 

 } 

 else if(pos==4) 

 { 

    if(num==4) 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station D Please Pitch ¥4 RMB","SPACE pitch coin  ESC to cancel","The ticket is out"); 

       sleep

(2); 

       num=0; 

       main(); 

       break; 

    } 

    else 

    { 

       clrwnd(180,280,500,340); 

       helpwnd(180,280,500,340,"Station D Please Pitch ¥4 RMB","SPACE pitch coin  ESC to cancel","You pitch   coin"); 

       break; 

    } 

 } 

      case ESC :

 

 num=0; 

 clrwnd(180,280,500,340); 

 getmenu

(2); 

   } 

        } 

        gettime(&ti); 

        cur_time=ti.ti_min*60+ti.ti_sec; 

        gotoxy(55,19); 

        printf("%d",cur_time-start); 

     } 

       } 

       } 

       gettime(&ti); 

       cur_time=ti.ti_min*60+ti.ti_sec; 

       gotoxy(55,19); 

       printf("%d",cur_time-start); 

       if(cur_time-start>=30) 

       { 

  clrwnd(180,280,500,340); 

  helpwnd(180,280,500,340, "","TIME OUT",""); 

  sleep

(2); 

  main(); 

       } 

    } 

 }

 

#include  

 #include  

 #include  

 #define NULL 0 

 #define pr printf 

 /*定义一 个函数时标题从左走到右*/ 

 void go() 

 {long i,j,q; 

  pr("\n"); 

  for(i=1;i<=42;i++) 

   {for(j=1;j<=i;j++) 

   pr(" "); 

   pr("Welcome to the subway train station!

 "); 

   for(q=1;q<=10000000;q++){} 

   pr("\r"); 

   

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 外语学习 > 英语考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1