航空订票小程序

航空订票小程序


#include
< stdlib.h >
#include
< stdio.h >
#include
< memory.h >

#define  NOSMOKE 10
#define  SMOKE 10

struct  PlaneSeat
{
    
int noSmoke[NOSMOKE];
    
int smoke[SMOKE];
}
;

int  AllocNoSmokeSeat(PlaneSeat *  pSeat);
int  AllocSmokeSeat(PlaneSeat *  pSeat);


int  main()
{

    PlaneSeat 
*pSeat = new PlaneSeat();
    memset(pSeat,
0,sizeof(PlaneSeat));
    
int part = 0;
    
int ret = 0;

    
while(1)
    
{
        printf(
"1.无烟区\n2.吸烟区\n3.退出\n请选择:");
        scanf(
"%d",&part);
        
if(part == 1)
        
{
            ret 
= AllocNoSmokeSeat(pSeat);
            
if(ret >0)
            
{
                printf(
"您在无烟区的座位号是%d\n",ret);
                
continue;
            }

            
else if(ret == -1)
            
{
                printf(
"无烟区已经没有座位,是否要查询吸烟区?(1.是 2.不):");
                scanf(
"%d",&ret);
                
if(ret == 1)
                
{
                    ret 
= AllocSmokeSeat(pSeat);
                    
if(ret >0)
                    
{
                        printf(
"您在吸烟区的座位是%d\n",ret);
                        
continue;
                    }

                    
else if(ret == -1)
                    
{
                        printf(
"对不起,吸烟区也没有座位了\n");
                        
continue;
                    }

                }

                
else if(ret == 2)
                
{
                    
continue;
                }

            }

        }

        
else if(part == 2)
        
{
            ret 
= AllocSmokeSeat(pSeat);
            
if(ret >0)
            
{
                printf(
"您在吸烟区的座位是%d\n",ret);
                
continue;
            }

            
else if(ret == -1)
            
{
                printf(
"吸烟区已经没有座位,是否要查询无烟区?(1.是 2.不):");
                scanf(
"%d",&ret);
                
if(ret == 1)
                
{
                    ret 
= AllocNoSmokeSeat(pSeat);
                    
if(ret >0)
                    
{
                        printf(
"您在无烟区的座位是%d\n",ret);
                        
continue;
                    }

                    
else if(ret == -1)
                    
{
                        printf(
"对不起,无烟区也没有座位了\n");
                        
continue;
                    }

                }

                
else if(ret == 2)
                
{
                    
continue;
                }

            }

        }

        
else if(part == 3)
        
{
            
break;
        }

    }


    
return 0;

}


int  AllocNoSmokeSeat(PlaneSeat *  pSeat)
{
    
for(int i = 0; i<NOSMOKE; i++)
    
{
        
if(pSeat->noSmoke[i] == 0)
        
{
            pSeat
->noSmoke[i] =1;
            
return i+1;
        }

    }

    
return -1;
}


int  AllocSmokeSeat(PlaneSeat *  pSeat)
{
    
for(int i = 0; i<SMOKE; i++)
    
{
        
if(pSeat->smoke[i] == 0)
        
{
            pSeat
->smoke[i] = 1;
            
return i+1;
        }

    }


    
return -1;
}


你可能感兴趣的:(航空订票小程序)