首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮帮忙~

2012-02-13 
各位大哥帮帮忙~~~#includestdio.h#includestdlib.h#includestring.h#includectype.h#include co

各位大哥帮帮忙~~~
#include   <stdio.h>
#include   <stdlib.h>
#include   <string.h>
#include   <ctype.h>
#include <conio.h>
#define   SIZE   200
int   flag;
struct   flight                                           /*定义结构体*/
{
    char   distination[10];
    char   price[7];
    char   month[5];
    char   day[5];
    char   year[5];
    char   hour[5];
    char   minute[5];  
}flights[SIZE];

void   save()                                               /*把结构体的内容保存到文件中*/
{  
    FILE   *fp;
    int   i=0;
    if((fp=fopen( "file.txt ", "ab "))==NULL)
        {
            printf( "cannot   open   file\n ");
            return;
        }
    for(i=0;i <SIZE;i++)
        if(fwrite(&flights[i],sizeof(struct   flight),1,fp)!=1)
{if(feof(fp)){fclose(fp);return;}
  printf( "file   read   error\n ");
}
fclose(fp);
  }
void   load()                                             /*把文件内容输出到结构体中*/
{
    FILE   *fp;
    int   i;
    fp=fopen( "file.txt ", "rb ");
    for(i=0;i <SIZE;i++)
        fread(&flights[i],sizeof(struct   flight),1,fp);
    fclose(fp);
    return;
    }  

void   input()                                           /*从键盘向结构体输入信息*/
{   void   winAdmin();
    int   i;
    int   j=1;
    for(i=0;i <SIZE;i++)
    if(j==1)
    {     printf( "请输入航班的目的地:\n ");scanf( "%s ",flights[i].distination);
          printf( "请输入机票的价格:\n ");scanf( "%s ",flights[i].price);
          printf( "请输入航班的起飞日期(月份):\n ");scanf( "%s ",flights[i].month);
          printf( "请输入航班的起飞日期(日期):\n ");scanf( "%s ",flights[i].day);
          printf( "请输入航班的起飞日期(年份):\n ");scanf( "%s ",flights[i].year);
          printf( "请输入航班的起飞时间(几点):\n ");scanf( "%s ",flights[i].hour);
          printf( "请输入航班的起飞时间(几分):\n ");scanf( "%s ",flights[i].minute);
          printf( "您还想再输入新的航班信息吗?(1.是/2.否)\n ");
          scanf( "%d ",&j);
          flag++;
    }        
    save();
    winAdmin();
}



void   output()                                 /*打印结构体内容*/
{  
    int   i;
    printf( "目的地         票价       月       日       年           时间             \n ");
    for(i=0;i <flag;i++)
        printf( "%s     %s       %s       %s       %s       %s:%s\n ",flights[i].distination,flights[i].price,flights[i].month,flights[i].day,flights[i].year,flights[i].hour,flights[i].minute);
    return;
}

void   winGuest()                               /*客户的欢迎界面*/
{void   main();
  void   search();
  int   choice;
  loop:printf( "\n\n\n\n\n\n\n\n ");         /*为了在屏幕的中间位置显示菜单,加空行*/
    printf( "                                   |******         欢迎光临SHEEP的航班查询系统     ******|\n ");
    printf( "                                   |---------------------------------------------|\n ");
    printf( "                                   |     请问您想做什么?(1~2):                                             |\n ");
    printf( "                                   |---------------------------------------------|\n ");
    printf( "                                   |                                 1----搜索航班信息                         |\n ");
    printf( "                                   |                                 2----回到主菜单                             |\n ");
    printf( "                                   |                                 3----退出                                         |\n ");
    printf( "                                   |---------------------------------------------|\n                                   ");


            scanf( "%d ",&choice);
            switch(choice)
            {
            case   1:search();break;
                case   2:main();break;
                default:printf( "您输入的选项不存在,请重新输入:\n ");goto   loop;
            }
}
void   search()                                     /*搜索航班信息*/
{     void   screening();
      int   c;
  load();
    output();
    loop:printf( "\n\n\n************************************\n           您想按目的地查找航班信息吗(1.是   2.否)? ");
    scanf( "%d ",&c);
    if(c==1)
                  screening();
      else
        if(c==2)
              {   printf( "按任意键离开 ");
                  getchar();
                  main();
              }
      else
            {
                printf( "该选项不存在,请重新选择 ");
                goto   loop;
                }      
}
void   screening()
{
      int   i,j;  
      char   dist[10];
      printf( "请输入您要查询的目的地 ");
      for(i=0;i <10;i++)
          scanf( "%c ",dist[i]);
      printf( "目的地         票价       月       日       年           时间             ");
      for(j=0;j <10;j++)
            if(strcmp(flights[j].distination,dist[j])==0)
                    printf( "%s   %s   %s   %s   %s   %s   %s ",flights[j].distination,flights[j].price,flights[j].month,flights[j].day,flights[j].year,flights[j].hour,flights[i].minute);
               
}

void   ticketimfo()  
{
}

void   winAdmin()                               /*管理员的欢迎界面*/
{
    void   main();
      int   choice;
  loop:printf( "\n\n\n\n\n\n\n\n ");         /*为了在屏幕的中间位置显示菜单,加空行*/
    printf( "                                   |******         欢迎光临SHEEP的航班查询系统     ******|\n ");
    printf( "                                   |---------------------------------------------|\n ");


    printf( "                                   |     请问您想做什么?(1~4):                                             |\n ");
    printf( "                                   |---------------------------------------------|\n ");
    printf( "                                   |                                 1----搜索航班信息                         |\n ");
    printf( "                                   |                                 2----输入新的航班信息                 |\n ");
    printf( "                                   |                                 3----查询机票订购情况                 |\n ");
    printf( "                                   |                                 4----回到主菜单                             |\n ");
    printf( "                                   |                                                                                           |\n ");
    printf( "                                   |---------------------------------------------|\n                                   ");
            scanf( "%d ",&choice);
            switch(choice)
            {
            case   1:search();break;
                case   2:input();break;
                case   3:ticketimfo();break;
                case   4:main();break;
                default:printf( "您输入的选项不存在,请重新输入:\n ");goto   loop;
            }
          }

void   main()                                      


{
  int   id,t=0;
  do{       printf( "\n\n\n\n\n\n\n\n ");
        printf( "                                   |******         欢迎光临SHEEP的航班查询系统     ******|\n\n ");
      printf( "                                   |请问您是?(1~2):                                                             |\n ");
      printf( "                                   |---------------------------------------------|\n ");
      printf( "                                   |                                 1----系统管理员                             |\n ");
      printf( "                                   |                                 2----乘客                                         |\n ");
              printf( "                                   |                                                                                           |\n ");
              printf( "                                   |                                                                                           |\n ");
      printf( "                                   |---------------------------------------------|\n                               ");
        scanf( "%d ",&id);
            if(id==1)
          winAdmin();
      else   if(id==2)
      winGuest();
      else
      printf( "the   choice   does   not   exist,please   input   again:\n ");
}while((id!=1)&&(id!=2));
       


}


[解决办法]
void screening()
{
int i,j;
char dist[10]={0};
printf( "请输入您要查询的目的地 ");
//for(i=0;i <10;i++)
// scanf( "%c ",dist[i]);
scanf( "%s ", dist);

printf( "目的地 票价 月 日 年 时间 ");
for(j=0;j <10;j++)
if(strcmp(flights[j].distination,dist)==0)
printf( "%s %s %s %s %s %s %s ",flights[j].distination,flights[j].price,flights[j].month,flights[j].day,flights[j].year,flights[j].hour,flights[j].minute);

}

热点排行