课 程 设 计 报 告
课程设计名称: 数据结构 系 : 计算机科学系
学生姓名:
班 级: 13計算機科學與技術1班 学 号:成 绩:
指导教师: 肖錦輝老師
开课时间:学年
数据结构课程设计报告
一.设计题目
算术表达式求值
二.主要内容
(所选课题的需求分析,实现功能等)
1、程序能对所输入的表达式作简单的判断,如表达式有错。
2、能处理单目运算符:+、-。
三.课题设计的基本思想,原理和算法描述
(包括课题所用数据结构,界面设计、输入/输出设计,功能模块设计,符号说明等)
对于中缀表达式,一般运算规则如下:
1、先乘方,再乘除,最后加减。
2、同级运算从左算到右。
3、先括号内,再括号外。
操作的符号:+ - * / ^ % ().
根据实际经验,可以对运算符设置统一的优先级,从而方便比较。
上面讨论的+、-为双目运算符,如单目运算符,编程实现时,可在前面加上0而转化为双目运算符。
思路如下:
1、将optr栈和opnd栈清空,在optr栈中加入一个‘=’。
2、从输入流获取一字符ch,循环执行步骤3至步骤5直到求出表达式的值为止。
3、取出optr的栈顶optrTop,当optrTop=‘=’且ch=‘=’时,整个表达式求值完毕,这时opnd栈的栈顶元素为表达式的值。
第1页 1
数据结构课程设计报告
4、若ch不是操作符,则将字符放回输入流(cin.putback),读操作符operand;将operand加入opnd栈,读入下一个字符ch。
5、若ch是操作符,按如下方式进行处理:
a.若ch为单目运算符,则在ch前面加上操作符0,也就是将0入pond。
b.若optrTop与ch不匹配,例如optrTop=‘)’且ch=‘(’,显示错误信息。 c.若optrTop=‘(’且ch=‘)’,则从optr栈退出栈顶的‘(’,去括号,然后从输入流中读入字符并送入ch;
d.若ch=‘(‘或optrTop比ch优化级低,则ch入optr,从输入流中取下一个字符ch;
e.若optrTop大于或等于ch的优先级,则从opnd栈退出left和right,从optr栈退出theta,形成运算符指令(left)theta(right),结果入opnd栈。
四.源程序及注释
需要用到的头文件有:
lk_stack.h node.h utility.h cal.h
// cal.h
#ifndef __CALCULATOR_H__
#define __CALCULATOR_H__
#include "lk_stack.h" // 链栈类
template<class ElemType>
class Calculator
{
private:
LinkStack<ElemType> opnd; LinkStack<char> optr; //char GetChar(); int OperPrior(char op); void Get2Operands (ElemType &left,ElemType &right);
第2页 2
数据结构课程设计报告
ElemType Operate(ElemType left,char op,ElemType right);
bool IsOperator(char ch);
public:
Calculator(){};
virtual ~Calculator(){};
void Run();
};
template<class ElemType>
int Calculator<ElemType>::OperPrior(char ch)
{
if(ch == '=') return 1;
if(ch == '^') return 5;
if(ch == '('||ch == ')') return 2;
if(ch == '+'|| ch == '-') return 3;
if(ch == '*'||ch == '/'||ch == '%') return 4;
return 0;
}
template<class ElemType>
bool Calculator<ElemType>::IsOperator(char ch)
{
if (ch == '=' || ch == '(' || ch == '*' ||
ch == '/' || ch == '+' || ch == '-' || ch == ')'|| ch == '%'||ch == '^') return true; else return false;
};
template<class ElemType>
ElemType Calculator<ElemType>::Operate(ElemType left, char theta, ElemType right) // 操作结果:执行运算left op right
{
ElemType result;
if (theta == '+') result = left + right; // 加法运算
else if (theta == '-') result = left - right; // 减法运算
else if (theta == '*') result = left * right; // 乘法运算
//else if (theta == '/' && right == 0) throw "除数为零!"; // 抛出异常
else if (theta == '/' ) result = left / right; // 除法运算
else if (theta == '^') result = pow(left , right);
else if (theta == '%') result = (int)left%(int)right;
return result; // 返回result
}
template<class ElemType>
void Calculator<ElemType>::Get2Operands( ElemType &left, ElemType &right)
// 操作结果:从栈opnd中退出两个操作数
{
opnd.Pop(right);
opnd.Pop(left);
第3页 3
数据结构课程设计报告
}
template<class ElemType>
void Calculator<ElemType>::Run()
{
optr.Clear();
opnd.Clear();
optr.Push('=');
char ch;
char priorChar;
char optrTop;
ElemType operand;
char op;
priorChar='=';
ch=GetChar();
optr.Top(optrTop);
while(optrTop!='='||ch!='=')
{
if(isdigit(ch)||ch=='.')
{
cin.putback(ch);
cin>>operand;
opnd.Push(operand);
priorChar='0';
ch=GetChar();
}
else if(!IsOperator(ch))
{
cout<<"表达式错误!"<<endl;
return;
}
else
{
if ((priorChar=='='||priorChar=='(')&&(ch=='+'||ch=='-')) {
opnd.Push(0);
priorChar='0';
}
if(optrTop=='('&&ch==')')
{
optr.Pop(optrTop);
ch=GetChar();
priorChar=')';
}
else if(ch=='('||OperPrior(optrTop)<OperPrior(ch))
第4页 4
数据结构课程设计报告
{
optr.Push(ch);
priorChar=ch;
ch=GetChar();
}
else
{
optr.Pop(op);
ElemType left,right;
Get2Operands(left,right);
opnd.Push(Operate(left,op,right)); }
}
optr.Top(optrTop);
}
opnd.Top(operand) ;
cout<<operand<<endl;
};
#endif
//main.cpp
#include"utility.h"
#include "cal.h" // 计算器类
int main(void)
{
try // 用try封装可能出现异常的代码
{
do
{
cout << "输入一个表达式:" << endl;
Calculator<double> cal;
cal.Run(); // 表达式求值
cout << "是否继续";
} while (UserSaysYes());
}
第5页 5
数据结构课程设计报告
catch (Error err) // 捕捉并处理异常
{
err.Show(); // 显示异常信息
}
system("PAUSE"); // 调用库函数system()
return 0; // 返回值, 返回操作系统
}
五、运行示例及结果分析
(截图分析)
六、调试和运行程序过程中产生的问题及采取的措施Throw语句出错,用cout和return代替。
七、总结和展望
(400字以上)
第6页 6
数据结构课程设计报告
感谢老师给我们这次课程设计的机会,在此次项目中,虽然我面临着许多困难,但是,经过不断地努力与调试后,终于完成了该次项目。不过,该项目的局限性,加上运行环境的问题,可能会出现不稳定,但总体来说,可以顺利实现项目要求。当然,在完成该次项目的过程中,我意识到自己在基础知识上的各种不足,同时,我也为了完成项目而不断努力地复习并验证知识点。我希望在以后的日子里,可以接受更大的挑战,因为那不仅可以给自己锻炼,还可以在那个过程中,学到更多的项目经验。说的夸张一点,那是算是宝贵的财富吧。当然,需要在拥有一定的知识基础,才能接受一定难度的项目,所以,必须先从基础知识开始,固然需要对基础知识加以巩固,然后不断地上机操作,并加以锻炼。说实话,对首次完成项目,难度比较大,因为要考虑各种不确定因素,所以,在真正实践起来,相当困难,有时候可能对一个小小的问题,抱着很多无奈,当然,结果刻苦地努力,还是可以顺利完成任务的。
八、参考资料
(格式为:[序号]作者.书名.出版社,出版年份 如:
[1] 李建学等著.数据结构课程设计案例精编.清华大学出版社,2007
[2] 唐宁九等主编.数据结构与算法(C++版)实验和课程设计教程. 清华大学出版社,2008)
注:以上所有正文内容(所给八个标题除外)均采用小四字体书写,且每段首行缩进,段落间距1.3倍行距。
第7页 7
课题设计1:迷宫求解
一. 需求分析:
本程序是利用非递归的方法求出一条走出迷宫的路径,并将路径输出。
首先由用户输入一组二维数组来组成迷宫,确认后程序自动运行,当迷宫有完整路径可以通过时,以0和1所组成的迷宫形式输出,标记所走过的路径结束程序;当迷宫无路径时,提示输入错误结束程序。
二、 概要设计:
1.抽象数据类型定义:
ADT Find{
数据对象:D={ai?ai ∈ElemSet,i=1,2,…,n,n≥0}
数据关系:R1={<ai-1,ai>?ai-1, ai∈D }
基本操作:
find (&S)
初始条件:已初始化栈S,且栈为空
操作结果:从栈S中找出相对应的数据关系,并输出结果
}ADT Find
2. 主程序的流程以及各程序模块之间的调用关系:
(1).定义变量i、j、w、z为整形变量
(2).输入迷宫二维数组maze(0:m,0:n)
(3).调用子程序find ()
(4).结束程序
三、相应的源程序如下:
#include<stdio.h>
#include<stdlib.h>
typedef enum { ERROR, OK } Status;
typedef struct
{
int row, line;
}PosType;
typedef struct
{
int di, ord;
PosType seat;
}SElemType;
typedef struct
{
SElemType * base;
SElemType * top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S);
Status Push(SqStack &S,SElemType &a);
Status Pop(SqStack &S,SElemType &a);
Status StackEmpty(SqStack S);
Status MazePath(int maze[12][12],SqStack &S, PosType start, PosType end);
void Initmaze(int maze[12][12],int size);
void printmaze(int maze[12][12],int size);
Status Pass(int maze[12][12],PosType CurPos);
void Markfoot(int maze[12][12], PosType CurPos);
PosType NextPos(PosType CurPos, int Dir);
void printpath(int maze[12][12],SqStack S,int size);
void main (void)
{
SqStack S;
int size,maze[12][12];
for(int n=0;n<10;n++)
{
printf("创建一个正方形迷宫,请输入迷宫尺寸(注意不要大于50):\n");
scanf("%d",&size);if(size<1 || size>10){printf("输入错误!");return;}
Initmaze(maze,size);
printmaze(maze,size);
PosType start,end;
printf("输入入口行坐标和列坐标:");scanf("%d",&start.row);scanf("%d",&start.line);
printf("输入出口行坐标和列坐标:");scanf("%d",&end.row);scanf("%d",&end.line);
if(MazePath(maze,S,start,end))
printpath(maze,S,size);
else printf("找不到通路!\n\n");
}
}
Status MazePath(int maze[12][12],SqStack &S, PosType start, PosType end)
{
PosType curpos;
int curstep;
SElemType e;
InitStack(S);
curpos = start;
curstep = 1;
do {
if (Pass(maze,curpos))
{
Markfoot(maze,curpos);
e.di =1;
e.ord = curstep;
e.seat= curpos;
Push(S,e);
if (curpos.row==end.row && curpos.line==end.line)
return OK;
curpos = NextPos(curpos, 1);
curstep++;
}
else
{
if (!StackEmpty(S))
{
Pop(S,e);
while (e.di==4 && !StackEmpty(S))
{
Markfoot(maze,e.seat);
Pop(S,e);
}
if (e.di<4)
{
e.di++;
Push(S, e);
curpos = NextPos(e.seat, e.di);
}
}
}
} while (!StackEmpty(S));
return ERROR;
}
void Initmaze(int maze[12][12],int size)
{
char select;
printf("选择创建方式 A:自动生成 B:手动创建\n");
label:scanf("%c",&select);
if(select=='a'||select=='A')
{
for(int i=0;i<size+2;i++)maze[0][i]=1;
for( i=1;i<size+1;i++)
{
maze[i][0]=1;
for(int j=1;j<size+1;j++)
maze[i][j]=rand()%2;
maze[i][size+1]=1;
}
for(i=0;i<size+2;i++)maze[size+1][i]=1;
}
else if(select=='b'||select=='B')
{
printf("按行输入%d*%d数据,0代表可通,1代表不可通(每行以Enter结束):\n",size,size);
for(int i=0;i<size+2;i++)maze[0][i]=1;
for( i=1;i<size+1;i++)
{
maze[i][0]=1;
for(int j=1;j<size+1;j++)
scanf("%d",&maze[i][j]);
maze[i][size+1]=1;
}
for(i=0;i<size+2;i++)maze[size+1][i]=1;
}
else if(select=='\n')goto label;
else printf("输入错误!");
}
void printmaze(int maze[12][12],int size)
{
printf("\n\n");
printf("显示所建的迷宫(#表示外面的墙):\n");
for(int i=0;i<size+2;i++)printf("%c ",'#');printf("\n");
for(i=1;i<size+1;i++)
{
printf("%c ",'#');
for(int j=1;j<size+1;j++)
{
printf("%d ",maze[i][j]);
}
printf("%c",'#');
printf("\n");
}
for(i=0;i<size+2;i++)printf("%c ",'#');printf("\n");
}
void printpath(int maze[12][12],SqStack S,int size)
{
printf("\n\n通路路径为:\n");
SElemType * p=S.base;
while(p!=S.top)
{
maze[p->seat.row][p->seat.line]=2;
p++;
}
for(int i=0;i<size+2;i++)printf("%c ",'#');printf("\n");
for(i=1;i<size+1;i++)
{
printf("%c ",'#');
for(int j=1;j<size+1;j++)
{
if(maze[i][j]==2) printf("%c ",'0');
else printf(" ");
}
printf("%c",'#');
printf("\n");
}
for(i=0;i<size+2;i++)printf("%c ",'#');printf("\n\n");
}
Status Pass(int maze[12][12],PosType CurPos)
{
if (maze[CurPos.row][CurPos.line]==0)
return OK;
else return ERROR;
}
void Markfoot(int maze[12][12],PosType CurPos)
{
maze[CurPos.row][CurPos.line]=1;
}
PosType NextPos(PosType CurPos, int Dir)
{
PosType ReturnPos;
switch (Dir)
{
case 1:
ReturnPos.row=CurPos.row;
ReturnPos.line=CurPos.line+1;
break;
case 2:
ReturnPos.row=CurPos.row+1;
ReturnPos.line=CurPos.line;
break;
case 3:
ReturnPos.row=CurPos.row;
ReturnPos.line=CurPos.line-1;
break;
case 4:
ReturnPos.row=CurPos.row-1;
ReturnPos.line=CurPos.line;
break;
}
return ReturnPos;
}
Status InitStack(SqStack &S)
{
S.base=(SElemType *)malloc(100*sizeof(SElemType));
if(!S.base)return ERROR;
S.top=S.base;
S.stacksize=100;
return OK;
}
Status Push(SqStack &S,SElemType &a)
{
*S.top++=a;
return OK;
}
Status Pop(SqStack &S,SElemType &a)
{
if(S.top==S.base)return ERROR;
a=*--S.top;
return OK;
}
Status StackEmpty(SqStack S)
{
if(S.top==S.base)return OK;
return ERROR;
}
以下为测试数据:
输入一个矩阵,例如:1 0 0 1 1
0 0 1 1 1
1 0 0 0 1
0 1 0 1 1
1 1 0 0 0
输入入口行坐标和列坐标:1 2
输入出口行坐标和列坐标:5 5
通路路径为:
课题设计3:joseph环
一. 需求分析:利用单向循环链表存储结构模拟此过程,按照出列的顺序输出各个人的编号。首先创建一个空链表,初始化链表,构造出一个只有头结点的空链表,建立好一个约瑟夫环。
1. 输入的形式和输入值的范围
本程序中,输入报数上限值m和人数上限l,密码,均限定为正整数,输入的形式为一个以“回车符”为结束标志的正整数。
2. 输出的形式
从屏幕显示出列顺序。
3. 程序功能
提供用户从键盘输入,Joseph约瑟夫环的必要数据,并显示出列顺序。
二、 概要设计
以单向循环链表实现该结构。
1. 抽象数据类型的定义为:
ADT LNode
{
数据对象:D={ai | ai∈CharSet,i= 1,2,…,n,n≥0}
数据关系:R1={< ai-1 ,ai > | ai ∈D, I=2,…,n}
三.源程序:#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int key;//每个人持有的密码
int num;//这个人的编号
struct Node *next;//指向下一个节点
}Node,*Link;
void InitList(Link &L) //创建一个空的链表
{
L=(Node *)malloc(sizeof(Node));
if(!L) exit(1);
L->key=0;
L->num=0;
L->next=L;
}
void Creater(int n,Link &L) //初始化链表
{
Link p,q;
q=L;
for(int i=1;i<=n;i++)
{
p=(Node *)malloc(sizeof(Node));
if(!p) exit(1);
printf("the key_%d is:",i);
scanf("%d",&p->key);
p->num=i;
L->next=p;
L=p;
}
L->next=q->next;
free(q);
}
void main()
{
Link L,p,q;
int n,x;
L=NULL;
InitList(L);//构造出一个只有头结点的空链表
printf("please input the totle number of people:");
scanf("%d",&n);//总共的人数n
printf("the start key is:");
scanf("%d",&x);//初始密码为x
Creater(n,L);//建立好一个约瑟夫环
p=L;
for(int i=1;i<=n;i++)
{
for(int j=1;j<x;j++)
p=p->next;
q=p->next;
x=q->key;
printf("%d ",q->num);
p->next=q->next;
free(q);
}
}
四、测试数据:
m的初值为20,n=7 ,7个人的密码依次为3,1,7,2,4,7,4
输出:6 7 4 1 5 3 2
课题设计4:商品货架管理
1、需求分析:设计一个算法,每一次上货后始终保持生产日期越近的商品越靠近栈底。求货架上剩余货物M、每天销售件数N、员工每天上货工作时间T,三者之间有何关系及T的最小值。
2、源程序:#include<iostream.h>
#include"string.h"
#include"stdio.h"
const int maxsize=100;
const int k=10;
#define elemtype char
typedef struct
{
int Month;
int Day;
int Year;
}DATE;
typedef struct
{
int num;
DATE date;
} Node;
class seqstack
{
public:
Node stack[maxsize];
int top;
void inistack()
{
top=0;
}
void push(int x,int day,int month,int year)
{
if(top==maxsize)
cout<<"货架已满"<<endl;
else
{
top++;
stack[top].num=x;
stack[top].date.Day=day;
stack[top].date.Month=month;
stack[top].date.Year=year;
}
}
void pop()
{
if(top==0)
cout<<"货架已空"<<endl;
else
top--;
}
elemtype gettop()
{
if(top==0)
cout<<"货架已空"<<endl;
else
return top;}
bool empty()
{
return top==0;
}
};
void main()
{
seqstack c[k+1]; //存放k种商品的数组,用c[0]来做中介货架
int Txq[k+1]; //第i种取货用的时间
int Txs[k+1]; //第i种上货用的时间
int Nx[k+1]; //第i种每天的销售数量
int N=0; //每天销售总量
int Tx[k+1]; //第i种每天上货的总时间
int T=0; //每天上货用的总时间
char yn='Y';
for(int i=1;i<=k;i++)
{
cout<<" ******************************"<<endl;
cout<<" 商品货架管理系统"<<endl;
cout<<" ******************************"<<endl;
Node store[20];
char year,month;
int count; //货架上第i种商品的数目
int x,d,m,y; //x为第i种商品的序号
cout<<"请输入货架上第"<<i<<"种货物的详细信息:"<<endl;
cout<<"(序号,生产日期(年、月、日如2006.2.13),现在货架上的存货数目,上货用时和取货用时)"<<endl;
cin>>x>>y>>year>>m>>month>>d>>count>>Txs[i]>>Txq[i];
Nx[i]=maxsize-count;
cout<<"货架上还需上"<<i<<"货物"<<Nx[i]<<"件"<<endl;
Tx[k]=Txs[i]*(maxsize+count)+2*Txq[i]*count;
cout<<"该货架满货需要用时"<<Tx[k]<<endl;
cout<<"是否要上货?(Y/N)"<<endl;
cin>>yn;
if(yn=='Y'||yn=='y')
{
int numbers,nian,yue,ri;
cout<<"请输入要上货物的数目及生产日期(年、月、日)"<<endl; //上的是同一日期生产的货物
cin>>numbers>>nian>>yue>>ri;
if(numbers>maxsize-count)
{
cout<<"要上的货物数目超出了货架的最大容量,请重新输入"<<endl;
cin>>numbers>>nian>>yue>>ri;
}
for(int j=1;j<=numbers;j++)
{
}
}
N+=Nx[i];
T+=Tx[i];
}
cout<<"每天销售总量为:"<<N<<endl;
cout<<"每天上货用的总时间为:"<<T<<endl;
}
3、测试结果:
五、课程设计5:航空客运订票系统
1、需求分析:
对于本设计,可采用基数排序法对于一组具有结构特点的飞机航班号进行排序,利用二分查找法对排好序的航班记录按航班号实现快递查找,按其他次关键字的查找可采用最简单的顺序查找方法进行,因为它们用的较少。
2、源程序:#include <stdio.h>
#include <string.h>
#define maxspace 100
#define keylen 7
#define radix_n 10
#define radix_c 26
typedef char keytype;
typedef struct
{
char start[6];
char end[6];
char sche[10];
char time1[5];
char time2[5];
char model[4];
int price;
}infotype;
typedef struct
{
keytype keys[keylen];
infotype others;
int next;
}slnode;
typedef struct
{
slnode sl[maxspace];
int keynum;
int length;
}sllist;
typedef int arrtype_n[radix_n];
typedef int arrtype_c[radix_c];
void distribute(slnode *sl,int i,arrtype_n f,arrtype_n e)
{
int j,p;
for(j=0;j<radix_n;j++)
{
f[j]=e[j]=0;
}
for(p=sl[0].next;p;p=sl[p].next)
{
j=sl[p].keys[i]%48;
if(!f[j])
f[j]=p;
else
sl[e[j]].next=p;
e[j]=p;
}
}
void collect(slnode *sl,int i,arrtype_n f,arrtype_n e)
{
int j,t;
for(j=0;!f[j];j++);
sl[0].next=f[j];
t=e[j];
while(j<radix_n-1)
{
for(j=j+1;j<radix_n-1&&!f[j];j++);
if(f[j])
{
sl[t].next=f[j];
t=e[j];
}
}
sl[t].next=0;
}
void distribute_c(slnode *sl,int i,arrtype_c f,arrtype_c e)
{
int j,p;
for(j=0;j<radix_c;j++)
{
f[j]=e[j]=0;
}
for(p=sl[0].next;p;p=sl[p].next)
{
j=sl[p].keys[i]%65;
if(!f[j])
f[j]=p;
else
sl[e[j]].next=p;
e[j]=p;
}
}
void collect_c(slnode *sl,int i,arrtype_c f,arrtype_c e)
{
int j,t;
for(j=0;!f[j];j++);
sl[0].next=f[j];
t=e[j];
while(j<radix_c-1)
{
for(j=j+1;j<radix_c-1&&!f[j];j++);
if(f[j])
{
sl[t].next=f[j];
t=e[j];
}
}
sl[t].next=0;
}
void radixsort(sllist &l)//链式
{
int i;
arrtype_n fn,en;
arrtype_c fc,ec;
for(i=0;i<l.length;i++)
l.sl[i].next=i+1;
l.sl[l.length].next=0;
for(i=l.keynum-1;i>=2;i--)
{
distribute(l.sl,i,fn,en);
collect(l.sl,i,fn,en);
}
for(i=1;i>=0;i--)
{
distribute_c(l.sl,i,fc,ec);
collect_c(l.sl,i,fc,ec);
}
}
void arrange(sllist &l)//重新整理
{
int p,q,i;
slnode temp;
p=l.sl[0].next;
for(i=1;i<l.length;i++)
{
while(p<i)
p=l.sl[p].next;
q=l.sl[p].next;
if(p!=i)
{
temp=l.sl[p];
l.sl[p]=l.sl[i];
l.sl[i]=temp;
l.sl[i].next=p;
}
p=q;
}
}
int binsearch(sllist l,keytype key[])
{
int low,high,mid;
low=1;
high=l.length;
while(low<=high)
{
mid=(low+high)/2;
if(strcmp(key,l.sl[mid].keys)==0)
return mid;
else if(strcmp(key,l.sl[mid].keys)<0)
high=mid-1;
else
low=mid+1;
}
return 0;
}
void seqsearch(sllist l,keytype key[],int i)
{
int j,k,m=0;
printf("*************************************************************\n");
printf("* 航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价 *\n");
for(j=1;j<=l.length;j++)
{
switch(i)
{
case 2:k=strcmp(key,l.sl[j].others.start);break;
case 3:k=strcmp(key,l.sl[j].others.end);break;
case 4:k=strcmp(key,l.sl[j].others.time1);break;
case 5:k=strcmp(key,l.sl[j].others.time2);break;
}
if(k==0)
{
m=1;
printf("* %-8s%-7s%-6s%-11s%-9s%-7s%-5s%4d *\n",l.sl[j].keys,l.sl[j].others.start,l.sl[j].others.end,l.sl[j].others.sche,l.sl[j].others.time1,l.sl[j].others.time2,l.sl[j].others.model,l.sl[j].others.price);
}
}
if(m==0)
printf("* 无此航班信息,可能是输入错误! *\n");
printf("*************************************************************\n");
}
void searchcon(sllist l)
{
keytype key[keylen];
int i=1,k;
while(i>=1&&i<=5)
{
printf("\n ********************\n");
printf(" * 航班信息查询系统 *\n");
printf(" ********************\n");
printf(" * 1.航 班 号 *\n");
printf(" * 2.起 点 站 *\n");
printf(" * 3.终 点 站 *\n");
printf(" * 4.起飞时间 *\n");
printf(" * 5.到达时间 *\n");
printf(" * 0.退出系统 *\n");
printf(" ********************\n");
printf(" 请选择(0-5):");
scanf("%d",&i);
printf("\n");
switch(i)
{
case 1:printf("输入要查询的航班号(字母要大写):");
scanf("%s",key);
k=binsearch(l,key);
printf("*************************************************************\n");
if(k==0)
printf("* 无此航班信息,可能是输入错误! *\n");
else
{
printf("* 航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价 *\n");
printf("* %-8s%-7s%-6s%-11s%-9s%-7s%-5s%4d *\n",l.sl[k].keys,l.sl[k].others.start,l.sl[k].others.end,l.sl[k].others.sche,l.sl[k].others.time1,l.sl[k].others.time2,l.sl[k].others.model,l.sl[k].others.price);
}
printf("*************************************************************\n");
break;
case 2:printf("输入要查询的航班起点站名:");
scanf("%s",key);
seqsearch(l,key,i);
break;
case 3:printf("输入要查询的航班终点站名:");
scanf("%s",key);
seqsearch(l,key,i);
break;
case 4:printf("输入要查询的航班起飞时间:");
scanf("%s",key);
seqsearch(l,key,i);
break;
case 5:printf("输入要查询的航班到达时间:");
scanf("%s",key);
seqsearch(l,key,i);
break;
case 0:printf("\n\n\n 再 见\n\n\n");
}
}
}
void inputdata(sllist &l)
{
int i=++l.length;
char yn='y';
while(yn=='y'||yn=='Y')
{
printf("航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价\n");
scanf("%s%s%s%s%s%s%s%d",l.sl[i].keys,l.sl[i].others.start,l.sl[i].others.end,l.sl[i].others.sche,l.sl[i].others.time1,l.sl[i].others.time2,l.sl[i].others.model,&l.sl[i].others.price);
++i; getchar();
radixsort(l);
arrange(l);
printf("继续输入吗?y/n:");
scanf("%c",&yn);
}
l.length=i-1;
}
void main()
{
sllist l;
l.keynum=6;
l.length=0;
inputdata(l);
searchcon(l);
}
3、测试结果:
航班信息:航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价
输入:CA1544 合肥 北京 1.2.4.5 1055 1240 733 960
提示:继续输入吗?y/n:y
显示:航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价
MU5341 上海 广州 每日 1420 1615 M90 1280
提示:继续输入吗?y/n:y
……
提示:继续输入吗?y/n:n
课程设计说明书课程名称:数据结构与算法专业:计算机科学与技术班级:103013姓名:XXX学号:03指导教师:XXX完成日期:20…
西安郵電學院数据结构课程设计报告题目校园导航系统院系名称计算机学院专业名称计算机科学与技术班级学生姓名学号8位指导教师设计起止时间…
安徽省巢湖学院计算机与信息工程学院课程设计报告课程名称课题名称用三元组实现稀疏矩阵的转置相加相乘专业计算机科学与技术班级学号AA姓…
扬州大学信息工程学院数据结构课程设计报告题目井字棋小游戏班级学号姓名指导教师一课程题目井字棋小游戏二需求分析计算机和人对弈问题计算…
攀枝花学院学生课程设计论文题目学生姓名学号20xx108010所在院系数学与计算机学院专业计算机科学与技术专业班级20xx级计算机…
《数据结构》课程设计报告题目:班级:计算机系1001班姓名:学号:4236指导教师:日期:20##年7月3日一、课程设计目标二、概…
数据结构课程设计报告学生姓名学号班级地信10901长江大学20XX.6目录1.需求分析......................…
软件111班18号赵庆珍数据结构课程设计任务书学期12131班级软件111一设计目的数据结构是一门实践性较强的软件基础课程为了学好…
课程设计报告课程名称数据结构课题名称迷宫问题姓名吴明华学号20xx16020xx9院系计算机学院通信与信息工程系专业班级通信112…
数据结构与算法课程设计报告姓名林小琼学号0907022118班级09网络工程设计时间20xx11020xx114审阅教师目录一课程…
CENTRALSOUTHUNIVERSITY数据结构课程设计报告题目学生姓名指导教师学院专业班级完成时间交通旅游图的最短路径问题摘…