停车场管理程序实验报告

发布时间:2018-11-23 23:38:17   来源:文档文库   
字号:

停车场管理程序实验报告

实验题目: 停车场管理程序

实验要求:

编写一个程序实现停车场的管理功能。并且,以栈模拟停车场,以队列模拟车场外到达便道的过程,按照从终端读入的输入数据序列进行模拟管理。栈以顺序结构实现,队列顺序循环结构实现。

用户输入的命令有以下5种:

(1)汽车到达;

(2)汽车离去输出停车场中的所有汽车牌号;

(3)输出候车场中的所有汽车牌号;

(4)退出系统运行。

实验内容:

3.1 栈的抽象数据类型:

ADT Stack{

数据对象:D={ai|aiElemSet, i=1,2, ,n, n0}

数据关系:R1={|ai-1,aiD, i=1,2, ,n }

约定an端为栈顶,a1端为栈底。

基本操作:{

InitStack( &S )

操作结果:构造一个空栈S

DestroyStack ( &S )

初始条件:栈S已存在。

操作结果:销毁栈S

ClearStack( &S )

初始条件:栈S已存在。

操作结果:将S清为空栈。

StackEmpty( S )

初始条件:栈S已存在。

操作结果:若S为空栈,则返回TRUE,否则返回FALSE

StackLength( S )

初始条件:栈S已存在。

操作结果:返回S的数据元素个数,即栈的长度。

GetTop( S, &e )

初始条件:栈S已存在且非空。

操作结果:用e返回S的栈顶元素。

Push( &S, e )

初始条件:栈S已存在。

操作结果:插入元素e为新的栈顶元素。

Pop( &S, &e )

初始条件:栈S已存在且非空。

操作结果:删除S的栈顶元素,并用e返回其值。

StackTraverse( S, visit() )

初始条件:栈S已存在且非空。

操作结果:从栈底到栈顶依次对S的每个数据元素调用函数visit()。一旦visit()失败,则操作失败。

}ADT Stack

3.2存储结构的定义;

#define N 3

#define M 4

#define price 2

typedef struct

{

int carno[N];

int cartime[N];

int top;

}SqStack;

typedef struct

{

int carno[M];

int front,rear;

}SqQueue;

3.3基本操作实现:

/* 创建栈 */

void InitStack(SqStack *&s)

{

s = (SqStack *)malloc(sizeof(SqStack));

s->top = -1;

}

/* 摧毁栈 */

void DestroyStack(SqStack *&s)

{

free(s);

}

/* 查看栈是否为空 */

bool StackEmpty(SqStack *s)

{

return s->top==-1;

}

/* 进栈 */

bool Push(SqStack *&s,int e1,int e2)

{

if(s->top == N - 1)

{

return false;

}

s->top++;

s->carno[s->top] = e1;

s->cartime[s->top] = e2;

// printf(">>停车场中位置:%d\n",e1);

return true;

}

bool StackFull(SqStack *s)

{

return s->top == N-1;

}

/* 出栈 */

bool Pop(SqStack *&s,int &e1,int &e2)

{

if(s->top == -1)

return false;

e1 = s->carno[s->top];

e2 = s->cartime[s->top];

s->top--;

return true;

}

void DispStack(SqStack *s)

{

printf(" >>停车场中的车辆为:");

int i;

for(i = s->top; i >= 0; --i)

{

printf("%d ",s->carno[i]);

}

printf("\n");

}

/***************** 以下为队列 *****************/

/* 初始化队列 */

void InitQueue(SqQueue *&q)

{

q = (SqQueue *)malloc(sizeof(SqQueue));

q->front=q->rear=0;

}

/* 释放队列 */

void DestroyQueue(SqQueue *&q)

{

free(q);

}

/* 查看队列是否为空 */

bool QueueEmpty(SqQueue *q)

{

return q->front == q->rear;

}

bool QueueFull(SqQueue *q)

{

return (q->rear + 1)% M == q->front;

}

/* 进队 */

bool enQueue(SqQueue *&q,int e)

{

if((q->rear + 1) % M == q->front)

return false;

q->rear=(q->rear + 1)%M;

q->carno[q->rear] = e;

return true;

}

/* 出队 */

bool deQueue(SqQueue *&q,int &e)

{

if(q->front == q->rear)

return false;

q->front = (q->front + 1) % M;

e = q->carno[q->front];

return true;

}

3.4解题思路:

1.通过栈模拟停车场

2.通过队列模拟候车场

3.然后全程模拟即可。

3.5解题过程

实验源代码如下:

#include

#include

#define N 3

#define M 4

#define price 2

typedef struct

{

int carno[N];

int cartime[N];

int top;

}SqStack;

typedef struct

{

int carno[M];

int front,rear;

}SqQueue;

/* 创建栈 */

void InitStack(SqStack *&s)

{

s = (SqStack *)malloc(sizeof(SqStack));

s->top = -1;

}

/* 摧毁栈 */

void DestroyStack(SqStack *&s)

{

free(s);

}

/* 查看栈是否为空 */

bool StackEmpty(SqStack *s)

{

return s->top==-1;

}

/* 进栈 */

bool Push(SqStack *&s,int e1,int e2)

{

if(s->top == N - 1)

{

return false;

}

s->top++;

s->carno[s->top] = e1;

s->cartime[s->top] = e2;

// printf(">>停车场中位置:%d\n",e1);

return true;

}

bool StackFull(SqStack *s)

{

return s->top == N-1;

}

/* 出栈 */

bool Pop(SqStack *&s,int &e1,int &e2)

{

if(s->top == -1)

return false;

e1 = s->carno[s->top];

e2 = s->cartime[s->top];

s->top--;

return true;

}

void DispStack(SqStack *s)

{

printf(" >>停车场中的车辆为:");

int i;

for(i = s->top; i >= 0; --i)

{

printf("%d ",s->carno[i]);

}

printf("\n");

}

/**************** 以下为队列 ******************/

/* 初始化队列 */

void InitQueue(SqQueue *&q)

{

q = (SqQueue *)malloc(sizeof(SqQueue));

q->front=q->rear=0;

}

/* 释放队列 */

void DestroyQueue(SqQueue *&q)

{

free(q);

}

/* 查看队列是否为空 */

bool QueueEmpty(SqQueue *q)

{

return q->front == q->rear;

}

bool QueueFull(SqQueue *q)

{

return (q->rear + 1)% M == q->front;

}

/* 进队 */

bool enQueue(SqQueue *&q,int e)

{

if((q->rear + 1) % M == q->front)

return false;

q->rear=(q->rear + 1)%M;

q->carno[q->rear] = e;

return true;

}

/* 出队 */

bool deQueue(SqQueue *&q,int &e)

{

if(q->front == q->rear)

return false;

q->front = (q->front + 1) % M;

e = q->carno[q->front];

return true;

}

void DispQueue(SqQueue *q)

{

printf(" >>候车场中的车辆为:");

int i ;

i = (q->front + 1) % M;

printf("%d ",q->carno[i]);

while((q->rear - i + M) % M > 0)

{

i = (i + 1) % M;

printf("%d ",q->carno[i]);

}

printf("\n");

}

int main( )

{

int comm;

int no, e1, e2, time;

int i, j;

SqStack *st, *st1;

SqQueue *qu;

InitStack(st);

InitStack(st1);

InitQueue(qu);

while(1)

{

printf("输入指令(1:到达 2:离开 3:停车场 4:候车场 0:退出):");

scanf("%d",&comm);

if(comm == 0)

{

if(!StackEmpty(st))

{

DispStack(st);

}

else

{

printf(" >>停车场中无车辆 !\n");

}

if(!QueueEmpty(qu))

{

DispQueue(qu);

}

else

{

printf(" >>候车场中无车辆 !\n");

}

break;

}

else if(comm == 1)

{

printf(" 车号 到达时间 ");

scanf("%d%d",&no,&time);

if(!StackFull(st))

{

Push(st,no,time);

printf(">>停车场中位置:%d\n",st->top + 1);

}

else

{

if(!QueueFull(qu))

{

enQueue(qu,no);

printf(">>候车场中位置:%d\n",qu->rear);

}

else

{

printf(">>候车场位置已满!不能停车!\n");

}

}

}

else if(comm == 2)

{

printf(" 车号 离开时间 ");

scanf("%d%d",&no,&time);

for(i = 0;i <= st->top && st->carno[i] != no; ++i);

if(i>st->top)

{

printf(">>未找到该编号的汽车\n");

}

else

{

for(j = st->top; j > i; --j)

{

Pop(st,e1,e2);

Push(st1,e1,e2);

}

Pop(st,e1,e2);

printf(" >>%d 汽车停车费用:%d\n",no,(time - e2) * price);

while(!StackEmpty(st1))

{

Pop(st1,e1,e2);

Push(st,e1,e2);

}

if(!QueueEmpty(qu))

{

deQueue(qu,e1);

Push(st,e1,time);

}

}

}

else if(comm == 3)

{

if(!StackEmpty(st))

{

DispStack(st);

}

else

{

printf(">>停车场中无车辆 !\n");

}

}

else if(comm == 4)

{

if(!QueueEmpty(qu))

{

DispQueue(qu);

}

else

{

printf(">>候车场中无车辆 !\n");

}

}

else

{

printf("指令输入错误!请重新输入!\n");

}

printf("\n");

}

DestroyStack(st);

DestroyStack(st1);

DestroyQueue(qu);

return 0;

}

实验结果:

2010年读书节活动方案

一、     活动目的:

书是人类的朋友,书是人类进步的阶梯!为了拓宽学生的知识面,通过开展“和书交朋友,遨游知识大海洋”系列读书活动,激发学生读书的兴趣,让每一个学生都想读书、爱读书、会读书,从小养成热爱书籍,博览群书的好习惯,并在读书实践活动中陶冶情操,获取真知,树立理想!

二、活动目标:

1、通过活动,建立起以学校班级、个人为主的班级图书角和个人小书库。

2、通过活动,在校园内形成热爱读书的良好风气。

3、通过活动,使学生养成博览群书的好习惯。

4、通过活动,促进学生知识更新、思维活跃、综合实践能力的提高。

三、活动实施的计划

1 做好读书登记簿

1 每个学生结合实际,准备一本读书登记簿,具体格式可让学生根据自己喜好来设计、装饰,使其生动活泼、各具特色,其中要有读书的内容、容量、实现时间、好词佳句集锦、心得体会等栏目,高年级可适当作读书笔记。

2 每个班级结合学生的计划和班级实际情况,也制定出相应的班级读书目标和读书成长规划书,其中要有措施、有保障、有效果、有考评,简洁明了,易于操作。

3)中队会组织一次“读书交流会”展示同学们的读书登记簿并做出相应评价。

2 举办读书展览:

各班级定期举办“读书博览会”,以“名人名言”、格言、谚语、经典名句、“书海拾贝”、“我最喜欢的___”、“好书推荐”等形式,向同学们介绍看过的新书、好书、及书中的部分内容交流自己在读书活动中的心得体会,在班级中形成良好的读书氛围。

3 出读书小报:

本文来源:https://www.2haoxitong.net/k/doc/9783500749d7c1c708a1284ac850ad02df800718.html

《停车场管理程序实验报告.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式