把握命运,追逐梦想

对自己所做的事要有兴趣,同时还要能够坚持不懈

统计

留言簿(1)

阅读排行榜

评论排行榜

航空订票小程序


#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;
}


posted on 2009-07-30 15:34 把握命运 阅读(181) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理