| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:请看看我的程序,哪里有错,告诉我怎么修改啊,只有一个错误
只看楼主 加入收藏
梁茶恩
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-26
收藏
 问题点数:0 回复次数:0 
请看看我的程序,哪里有错,告诉我怎么修改啊,只有一个错误
#ifndef _NODE
#define _NODE
#define N 20
 struct Flight                 
{
     char company[20];
    char flightnum[10];
    char from[15];
    char destn[15];
    char starttime[12];
    char arrive[12];  
    int price;      
    int surplus;
    char late[5];   
 
 }s[N];
 typedef struct Flight Flight;
 const int sizeFli = sizeof(Flight);
 struct customer
{
    long int ID;
    char bookflightnum[10];
    int ticket;
    int lose;
}c[N];
 typedef struct customer customer;
 const int sizecustomer = sizeof(customer);
endifa

#include<stdio.h>  
#include<string.h>   
#include<stdlib.h>     
#include<time.h>      
#include<conio.h>
#include <node.h>
int h=0,m=0;  
void input();
void printall();   
void add();      
void Change();   
void delet();     
void sorttime();   
void book();     
void tuipiao();   
void search();     
void find();
void searchmenu();   
void managemenu();   
void readOut();
void creatfile();
void readcustomer();  
int comptime();
#define PRINT "%-9s%-9s%-9s%-9s%-11s%-11s%-9d%-7d%-10s\n",s[i].company,s[i].flightnum,s[i].from,s[i].destn,s[i].starttime,s[i].arrive,s[i].surplus,s[i].price,s[i].late   //瀹氫箟杈撳嚭鏍煎紡
 int main()
{
    int  j;
    system("color f4");

    readOut(s);
    printf(" 您好,欢迎进入中国民航票务管理系统 \n");
    printf("================================================================================\n");
    do
    {
        printf("        --------1. 管理员管理航班信息 ------- \n\n"
            "           --------2. 按时间排列信息------- \n\n"
            "           --------3.订票信息------- \n\n"
            "           --------4.退票信息------- \n\n"
            "           --------5.查询信息------- \n\n"
            "           --------6.浏览航班信息------- \n\n"
            "           --------0.退出------- \n\n");
        printf("================================================================================\n");
        printf("请在0-6中选择以回车键结束:\n\n");
        scanf("%d",&j);
switch(j)
        {
        case 1:   managemenu();      break;
        case 2:   sorttime();     break;
        case 3:   book();        break;
        case 4:   tuipiao();  break;
        case 5:   search();      break;
        case 6:   printall();    break;
        case 0:          break;
        }
 }while(j!=0);     
 printf("谢谢使用,再见!\n");
 system("pause");
 return 0;
}
void managemenu()
{
    int m=0;   
    printf("           --------1.输入航班信息------- \n\n"
   "           --------2.修改航班信息------- \n\n"
   "           --------3.增加航班信息------- \n\n"
   "           --------4.删除航班信息------- \n\n"
   "           --------5.退出系统------- \n\n");
    printf("请输入您的选择:\n");
    scanf("%d",&m);
    switch(m)
    {
    case 1:    creatfile();       break;        
    case 2:    Change();       break;
    case 3:    add();          break;
    case 4:    delet();        break;
    case 5:    return;
    }
}
void searchmenu()
{
  printf("           --------1.按航班号查询信息------- \n\n"
  "           --------2.按起点查询信息------- \n\n"
    "           --------3.按航空公司查询信息------- \n\n");
}
void find(char ch[10])     
{
    int i=0;
    readOut(s);
    printf("公司  航班号  起始站  终点站  起飞时间  到达时间  机票数  晚点  \n");
    do{
        if(strcmp(s[i].flightnum,ch)==0||strcmp(s[i].from,ch)==0||strcmp(s[i].company,ch)==0)
            {
               
                fprintf(stdout,PRINT);
            }
        }while(i++<h);
}
void search()
{
    char ch[10],a[10];
    int n=0;
    searchmenu();
    printf("请输入您的选择:\n");
    scanf("%d",&n);
    switch(n)
    {
    case 1:
        printf("请输入航班号:");
        scanf("%s",ch);
        break;
    case 2:
        printf("请输入起点:\n");
        scanf("%s",ch);
        break;
   
    case 3:
        printf("请输入航空公司:\n");
        scanf("%s",ch);
        break;
    }
    find(ch);
    printf("查询完毕或未找到,输入任意键回车返回:\n");
    scanf("%s",a);
}

int comptime(int i)
{
    struct tm *local;
    long t;
    int l=0,m=0,n=0;
    char tm1[5],tm2[5];
    time(&t);
    local = localtime(&t);
    for(l=0;l<5;l++)         
    {
        if(s[i].starttime[l]>='0'&&s[i].starttime[l]<='9')
            tm1[l]=s[i].starttime[l];
        else
            break;
    }
    n=l;
    for(m=0;m<5;m++)
    {
        if(s[i].starttime[n]>='0'&&s[i].starttime[n]<='9')
            tm2[m]=s[i].starttime[n++];
        else
            break;
    }
    if(((atoi(tm1)-local->tm_hour)*60+(atoi(tm2)-local->tm_min))>=240)      
        return 1;
    else
        return 0;
}


void tuipiao()            
{
    int i=0,l=0,j=0;
    long int ID=0;

   
    Flight s[20];
    customer c[20];
    FILE *fp,*fp1;
    readOut(s);
    readcustomer(c);   
    fp=fopen("d:\\flight.dat","rb+");
    if(!fp)
    {
        printf("无法打开文件");
        exit(1);
    }
    fp1=fopen("d:\\customer.dat","rb");
    if(!fp)
    {
        printf("无法打开文件");
        exit(1);
    }
   
    printf("请输入您的身份证号码:\n");
    scanf("%ld",&ID);
    for(l=0;l<m;l++)
    {
        if(c[l].ID==ID)            
        {
            for(i=0;i<h;i++)
            {
                if(strcmp(s[i].flightnum,c[l].bookflightnum)==0)
                    break;            
            }
            
            if(comptime(i))
                     {
                        printf("退票成功!\n");
                        c[l].ticket--;
                        s[i].surplus++;
                        fseek(fp1,(i)*100L,SEEK_SET);
                        
                        fwrite(&s[i],sizeFli,1,fp1);
                        printf("公司  航班号  起始站  终点站  起始时间  到达时间  机票数  票价  晚点  \n");
                        fprintf(stdout,PRINT);
                         fwrite(&c[l],sizecustomer,1,fp);
                         printf("客户信息:\n");
                          printf("身份证 预定航班 预订票数 失信次数 \n");
                         printf("%ld %10s %10d %10d\n",c[l].ID,c[l].bookflightnum,c[l].ticket,c[l].lose);
                    }
                    else
                    {
                        printf("飞机即将起飞,现在无法退票!\n");
                        break;
                    }
        }
        
    };
    if(l==m)
        {
        printf("错误的身份证号!您未预定机票\n");
   
        }
   
}





void sorttime()      
{
     char sort[20][10],temp[10],w[10];
    int i=0,m=0,n=0,last=0,l=0;
   
    readOut(s);
   
if(h==0)
{
        printf("没有可排序的航班信息!\n\n");
        return;
}
    for(i=0;i<h;i++)                    
    {   
        strcpy(sort[i],s[i].starttime);     
    }
    while(m<h)                        
    {
        last=h;
        for(n=h;n>m;n--)
        if(strcmp(sort[n],sort[n-1])<0)
        {
            strcpy(temp,sort[n-1]);
            strcpy(sort[n-1],sort[n]);
            strcpy(sort[n],temp);
            last=n;
        }
        m=last;
    }
    for(i=0;i<h;i++)                  
    {
        strcpy(s[i].starttime,sort[i]);
        
    }
    printf("公司  航班号  起始站  终点站  起飞时间  到达时间  机票数  票价  晚点  \n");
    for(i=0;i<h;i++)
     {
         fprintf(stdout,PRINT);
      
        
    }
    printf("按任意键再回车结束:\n");
           scanf("%s",w);
}

void creatfile()
{
    int i=0,y=0;
    FILE *fp;
    if((fp=fopen("d:\\flight.dat","wb"))==NULL)
    {
        printf("创建文件失败!\n\n");
        exit(1);
    }
    for(i=0;i<N;i++)
    {
        input(i);
        fwrite(&s[i],sizeFli,1,fp);   
        printf("信息已经输完是否继续?按任意键继续,按0结束");
        scanf("%d",&y);
        if(y==0)
        {
                printf("录入信息完成!\n\n");
                break;
        }
    }
    fclose(fp);
}

void input(int i)        
{
    char s2[6],s1[6];
    printf("请依次输入航班信息,完成输入信息请键入数字以回车键结束\n\n");      
    printf("--------------------------------------------------------------------------\n");
    printf("请输入航空公司:\n");
    scanf("%s",s[i].company);
    printf("请输入航班号:\n");  
        scanf("%s",s[i].flightnum);              
        printf("请输入起始站:\n");
        scanf("%s",s[i].from);
        printf("请输入终点站:\n");
        scanf("%s",s[i].destn);
     do{
         printf("请输入起飞时间:\n");
         scanf("%s",s1);
         if(s1[0]<'0'||s1[0]>'2'||s1[1]<'0'||s1[1]>'9'||s1[2]!=':'||s1[3]<'0'||s1[3]>'5'||s1[4]<'0'||s1[4]>'9')
             printf("输入格式错误!\n");
         else
             break;
     }while(1);
    strcpy(s[i].starttime,s1);

    do{
         printf("请输入到达时间:\n");
         scanf("%s",s2);
         if(s2[0]<'0'||s2[0]>'2'||s2[1]<'0'||s2[1]>'9'||s2[2]!=':'||s2[3]<'0'||s2[3]>'5'||s2[4]<'0'||s2[4]>'9')
             printf("输入格式错误!\n");
         else
             break;
     }while(1);
    strcpy(s[i].arrive,s2);
    do{
        printf("请输入机票数(<300):\n");
        scanf("%d",&s[i].surplus);
    }while(s[i].surplus>300||s[i].surplus<0);
    printf("请输入票价:\n");
        scanf("%d",&s[i].price);
    printf("请输入是否晚点:\n");   
    scanf("%s",s[i].late);
    h++;      
}

void add()
{
    FILE *fp1;
    int y,i=h;
    if((fp1=fopen("d:\\flight.dat","ab+"))==NULL)
    {
        printf("出错,请检查文件是否存在,按任意键返回主菜单\n\n");
        exit(1);
    }
    input(h);
    fwrite(&s[i],sizeFli,1,fp1);
    printf("信息已经输完是否继续?按任意键继续,按0结束");
    scanf("%d",&y);
    if(y==0)
    {
        printf("录入信息完成!\n\n");
    }
    fclose(fp1);
}


void delet()                    
{
    char  ch1[20],ch2[20],name2[20],name1[20];
    int n=0,i=0,k=0;
    FILE *fp;
    readOut(s);
   
   
    do
    {
        printf("请选择删除以回车键结束:\n\n");
        printf("*1.按航班号删除\n\n"
        "*2.按航线删除\n\n"
        "*0.返回\n\n");
        printf("请在0-2中选择以回车键结束:\n");
        scanf("%d",&n);
        if(n==0)
            
            break;   
        switch(n)
        {
        case 1:
        printf("请输入航班号:\n");
        scanf("%s",ch1);
        break;
        case 2:
        printf("请输入起始站名称:\n");
        scanf("%s",name1);
        printf("请输入终点站名称:\n");
        scanf("%s",name2);
        break;
        }
        for(i=0;i<h;i++)
        {
            if(strcmp(s[i].flightnum,ch1)==0||strcmp(s[i].from,name1)==0&&strcmp(s[i].destn,name2)==0)
            {    k=i;     break;    }
        }
            do{
                s[k]=s[k+1];
               
            }while(++k<h);
            h--;
    if((fp=fopen("d:\\flight.dat","wb"))==NULL)
    {
        printf("创建文件失败!\n\n");
        exit(1);
    }   
    for(i=0;i<9;i++)
    {
        fwrite(&s[i],sizeFli,1,fp);   
    }
        printf("是否继续删除\n");
        printf("请键入yes或no以回车键结束\n");
        scanf("%s",ch2);      
        if(!strcmp(ch2,"yes"))
            printf("请按任意键以回车键结束返回上层菜单:\n");   
        break;
    }while(n!=1&&n!=2&&n!=3&&n!=4&&n!=0);  
}

void readOut(struct Flight *s)  
{
    int i=0;
     FILE  *fp1;
     if((fp1=fopen("d:\\flight.dat","rb"))==NULL)
    {
        printf("打开文件失败!\n\n");
        exit(1);
    }
     fread(&s[i++],sizeof(struct Flight ),1,fp1);
     while(!feof(fp1))
     {
         fread(&s[i++],sizeof(struct Flight),1,fp1);
     }
     fclose(fp1);
     h=--i;
}
void readcustomer(customer *c)
{
    int i=0;
     FILE  *fp1;
     if((fp1=fopen("d:\\customer.dat","rb"))==NULL)
    {
        printf("打开文件失败!\n\n");
        exit(1);
    }
     fread(&c[i++],sizecustomer,1,fp1);
     while(!feof(fp1))
     {
         fread(&s[i++],sizecustomer,1,fp1);
     }
     fclose(fp1);
     m=i;
                        
}

void printall()  
{
    int i=0;
     char w[10];
     struct Flight s[20];         
     readOut(s) ;
     printf("公司  航班号  起始站  终点站  起飞时间  到达时间  机票数  票价  晚点  \n");
     for (i=0;i<h;i++)     
         printf(PRINT);
     printf("请按任意键以回车键结束,返回上层菜单:\n");
     scanf("%s",w);

}
void Change()           
{
    Flight s[20];
    int i=0,num=0,m=0,n=0,k=0;
    char s1[10],s2[6],s3[10],ch[10],s4[10];
    FILE *fp;
    if((fp=fopen("d:\\flight.dat","rb+"))==NULL)
    {
        printf("打开文件失败!\n\n");
        exit(1);
    }   
    printf("请输入您要修改的航班:\n");      
    scanf("%s",s1);
         
    readOut(s);            
    for(i=0;i<h;i++)
     {
        if(strcmp(s[i].flightnum,s1)==0)   
        {
            fseek(fp,(i)*100L,SEEK_SET);
        break;
        }
     }
   
    if(i>h)
    {
        printf("您要修改的航班不存在\n");
        return;
    }
            printf("选择修改项目:\n");
            printf("1.修改起飞时间 \n");
            printf("2.修改到达时间 \n");
            printf("3.修改余票数量 \n");
               printf("4.修改是否晚点 \n");
            printf("5.返回 \n");
            scanf("%d",&num);
            switch(num)
            {
            case 1:

                do{
                    printf("输入修改后的起飞时间:\n");
                    scanf("%s",s2);
                    if(s2[0]<'0'||s2[0]>'2'||s2[1]<'0'||s2[1]>'9'||s2[2]!=':'||s2[3]<'0'||s2[3]>'5'||s2[4]<'0'||s2[4]>'9')
                        printf("输入格式错误!\n");
                    else
                        break;
                }while(1);
                strcpy(s[i].starttime,s2);
                   break;
            case 2:
                do{
                    printf("输入修改后的到达时间:\n");
                    scanf("%s",s4);
                    if(s4[0]<'0'||s4[0]>'2'||s4[1]<'0'||s4[1]>'9'||s4[2]!=':'||s4[3]<'0'||s4[3]>'5'||s4[4]<'0'||s4[4]>'9')
                        printf("输入格式错误!\n");
                    else
                        break;
                }while(1);
                strcpy(s[i].arrive,s4);
                   break;
            case 3:
                do{
                    printf("输入现在剩余票数(<300):\n");
                    scanf("%d",&n);
                }while(n<0||n>300);
                s[i].surplus=n;              break;

            case 4:
                printf("修改是否晚点:\n");
                scanf("%s",s3);
                strcpy(s[i].late,s3);
                break;
            case 5:
                return;
            }
            fwrite(&s[i],sizeFli,1,fp);
            fclose(fp);
            
            printf("修改后的航班信息:\n");
            printf("公司  航班号  起始站  终点站  起飞时间  到达时间  机票数  票价  晚点  \n");
            fprintf(stdout,PRINT);
   
           printf("按任意键再回车结束:\n");
           scanf("%s",ch);
}
void book()   
{    FILE *fp,*fp1;   
    Flight  s[20];
    long int ID=0;      
    char ch[10],name1[10],name2[10];   
                                                      
    int n=0,i=0,m=0,k=0;
   
    if((fp1=fopen("d:\\flight.dat","rb+"))==NULL)
    {
        printf("打开文件失败!\n\n");
        exit(1);
    }   
   
    readOut(s);                          
    fp=fopen("d:\\customer.dat","wb");
    if(!fp)
    {
        printf("无法打开文件");
        exit(1);
    }
       printf("请输入您的身份证号码:\n");
    scanf("%ld",&ID);
    printf("请选择您的预订方式:\n");
    printf("1.\t\t\t\t 按航班号预定\n");
    printf("2.\t\t\t\t按航线预定 \n\n");
    scanf("%d",&n);
    switch(n)
    {
    case 1:
            printf("请输入您要预订的航班号:");
            scanf("%s",ch); break;
    case 2:
            printf("请输入您的出发地:");
            scanf("%s",name1);
            printf("请输入您的目的地:");
            scanf("%s",name2);
            break;
    }
        for(i=0;i<h;i++)
        {
            if(strcmp(s[i].flightnum,ch)==0||strcmp(s[i].from,name1)==0&&strcmp(s[i].destn,name2)==0)
            {     k=i;       break;        }
        }
        if(s[k].surplus==0)
        {
            printf("已经没有余票,订票失败,请重新选择!\n\n");
            return;
        }
        if(comptime(k))
        {
            c[m].ID=ID;
            c[m].ticket++;
            c[m].lose=0;
            strcpy(c[m].bookflightnum,s[i].flightnum);
            fwrite(&c[m],sizecustomer,1,fp);
            printf("客户信息:\n");
            printf("身份证  预定航班  预订票数  失信次数 \n");
            printf("%ld %10s %10d %10d\n",c[m].ID,c[m].bookflightnum,c[m].ticket,c[m].lose);
         
             m++;   
             fseek(fp1,(k)*100L,SEEK_SET);
             s[k].surplus--;
            
             fwrite(&s[k],sizeFli,1,fp1);
             printf("预订机票成功!\n");
            printf("公司  航班号  起始站  终点站  起飞时间  到达时间  机票数  票价  晚点  \n");
            printf(PRINT);
             fclose(fp);
             fclose(fp1);
             return;
        }
        else
            printf("没有该航班或飞机即将起飞,现在无法预订机票!请重新选择\n\n");
            return;
}
搜索更多相关主题的帖子: customer company price 
2014-05-26 17:10
快速回复:请看看我的程序,哪里有错,告诉我怎么修改啊,只有一个错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040323 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved