资源简介
基于C++数据结构编写的航空订票系统,含有源代码,可以运行,很好!

代码片段和文件信息
#include
#include
#include
#include
#define M 450//定义数组的空间为不可改变的整数
using namespace std;
int main();//申明主函数
struct flight//航班信息
{char terminal[10];//终点站名
char number[10];//航班号
char id[10];//飞机号
char date[10];//飞行日期
int member;//乘员定额
int rest;//余票量
struct flight * next;//指向下一个节点的指针
};
struct custom//客户信息
{char name[10];//姓名
char number[10];//航班号
int count;//数量
int grade;//舱位等级
struct custom * next;//指向下一个节点的指针
};
struct flight *a[M];//flight类型的指针数组
struct node//二叉树节点
{ struct custom * base;
node *r;//左孩子
node *l;//右孩子
};
char ch[100];
int judge(char (&ch)[100])
{
int is=0x=0;
if(strlen(ch)==3)
{for(i=0;i {
if(ch[i]>=‘0‘&&ch[i]<=‘9‘)
s++;
}
if(s==strlen(ch))
{for(i=0;i x=x*10+ch[i]-48;
return x;
}
else
return 0;
}
else return 0;
}
int hash(unsigned long k)
{return k%M;}//取余
unsigned long hashvalue(char *str)//将输入字符串转换成长整型数返回
{int il;
unsigned long ret=0;
unsigned short *s;
if (str == NULL) return(0);
l=(strlen(str)+1)/2;
s=(unsigned short *)str;
for (i=0; i ret^=(s[i]<<(i&0x0f));
return(ret);
}
void hashlist()//建立哈希表
{fstream obj;
flight *s=new flight*t=new flight;
int i=0val;
obj.open(“d:\\fly.txt“ios::in);//打开航班信息的文件
while(obj>>s->terminal>>s->number>>s->id>>s->date>>s->member>>s->rest)//提取文件信息
{val=hash(hashvalue(s->terminal));
while(a[hash(val)]!=NULL)//如果数组中的元素不为空,建立链表
{if(!strcmp(a[hash(val)]->terminals->terminal))
{t=a[hash(val)];
while(t->next)//将节点往下移,直至最后节点
{t=t->next;}
t->next=s;
t=s;
t->next=NULL;//末尾节点的next赋空
break;
}
else val++;//哈希表冲突,往数组后面的空位移动
}
if(a[hash(val)]==NULL)//如果哈希表中元素为空,赋给从文件中提取的值
{a[hash(val)]=s;
a[hash(val)]->next=NULL;}
s=new flight;
}
obj.close();//关闭文件
}
void create(node *&rootcustom *&s) //生成二分查找树
{ custom *t=new custom;
if(root==NULL) //当该节点为空时赋值
{ root=new node;
root->base=s;
root->l=NULL;
root->r=NULL;
}
else if(hash(hashvalue(s->name))>hash(hashvalue(root->base->name)))
create(root->rs); //比当前节点小,往左孩子移
else if(hash(hashvalue(s->name))base->name)))
create(root->ls); //比当前节点大,往右孩子移
else //等于当前节点
{t=root->base;
while(t->next!=NULL)//将节点往下移,直至最后节点
t=t->next;
t->next=s;//到尾部添加形成线性表
t=s;
t->next=NULL;//末尾节点的next赋空
}
}
void print(node *&rootchar *&name)//输出要查找的值
{custom *t=new custom;
if(root!=NULL)//如果节点不为空
{if(root->l!=NULL && hash(hashvalue(name))base->name)))
print(root->lname);//比当前节点小
else if(root->r!=NULL && hash(hashvalue(name))>hash(hashvalue(root->base->name)))
print(root->rname);//比当前节点大
else if(hash(hashvalue(name))==hash(hashvalue(root->base->name)))//等于当前节点
{t=root->base;
cout< “票量“< while(t!=NULL)//输出找到的线性表
{cout<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 836 2014-03-13 10:32 2-08-胡锋-航空订票系统\Makefile.win
文件 19027 2014-03-13 10:32 2-08-胡锋-航空订票系统\航空订票系统.cpp
文件 841 2014-03-13 10:32 2-08-胡锋-航空订票系统\航空订票系统.dev
文件 454569 2014-03-13 10:32 2-08-胡锋-航空订票系统\航空订票系统.exe
文件 41517 2014-03-13 10:32 2-08-胡锋-航空订票系统\航空订票系统.o
目录 0 2014-03-13 10:32 2-08-胡锋-航空订票系统
----------- --------- ---------- ----- ----
516790 6
- 上一篇:DBMS c实现
- 下一篇:Bresenham画线连成多边形并填充
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 学校超市选址问题(数据结构C语言版
- VC++MFC小游戏实例教程(实例)+MFC类库
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- 数据结构 图的遍历源代码
评论
共有 条评论