⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flight.cpp

📁 民航机票预订系统 结合MFC界面编程 具有订票、退票
💻 CPP
字号:
// Flight.cpp: implementation of the CFlight class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "Keshe_flight.h"
#include "Flight.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFlight::CFlight()
{

}

CFlight::~CFlight()
{

}
airline* CFlight::start_air()
{
        airline *a;
        a=(airline*)malloc(sizeof(airline));
        if(a==NULL)
        a->next=NULL;
        return a;
}
customer* CFlight::start_cus()
{
        customer *c;
        c=(customer*)malloc(sizeof(customer));
        if(c==NULL)
        c->next=NULL;
        return c;
}
airline* CFlight::modefy_airline(airline *l,char *air_num)
{
        airline *p;
        p=l->next;
        while(p!=NULL)
        {
                if(strcmp(air_num,p->air_num)==0)
                {
                        p->left++;
                        return l;
                }
                p=p->next;
        }
}

int CFlight::insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
{
	airline *q;
	q=(airline*)malloc(sizeof(airline));
	strcpy(q->air_num,air_num);
	strcpy(q->plane_num,plane_num);
	strcpy(q->end_place,end_place);
	q->total=total;
	q->left=left;
	q->next=NULL;
	(*p)->next=q;
	(*p)=(*p)->next;
	return OK;
}
int  CFlight::insert_cus(customer **p,char *name,char *air_num,int seat_num)
{
	customer *q;
	q=(customer*)malloc(sizeof(customer));
	strcpy(q->name,name);
	strcpy(q->air_num,air_num);
	q->seat_num=seat_num;
	q->next=NULL;
	(*p)->next=q;
	(*p)=(*p)->next;
	return OK;
}

int CFlight::book(airline *a,char *air_num,customer *c,char *name)
{
	airline  *p=a;  
	customer *q=c->next;
	p=a->next;
//搜索客户姓名
	while (strcmp(name,q->name)!=0&&q->next!=NULL)
	{
		q=q->next;//找到和航班号对应的航班节点
	}
	if (strcmp(name,q->name)==0) 
		return 3;//已经有此人
	q=c->next;
	for(;q->next!=NULL;q=q->next);//移到乘客链表尾
//搜索航班号
	while (strcmp(air_num,p->air_num)!=0&&p->next!=NULL)
	{
		p=p->next;//找到和航班号对应的航班节点
	}
	if (strcmp(air_num,p->air_num)==0)  //若有此航班  
	{	
		if(p->left>0)
		{
			insert_cus(&q,name,air_num,(p->total-p->left)+1);
			p->left--;
			return OK;
		}
		else
		{
			return 0;
		}
	}
	else
		return 2;

}

int CFlight::del_cus(customer *c,airline *l,char *name)
{
        customer *p,*pr;
        char air_num[8];
        pr = c;
        p  = pr->next;	
        while(p!=NULL)
        {
                if(strcmp(p->name,name) == 0)
                {
                        strcpy(air_num, p->air_num);
                        l=modefy_airline(l, air_num);//修改链表
                        pr->next=p->next;
                        p=pr->next;
                        return OK;
                }
                pr=pr->next;
                p=pr->next;
        }
        return ERROR;//没有此乘客!
}

int CFlight::search_one_cus(customer *c,char *cus_name,customer *p)
{
   //customer *p;
   p=c->next;
   while (p) 
   {
       if(strcmp(p->name,cus_name)==0)
	   {
         return 1;
	   }
	   p=p->next;
   }
   printf("没有此乘客!");
   return 0;
}


int CFlight::creat_air(airline **l)
{
        airline *p=*l;
        int i=0;
        char *air_num[6]   =  {"0007","0008","0009","0010","0011","0012"};
        char *plane_num[6] =  {"plane1","plane2","plane3","plane4","plane5","plane6"};
        char *end_place[6] =  {"北京","上海","天津","荆州","武汉","深圳"};
        int total[6]       =  {100,100,100,100,120,150};
        int left[6]        =  {52,54,76,50,99,0};
        for(i=0;i<6;i++)
        insert_air(&p,air_num[i],plane_num[i],end_place[i],total[i],left[i]);
        return OK;
}
int CFlight::creat_cus(customer **l)
{
        customer *p=*l;
        int i=0;
        char *name[6]     =   {"小强","科比","麦迪","宋健","Jordan","民航"};
        char *air_num[6]  =   {"0007","0008","0009","0010","0011","0012"};
        int seat_num[6]   =   {2,5,7,1,28,44};
        for(i=0;i<6;i++)
        insert_cus(&p,name[i],air_num[i],seat_num[i]);
        return OK;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -