软件工程--第四次作业

编程题目:

一航空公司需要y架飞机,使它每天服务四个航班(102 311 444 519)。有一个顶层菜单可供选择航班和退出。选择一个航班,就会出现菜单栏

部分代码如下:

 

void read_file( struct flight *p ,char *filename )
{
    FILE *pseats ;
    if( ( pseats = fopen(filename ,"rb")) == NULL )
    {
        printf( "Can't open %s file . So load default data .\n , filename ");
        load_data( p );
    }
    else
    {
      //  go to start of file
        rewind( pseats );
        while( fread ( p ,sizeof (struct flight ), FLIGHT , pseats ) == 1 )
            continue ;
        fclose ( pseats );
        printf ("read %s successfully !\n ", filename ) ;
    }
}
read_file

 

int choose_flight(viod)
{
    char command[10] ;
    printf(" \n To choose a flight , enter its letter label: \n");
    printf("a) Flights 102 \n");
    printf("b) Flights 311 \n");
    printf("c) Flights 444 \n");
    printf("d) Flights 519 \n");
    printf("e) Quit \n");
    gets(command);
    switch(command[0])
    {
        case 'a' : return 0 ;
        case 'b' : return 1 ;
        case 'c' : return 2 ;
        case 'd' : return 3 ;
        default : return 4 ;
    }

}
choose_flight
void assign_seat(struct seat *p )
{
    int number , i ;
    printf( "Input the seat number :");
    scanf("%d",&number ) ;
    getchar();
    for(i =  0 ;i<SEAT ; i++)
        if(p[i].number == number )
    {
        if(p[i].assign == 1 )
            printf("No.%d seat is already assigned!\n",p[i].number);
        else
        {
            printf("Input firstname of the holder:") ;
            scanf("%s",p[i].firstname) ;
            printf("Input lastname of the holder ") ;
            scanf("%s" ,p[i].lastname ) ;
            getchar() ;
            p[i].assign = 1 ;
            printf("assign No.%d seat successgully!\n",p[i],number) ;
        }
        return ;
    }
    printf("%d is a invalid seat number !\n",number ) ;
}
assign_seat

 

 

void load_data( struct flight *p )
{
    int i , j ;
    for( i = 0 ; j<FLIGHT ; i++ )
        for( j = 0 ;j <SEAT ;j++ )
        {
            //按实际情况设计座位号
            p[i].seats[j].number = i*100 + j ;
            p[i].seats[j].assign = 0 ;
        }

}
load_data

 

 

 

 

int main(void )
{
    int n ;
    read_file( flights, "seat.dat");
    while(1)
    {
        n = choose_flight();
        if( n<0 || n >= FLIGHT )
            break ;
        while( choose_command( &flights[n] ) )
            continue ;
    }
    write_file( flights ,"seat.dat") ;
    puts( "Quit");
}
main

 

 

合影:

 

规范:基本与实际应用上的规则一致

心得:相比以往编程少了些枯燥,效率比较高,思维比较活跃,不过习惯了一个人默默地敲代码,结对编程还是需要慢慢适应的。

--------2016/09/25

 

 

转载于:https://www.cnblogs.com/zyp-ping/p/5904904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值