首页 > 代码库 > 软件工程--第四次作业

软件工程--第四次作业

编程题目:

一航空公司需要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

 

 

软件工程--第四次作业