标题:新人求助!有没有大佬看一看
只看楼主
ysy792656255
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2017-6-12
结帖率:0
已结贴  问题点数:10 回复次数:2 
新人求助!有没有大佬看一看

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

#define N 1000
struct flight
{
int flightno;
char start[10];
char end[10];
char day[10];
int totalticket;
int sellticket;
}s[N];

int i;
int m=0;

#define PRINT "%-d%14s%13s%12s%12d%16d\n",s[i].flightno,s[i].start,s[i].end,s[i].day,s[i].totalticket,s[i].sellticket

void menu();
void print();
void booking();
void input();
void save();
void search();
void back();
void correct();                      //定义函数

void menu()
{
int x;
while(1)
{
        printf("-------------------------操作选项---------------------\n");        
        printf("                     1.录入航班信息\n");   
        printf("                     2.浏览航班信息\n");   
        printf("                     3.修改航班信息\n");   
        printf("                     4.查询航班信息\n");   
        printf("                     5.订票信息\n");   
        printf("                     6.退票信息\n");   
        printf("                     0.退出\n");        
        printf("------------------------------------------------------\n");   
        printf("\n\n");   
        printf("按数字选择执行操作:");   
        scanf("%d",&x);      
        switch(x)   
        {
        case 1:input();break;               
        case 2:print();break;           
        case 3:correct();break;              
        case 4:search();break;        
        case 5:booking();break;        
        case 6:back();break;        
        case 0:break;               
        default:printf("\n\n\n\n                         请重新输入\n\n\n\n\n\n");      
        }   
        printf("谢谢使用,再见!\n");   
    }
}

void main()
{
    int part1,part2;
    char name[10]="7926",password[10]="7926";
    char person[10],c[10];
    printf("****************欢迎进入飞机票订票管理系统******************\n");   
    printf("请输入您的帐号密码\n");
    printf("帐号:");
    scanf("%s",person);    printf("密码:");   
    scanf("%s",c);
    part1=strcmp(person,name);
    part2=strcmp(c,password);
    if(part1==0&&part2==0)
    {  
        printf("登录成功!\n");        
        menu();   
    }
    else   
        printf("登录失败!帐号/密码错误!\n");
}

void input()//打印模块程序
{
    int y;   
    printf("请依次输入航班信息:\n");//打印提示信息
    printf("完成输入信息请键入w以回车键结束\n");   
    printf("_____________________________________________________________________\n");   
    for (i = 0; i < N; i++)
    {
        printf("请输入航班号:\n");        
        scanf("%d", &s[i].flightno);//读取航班号   
        printf("请输入起始站:\n");   
        scanf("%s", s[i].start);//读取起始站   
        printf("请输入终点站:\n");        
        scanf("%s", s[i].end);//读取终点站        
        printf("请输入时间:\n");        
        scanf("%s", s[i].day);//读取时间        
        printf("请输入预售票总数:\n");        
        scanf("%d", &s[i].totalticket);//读取预售票总数   
        printf("请输入已售票总数:\n");        
        scanf("%d", &s[i].sellticket);//读取已售票总数        
        m++;   


        printf("第%d个信息已经输入完是否继续?按任意数字键继续,按0结束\n",m);   
        scanf("%d", &y);        
        if (y == 0)        
        {  
            save();//将结构体信息存盘            
            print();//输出输入的航班信息        
            break;        
        }   
    }
}

void save()//保存模块程序
{
    FILE *fp, *fp1;//定义文件指针
    if ((fp = fopen("chen.dat", "wb")) == NULL)//打开文件并判断是否出错   
    {
        printf("创建文件失败!\n\n");//打印出错提示
        getchar();
        return;   
    }
    if ((fp1= fopen("hao.dat", "wb")) == NULL)//打开文件并判断是否出错
    {
        printf("创建文件失败!\n\n");//打印出错提示   
        getchar();        
        return;   
    }
    for (i = 0; i < m; i++)        
        if (fwrite(&s[i], sizeof(struct flight), 1, fp) == 0)//向文件写入数据,并判断是否出错        
            printf("向文件输入数据失败!\n\n");
    fprintf(fp1, "%d", m);
    fclose(fp);//关闭文件   
    fclose(fp1);//关闭文件
}

void read()//从文件读取信息模块
{
    FILE *fp, *fp1=NULL;//定义文件指针   
    if ((fp = fopen("chen.dat", "rb")) == NULL)//打开文件并判断是否出错
    {   
        printf("出错,请检查文件是否存在,按任意键返回主菜单");//打印出错提示   
        getchar();  
    }
    if ((fp = fopen("hao.dat", "rb")) == NULL)//打开文件并判断是否出错
    {
        printf("创建文件失败!\n\n");//打印出错提示   
        getchar();        return;   
    }
    fscanf(fp1,"%d",&m);   
    fclose(fp1);//关闭文件   
    for (i = 0; i < m; i++)   
    {  
        fread(&s[i], sizeof(struct flight), 1, fp);//从文件中读取信息        
    }
    fclose(fp);//关闭文件
}

void print()//打印模块
{
    char w[10];    read();//调用读取文件函数
    printf("航班号     起始站     终点站     时间     预售票总数     已售票总数\n");
    for (i = 0; i < m; i++)   
    {
        printf(PRINT);//打印信息  
    }   
    printf("请按任意键回车键结束返回上层菜单以:\n");   
    scanf("%s", w);
}

void search()//查询模块
{
    char startname[10];   
    char endname[10];
    char day[10];   
    char p[10];   
    int n, no;
    do   
    {
        printf("请选择查询方式:\n");//打印查询方式菜单        
        printf("1.按航班号查询\n");   
        printf("2.按起点站查询\n");   
        printf("3.按终点站查询\n");   
        printf("4.按航线查询\n");   
        printf("5.按飞行时间查询\n");   
        printf("0.返回\n");
        printf("请在0-5中选择:\n");   
        printf("按其他键以回车键结束返回主菜单:\n");   
        scanf("%d", &n);//读取查找方式        
        if (n == 0)        
            break;        
        switch (n)   
        {
        case 1:           
            printf("请输入航班号:\n");        
            scanf("%d", &no);//航班号        
            break;   
        case 2:            
            printf("请输入起点站名称:\n");        
            scanf("%s", &startname);        
            break;   
        case 3:            
            printf("请输入终点站名称:\n");        
            scanf("%s", &endname);//读取终点站        
            break;   
        case 4:           
            printf("请输入起点站名称:\n");           
            scanf("%s", &startname);//读取起始站           
            printf("请输入终点站名称:\n");        
            scanf("%s", &endname);//终点站        
            break;   
        case 5:            
            printf("请输入飞行时间:\n");   
            scanf("%s", &day);        
            break;      
        }   
        read();//调用读取函数   
        for (i = 0; i < m; i++)   
        {
            if (strcmp(s[i].end, startname) == 0 || strcmp(s[i].end, endname) == 0)//按终点站起始站判断输出条件   
            {
                printf("\n查询航班信息成功!\n");        
                printf("航班号     起始站     终点站     时间     预售机票数     已售票总数\n");        
                printf(PRINT);// 打印信息        
                break;         
            }        
            if (s[i].flightno==no)//按航班号判断输出条件   
            {
                printf("\n查询航班信息成功!\n");        
                printf("航班号     起始站     终点站     时间     预售机票数     已售票总数\n");        
                printf(PRINT);// 打印信息            
                break;         
            }        
            if (strcmp(s[i].day,day)==0)        
            {
                printf("\n查询航班信息成功!");            
                printf("\n航班号     起始站     终点站     时间     剩余机票数     预售机票数\n");        
                printf(PRINT);// 打印信息               
                break;            
            }      
        }        no = 0;//将航班号赋值为0        
        printf("没有您需要的信息或查找完毕:\n\n""是否继续查找?请输入yes或no以回车键结束\n");   
        scanf("%s", p);   
    }
    while (strcmp(p, "yes") == 0);//判断结束
}

void booking()        //订票模块
{
    int n;
    char f[10];
    do
    {
        search();                       //调用查询模块
        printf("请输入您要定的机票数以回车键结束:\n");
        scanf("%d",&n);              //读取所订机票数
        if(n<0)
        {
            printf("请输入有效的机票数\n");//判断机票数是否出错
            break;
        }
        if(s[i].totalticket!=0&&s[i].totalticket>=n);//判断是否出错
        {
            s[i].totalticket=s[i].totalticket-n;s[i].sellticket=s[i].sellticket+n;
            save();               //调用保存函数
            printf("订票成功!\n\n");
            if(s[i].totalticket<n)             //判断是否出错
            {
                printf("请输入有效的机票数:\n");
                break;
            }
            printf("是否继续 请输入yes或no以回车键结束:\n"); //判断是否继续订票
            scanf("%s",f);
        }
    }while(!strcmp(f,"yes"));         //判断结束
}

void back()      //!!!!!!
{
    char f[10];
    int n;
    do
    {
        search();               //调用查询模块
        printf("请输入您要退的机票数目:\n");
        scanf("%d",&n);     //输入所退票数
        if(n<0)                       //判断票数是否有效
            printf("请输入有效的机票数!\n");
        else
        {
            s[i].totalticket=s[i].totalticket+n; s[i].sellticket=s[i].sellticket-n;
        }
        save();   //调用保存模块
        printf("退票成功!\n\n");
        printf("是否继续 请键入yes或no以回车键结束:\n\n");//判断是否继续退票
        scanf("%s",f);
    }
    while(!strcmp(f,"yes"));               //判断并跳出循环
    getchar();
}

void correct()            //修改模块
{
    struct cor   
    {
        int no;        
        char startname[10];        
        char endname[10];         
        char day [10];        
        int totalticket;        
        int sellticket;         
    }
    x[1];   
    char j[10];
    int n;
    {
        read();                //调用读取模块
        do {printf("请选择修改方式:\n");
        printf("*1,按航班号修改:\n");
        printf("*2,按航线修改:\n");
        printf("请在1—2中修改以回车键结束:\n");
        scanf("%d",&n);               //读取修改方式
        switch(n)
        {
        case 1: printf("请输入航班号:\n");
            scanf("%d",&x[0].no);               //读取航班号
            break;case 2:printf("请输入起始站:\n");
            scanf("%s",x[0].startname);         //读取起始站
            printf("请输入终点站:\n");
            scanf("%s",x[0].endname);                       //读取终点站
            break;
        }
        for (i=0;i<m;i++)
        {
            if(strcmp(s[i].start,x[0].startname)== 0&&strcmp(s[i].end,x[0].endname)==0)//判断输出条件
            {
                printf("航班号            起始站              终点站          时间          预售票总数        已售票总数\n");        
                printf(PRINT);        
                break;        
            }
            if(s[i].flightno==x[0].no);        //判断输出条件   
            {  
                printf("航班号   起始站  终点站  预售总数  已售票总数\n");            
                printf (PRINT);        
                break;        
            }
        }
        x[0].no=0;            //将结构体中的号为零
        printf("请输入新航班号、起始站、终点站、时间(星期几)、预售票总数、已售票总数:\n");
        scanf("%d%s%s%s%d%d",&x[0].no,x[0].startname,x[0].endname,x[0].day,& x[0].totalticket,&x[0].sellticket);//定义输入格式 s[i].flightno=x[0].no ;//替换航班号
        strcpy(s[i].start,x[0].startname );//替换其始站
        strcpy(s[i].end,x[0].endname);        //替换终点站
        strcpy(s[i].day,x[0].day);        //替换时间
        s[i].totalticket=x[0].totalticket; //替換预售票总数
        s[i].sellticket=x[0].sellticket;             //替换已售票总数
        save();   //调用保存模块
        printf("是否继续 请键入yes或no以回车键结束:\n\n") ;
        scanf("%s",j); }while(strcmp(j,"yes")==0);//判断结束
    }
}
搜索更多相关主题的帖子: booking correct include search flight 
2017-06-12 14:40
ysy792656255
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2017-6-12
得分:0 
运行input函数选择结束的时候就会弹出这个窗口,为什么???
2017-06-12 14:42
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
得分:10 
fp1写成fp了
程序代码:
void read()//从文件读取信息模块
{
    FILE *fp, *fp1 = NULL;//定义文件指针    
    if ((fp = fopen("chen.dat", "rb")) == NULL)//打开文件并判断是否出错
    {
        printf("出错,请检查文件是否存在,按任意键返回主菜单");//打印出错提示    
        getchar();
    }
    if ((fp1 = fopen("hao.dat", "rb")) == NULL)//打开文件并判断是否出错
    {
        printf("创建文件失败!\n\n");//打印出错提示    
        getchar();        return;
    }
    fscanf(fp1, "%d", &m);
    fclose(fp1);//关闭文件    
    for (i = 0; i < m; i++)
    {
        fread(&s[i], sizeof(struct flight), 1, fp);//从文件中读取信息        
    }
    fclose(fp);//关闭文件
}
2017-06-12 15:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-477848-1-1.html




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

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