飞机订票系统课程设计报告

数 据 结 构

课 程 设 计 报 告

院系: 信息管理学院

专业:班级: 软件Q1141 学号: 11150132 姓名: 王毅 教师: 邓沌华 时间:

一、问题描述

题目:飞机订票系统 题目要求:

(1)可以录入航班情况

(2)可以查询某个航线的情况(如,输入航班号,查询起降时间, 起飞抵达城市,航班票价,票价折扣,确定航班是否满仓); 可以输入起飞抵达城市,查询飞机航班情况;

(3)可以订票,如果该航班已经无票,可以提供相关可选择航班;

(4)可以退票,退票后修改相关数据文件;

(5)当航班信息改变可以修改航班数据文件

二、系统分析及设计

1

2、概要设计

主函数中

flight a[15]; //全局航班数组,存储供测试的航班信息,一共15架飞机,航班信

息可以在所有文件中改变

o_customer co; //全局乘客数组存储已经买了票的顾客信息,顾客信息可以在所有文

件中调用、修改

int k = 15; //全局变量,当前的共有航班的辆数,也可被所有文件调用和修改 供测试的航班情况如下:

○1按航班号查询航班 int number_check() //有此辆航班则返回1,无则返回 0 ○2按终点站查询航班int station_check() //有到该站的航班则返回 1, 无则返回0. ○3订票

int Init(int k); //录入乘客信息, 订票成功返回1,否则返回0.

order_f() //订票函数 {

m = n = 0;

m = number_check();//乘客选择航班号方式的查询航班,m = 1方可订票 n = station_check();//乘客选择终点站查询方法查询航班,n = 1,方可订票

if(Init(0) == 0){}

//按编号查询,只显示一个编号的信息,票存在,但订票失败就给予其它方案 if(Init(k) == 0){} //按照终点站查询,订票失败时给予相应处理方法 } ○4退票

void takeoff(){}

//请用户输入他的证件号,避免同名现象造成的影响 //买票的乘客的信息已经存入全局数组中,直接从数组中找出该乘客信息,然后改变相应航班和乘客的信息

3、详细设计

Customer.cpp//顾客信息源代码

#include #include #include #include "customer.h" //#include"flight.h" //#include //using namespace std;

extern flight a[15]; extern int f_no[5]; extern int f;

extern o_customer co;

void getnumber(int i, int length)//获得订单号 {

srand((unsigned)time(NULL));

//随机产生一个订单号, 设置一个随机种子,

保证每次产生的订单号不同 co.a[length].t_number= rand()%100000000; a[i].total_s --; }

Check.cpp //查询操作源代码

#include"check.h" #include //#include"flight.h"

#include"display_flight.h"

int Init(int k) { cout>co.a[co.length].c_name; cout>co.a[co.length].c_number; cout>co.a[co.length].c_total; cout

cout

int f_no[5]; //用来存储按条件查找

的车在数组中的编号

int f ; //用来存储找到车辆的个数 extern flight a[15]; //15辆飞机

int number_check() { int i, n; f = 0; cout>n; cout

f_no[f++] = i; display_flight(a[i]); } } if(f == 0) { //cout

Order.cpp //订票源代码

#include #include"check.h" #include"order.h" #include"flight.h" extern flight a[15]; extern int f_no[5]; extern int f; o_customer co;

else { return 1; } }

int station_check() { int i; string s; f = 0; cout>s; cout

f_no[f++] = i; display_flight(a[i]); } } if(f == 0) { cout

#include"customer.h" #include"display_flight.h"

int b[5];

void order_f() //订票成功与否都会给出相应提示

{

char ch; int i, j, k, m, n; cout>ch; cout

//按编号查询,只显示一个编号的信息,票存在 { cout

//订票失败,数量超过座位余额

{ j = 0; for(i = 0; i

&& a[i].s_station == a[f_no[0]].s_station &&a[i].e_station== a[f_no[0]].e_station

&&co.a[co.length].c_total

{

display_flight(a[i]); b[j ++] = i; } } if(j > 0) {

if(ch == 'p' && n== 1) //按终点站查询 { int a2; cout>a2;

char ch1;

int n1;

cout

cin>>ch1; if(ch1 == 'c') {

cout

号: "

cin>>n1; for(i = 0; i

if(a[b[i]].f_number==1

&& co.a[co.length].c_total

cout

cout

cout

if(Init(k) == 0) { j = 0; for(i = 0; i

等于顾客所需票数的航

班列车,

其他的具有相同起始站

的航班不列出 if(i!=k && co.a[co.length].c_total 0) { char ch1; int n1; cout

继续请安'c', 退出请按'q' ">ch1; if(ch1 == 'c') { cout

cout

cin>>n1; for(i = 0; i

if(a[b[i]].f_number==n1

&& co.a[co.length].c_total

Takeoff.cpp //退票源代码

#include"takeoff.h" #include"customer.h" #include extern flight a[15]; extern o_customer co; //extern cs[100];

void takeoff()//请用户输入他的证件号,以免出现同名现象 { int i, j, k, m = -1; cout>j; cout

while(j != -1) { for(k = 0; k -1) { //cout>i; while(i > co.a[m].c_total) { cout>i; } co.a[m].c_total = co.a[m].c_total - i; a[co.a[m].f_number].total_s = a[co.a[m].f_number].total_s - i; cout>j; cout

三. 系统实现

1. 完整源代码(见文档末尾) 2. 输出界面:

查询、订票、退票操作截图:

四.设计总结

飞机订票系统主要实现的功能是:查询,订票,退票。其中用到了全局变量,数组等一系列知识,订票是该订票系统最难写的部分,要调用大量的函数。订票系统中数据量很大,写代码精力要高度集中。另外我发现了一个很好的编程习惯,写一个函数,或一个文件时,就编译一次;不能等到代码写完再去编译,当遇到代码量大,函数很多的代码时,小差错不容易被发现,而且报错的位置可能乱指,以后要逐个编译。另外用多文件写代码,思路清晰,函数分明,容易根据函数名找到相应的函数。

flight.h

#include

using namespace std; #ifndef _flight_h_ #define _flight_h_

typedef struct Flight { int f_number; string start_t; string end_t; float price; //航班信息 //航班号 //起飞时间 //到达时间 //票价

int total_seat; //可确定航班是否满仓 int total_s; //当前余票数 string s_station; //起点站 string e_station; //终点站 //city *h; 信息,是一个单链表(可以做火车订票系统) }flight; #endif

Customer.h #include"flight.h" #ifndef _customer_h_ #define _customer_h_ typedef struct Customer { string c_name; //顾客姓名 int c_number; //证件号 #include #include #include #include "customer.h"

extern flight a[15]; extern int f_no[5]; extern int f;

extern o_customer co;

void getnumber(int i, int length)//获得订单号 {

srand((unsigned)time(NULL));

//随机产生一个订单号, 设置一个随机种子 ,保证每次产生的订单号不同 co.a[length].t_number = rand()%100000000; a[i].total_s --;}

int Init(int k) { cout>co.a[co.length].c_name; cout

int c_total; //订票数量

int t_number; //订单编号 int f_number; //所定航班在数组中的位置 //int o_number; }customer;

typedef struct O_customer //存放买过票的乘客的信息 { customer a[100];

int length; //当前买过票的总人数 }o_customer;

int Init(int k); //录入顾客信息 void getnumber(int i, int length); #endif

customer.cpp cin>>co.a[co.length].c_number; cout>co.a[co.length].c_total; cout

cout

ndl; co.length ++; } else { cout

Check.h

#ifndef check_h #define check_h

int number_check(); int station_check(); #endif

check.cpp

#include"check.h" #include

#include"display_flight.h"

int f_no[5]; //用来存储按条件查找的车在数组中的编号 int f ; //用来存储找到车辆的个数 extern flight a[15];

int number_check() { int i, n; f = 0; int station_check()

{ cout

cin>>n; int i; cout>s; if(a[i].f_number == n) cout

else } { } return 1; input_data.h

#ifndef input_data_h #define input_data_h

void Input_data(); #endif

input_data.cpp #include #include"input_data.h" #include"flight.h"

extern flight a[50];

extern int k; //记录当前航班的辆数

//先建立15辆航班信息

int f[15] = {110, 111, 112, 113, 114, 115, 116, 117, 118 ,119, 120, 121, 122,123, 124};

string sa[15] = {"武汉", "云梦", "汉口", "武昌", "武昌", "北京", "上海", "天津", "十堰", "山东", " 武汉", "武汉"," 北京"," 上海"," 天津"};//起始站

string st[15] = {"9:10", "5:00", "6:00", "7:00", "8:00", "9:00", "10:00", "8:24", "9:24", "10:24", "10:35", "11:20", "10:00","11:30", "9:00"};//时间

string et[15] = {"12:10", "24:00", "13:05", "18:00", "18:32", "19:18", "24:24", "13:25", "15:24", "14:24", "13:10", "15:10", "20:18", "01: 15", "14:25"};//到站时间

string se[15] = {"信阳", "太原", "哈尔滨", "南京", "重庆", "大连", "吉林", "成都", "西安", "北京", "信阳", "信阳", "大连", "吉林", "成都"};//终点站

int ts[15] = {255, 230, 250, 150, 120, 130, 110, 90, 95, 120, 130, 120, 150, 160, 200};//总共座位数

int tss[15] = {255, 230, 250, 150, 120, 130, 110, 90, 95, 120, 130, 120, 150, 160, 200};//当前可供预定的票数

float p[15] = {39, 230, 150, 130, 230, 124, 135, 220, 113, 130, 39, 39, 124, 135, 220};

void Input_data() a[i].end_t = et[i]; { a[i].total_seat = ts[i]; int i; a[i].total_s = tss[i]; for(i = 0; i

int i = 1;

while(i != 0) {

cout

cin>>a[k].e_station; cin>>a[k].start_t; cin>>a[k].end_t ; cin>>a[k].total_seat; 终点站、起飞时间、到站时间、 仓位、票价">a[k].f_number; cin>>a[k].s_station;

order.h

#ifndef order_h #define order_h

#include"customer.h"

void order_f(); //订票成功

#endif order.cpp

#include #include"check.h" #include"order.h" #include"flight.h" #include"customer.h" #include"display_flight.h"

extern flight a[15]; extern int f_no[5]; extern int f; o_customer co; int b[5];

void order_f() //订票成功与否都会给出相应提示 {

char ch; int i, j, k, m, n; cout>ch; cout

cin>>a[k].price;

}

}

if(ch == 'n' && m == 1) //按编号查询,只显示一个编号的信息,票存在 { cout

//订票失败,数量超过座位余额

{ j = 0; for(i = 0; i

&& a[i].s_station == a[f_no[0]].s_station &&a[i].e_station== a[f_no[0]].e_station

&&co.a[co.length].c_total

{ display_flight(a[i]); b[j ++] = i; } } if(j > 0) { char ch1; int n1; cout

票, 继续请安'c', 退出请

按'q' "

cin>>ch1; if(ch1 == 'c') { cout>n1; for(i = 0; i

cout

return; } } } } if(ch == 'p' && n== 1)

{ int a2; cout>a2; cout

} if(Init(k) == 0) { j = 0; for(i = 0; i

只将于票数大于等于顾客所需票数的航班

列车,其他的具有相同起始站的航班不列出 if(i!=k && co.a[co.length].c_total

display_flight(a[i]);

b[j ++] = i; } } if(j > 0)

{ char ch1; int n1; cout>ch1; if(ch1 == 'c') { cout

cin>>n1; for(i = 0; i

{ co.a[co.length].f_number = b[i]; cout

takeoff.h

#include"flight.h" #define takeoff_h #include"customer.h" void takeoff();//请用户输入航班编号,取消 航班 #ifndef takeoff_h #endif takeoff.cpp

#include"takeoff.h" #include"customer.h" #include

extern flight a[15]; extern o_customer co;

void takeoff()//请用户输入他的证件号,以免出现同名现象 { int i, j, k, m = -1; cout>j; cout -1) { cout>i; while(i > co.a[m].c_total) {

cout>i; } co.a[m].c_total = co.a[m].c_total - i; a[co.a[m].f_number].total_s = a[co.a[m].f_number].total_s - i; cout>j; cout

interface.h

#ifndef _interface_h_ #define _interface_h_

void dis_interface(); #endif

interface.cpp

#include "interface.h" #include

void dis_interface() { cout

display_flight.h

#ifndef display_flight_h

#define display_flight_h #include"flight.h"

void display_flight(flight a); void display(); #endif

display_flight.cpp

#include"display_flight.h" #include

void display_flight(flight a) {

coutvoid display() {

cout

co.length = 0; main.cpp

#include"interface.h" Input_data(); #include"flight.h" dis_interface(); #include"customer.h" char ch; #include"check.h" int i; #include"order.h" #include"takeoff.h" #include"input_data.h" customer *c1 = NULL; #include"display_flight.h" customer *c2 = NULL; #include cout>ch; cout

while(ch != 'q') flight a[15]; //存储供测试的航班信息,一共

{ 15架飞机

switch(ch) extern o_customer co;//存储已经买了票的顾

{ 客信息

int k = 15; case'n': i = number_check(); break; int main() case'p': i = station_check(); { break; case'o':order_f();

break; case't':takeoff(); break; }

cout

cout>ch; cout


© 2024 实用范文网 | 联系我们: webmaster# 6400.net.cn