c# 编程停车场系统

c# 编程停车场系统,第1张

建一个 车 的类 做为 父类。。 其他车辆的种类继承 车这个父类,重写父类的计算价格的方法。。然后停车场做为一个类。 他有一个方法,就是停车, 和 一个存储所有停车位信息的集合。停车的方法有一个参数。一个参数为 车的信息(类型为父类类型)。。这样的话就可以计算出你需要的所有所有信息

#include <stdio.h>

#include <stdlib.h>

#include <malloc.h>

#define ERROR 0

#define OK 1

#define TRUE 1

#define FALSE 0

typedef int SElemType

typedef int Status

typedef int CarStack

typedef int LinkQueue

typedef int InputData

// definition of array based stack

#define STACK_INIT_SIZE 100 //Initial size for memory allocation

#define STACKINCREMENT 10 //incremental size

typedef struct{

SElemType *base //base pointer

SElemType *top//top pointer

CarStack *garage

CarStack *Temp

LinkQueue *road

InputData *inputdata

intstacksize //current size

}SqStack

status PopStack(CarStack *garage, CarStack *Temp, LinkQueue *road, InputData *inputdata)//车出库

{

CarNode *Car = (CarNode *)malloc(sizeof(CarNode))

if (!Car)

{

cout <<"内存分配失败!" <<endl

exit(0)

}

Car->num = inputdata->num

Car->leave = inputdata->t

int i = garage->top

while (i)

{

if (garage->stack[i -1 ]->num != Car->num)

{

garage->top--//进临时车站

Temp->stack[Temp->top] = garage->stack[garage->top]

Temp->top++

i--//没有找到,继续循环查找

if (i == 0)

{

cout <<"没有该车牌的车!" <<endl

}

}

else//获得车辆信息,并回归临时车栈的车辆

{

Car->reach = garage->stack[i -1 ]->reach

Print(Car)//打印车辆收费单

garage->top--

while (Temp->top>0)//回归临时车站的车辆

{

Temp->top--

garage->stack[garage->top] = Temp->stack[Temp->top]

garage->top++

}

if (road->head != road->rear)//从便道出来一辆车到停车场

{

garage->stack[garage->top] = road->head->next

cout <<endl

cout <<"车场有空位,便道第一辆车可以进入!" <<endl

garage->top++

road->head = road->head->next

}

i = 0//已经找到,退出循环

}

}

}

void InfoStack(CarStack *garage)//车库车辆信息

{

if (garage->top ==0 )

cout <<"车库里没有车!" <<endl

else

{

cout <<" _________________________ " <<endl

cout <<"| |" <<endl

cout <<"|车 库|" <<endl

cout <<"|位置 车辆号码 到达时间|" <<endl

for (int i = 0i<garage->topi++)

{

cout <<"| " <<i +1 <<" " <<garage->stack[i]->num <<" " <<garage->stack[i]->reach <<" |" <<endl

}

cout <<"|_________________________|" <<endl

}

}

void InfoQueue(LinkQueue *road)//便道车辆信息

{

CarNode *p

p = road->head->next

int i = 0

if (road->head == road->rear)

cout <<"便道里没有车!" <<endl

else

{

cout <<" __________________ " <<endl

cout <<"| |" <<endl

cout <<"| 便道 |" <<endl

cout <<"| 位置车辆号码 |" <<endl

while (p != NULL)

{

cout <<"| " <<++i <<"" <<p->num <<" |" <<endl

p = p->next

}

cout <<"|__________________|" <<endl

}

free(p)

}

void Print(CarNode *Car)//打印出站车辆信息

{

int rh, lh

float t

rh = Car->reach

lh = Car->leave

t = (lh - rh) * 60 *0.01

cout <<" ---------------------------------------------------- " <<endl

cout <<"|车辆的号码进库时间 离开时间 车费(元) |" <<endl

cout <<"|" <<Car->num <<" " <<rh <<" " <<lh <<" " <<t <<" |" <<endl

cout <<"|____________________________________________________|" <<endl

}

void Input(InputData *inputdata)

{

int maxsize

cout <<"请输入停车场容量 Maxsize (最多为5) : "

do

{

cin >>maxsize

if (!(maxsize<5 &&maxsize>0))

{

cout <<"输入有误,请重新输入停车场容量:"

}

} while (!(maxsize<5 &&maxsize>0))

int i = 0, j =0 , k =1

char c

int n

CarStack garage, Temp

LinkQueue road

CarNode car

InitStack(&garage, maxsize)

InitStack(&Temp, maxsize)

InitQueue(&road)

while (k)

{

i = 0

while (!i)

{

cout <<" ____________________________________________________________" <<endl

cout <<"||" <<endl

cout <<"| 欢迎光临停车场,本停车场每分钟收费元 |" <<endl

cout <<"||" <<endl

cout <<"| 请输入车库命令,格式如下(命令,车牌号,入库时间) |" <<endl

cout <<"||" <<endl

cout <<"| A(a)-入库 D(d)-离开 P(p)-查看停车场车辆 P(p)-查看过道车辆 |" <<endl

cout <<"|____________________________________________________________|" <<endl

cin >>(inputdata->command) >>(inputdata->num) >>(inputdata->t)

c = inputdata->command

n = inputdata->num

if (c != 'A'&&c != 'a'&&c != 'D'&&c != 'd'&&c != 'W'&&c != 'w'&&c != 'P'&&c != 'p'&&c != 'E'&&c != 'e')

{

cout <<"命令不正确,请重新输入!" <<endl

i =0

}

else

i = 1

// if(SearchInGarage(garage,n,maxsize)&&SearchInRoad(road,n))

// {

// i =0

// cout<<"命令不正确,请重新输入!"<<endl

// }

}

switch (c)

{

case 'A':

case 'a':

GetCarNode(&garage, &road, inputdata, maxsize)//获取车辆信息

break

case 'D':

case 'd':

PopStack(&garage, &Temp, &road, inputdata)//车出库

break

case 'P':

case 'p'://查询停车场的信息

InfoStack(&garage)//车库车辆信息

break

case 'W':

case 'w'://查询侯车场的信息

InfoQueue(&road)//便道车辆信息

break

case 'E':

case 'e':

k =0

break

default:

break

}

}

cout <<endl

cin.clear()

}

bool SearchInGarage(CarStack garage, int n, int maxsize)//a表示要查找的车牌号,如果在停车场里面,就返回true

{

bool tag = false

for (int i =0 i<maxsize || (i != garage.top)i++)

{

if (n == garage.stack[i]->num)

{

tag = true

break

}

}

return tag

}

bool SearchInRoad(LinkQueue road, int n)//a表示要查找的车牌号,如果在通道里面,就返回true

{

bool tag = false

StackNode *p

p = (StackNode *)malloc(sizeof(StackNode))

if (road.head != road.rear)//如果队列非空

{

p = road.head

while (p != road.rear)

{

++p

if (p->num == n)

tag = true

}//退出此while循环时p指向最后一个元素

}

free(p)

return tag

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11509244.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存