杭电软件工程学院程序设计实践
#include
#include
#include
#include
#include
#include
#define PASSWORD "000"
#define PRICE 5.0
#define END 24
#define SPEED_CAR 150
#define SELCET 300
#define EXIST 1 //EXIST代表当前车位有车
#define NO 0 //NO 代当前车位表没车
/*
创建一个二维数组,模拟车库的平面示意图
创建两个队列,模拟进库和出库的队列
车辆的队列与出库之间通过坐标进行联系
车位有空,但有既有车库又有车出库时,
遵照先出后进的原则,
即,出库的优先级高于入库的优先级*
*/
struct Coordinate
{
int x;
int y;
};
struct Car
{
int number; //车牌号
int time_inner; //在车库里的停车时间
int probability; //存储车辆离去的概率,1,2,3,4级数一次增大
double cost; //该次停车应付费用
char time_insert; //进库时间
char time_left; //出库时间, 出库的时间等于进库时间加出库时的probability
Coordinate local; //当前车辆所在/要出的库编号
Car *next; //由于车辆数并不确定,因此用链式存储
};
int Time=0;
double Sum_Money=0.0;
bool Garage[2][10]; //用10*2的方格模拟车库的平面示意图
Car *Head_Out=(Car *)malloc(sizeof(Car)); //在车库里,准备出来的车队
Car *Head_In=(Car *)malloc(sizeof(Car)); //在外面排队,准备进库的车队
/* 车库的平面示意、车队的头指针、收益设为全局变量,这样方便各函数的调用*/
void gotoxy(int x, int y)
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int Insert_Password(int flag)
{
char key[20],c;
int count=0;
if(flag)
{
system("cls");
puts("\n温馨提示,你的输入密码有误\n\n");
}
printf("\n请输入密码 : ");
while(c=getch(),c!='\r')
{
if(c==8)
{
system("cls");
if(flag)
printf("\n温馨提示,你的输入密码有误\n\n");
printf("\n请输入密码 : ");
if(count>0)
{
key[--count]='\0';
for(int i=0;i
printf("●");
}
}
else if(count>=0)
{
printf("●");
key[count++]=c,key[count]='\0';
}
}
if(strcmp(key,PASSWORD)==0)
{
system("cls");
gotoxy(35,5);
puts("密码正确");
Sleep(2000);
return 1;
}
else return Insert_Password(1);
}
void Enter()
{
for(int i=0;i<15;i++)
{
gotoxy(35,5);
puts("正在登录\n");
Sleep(200);
for(int j=0;j
{
if(!j)
printf("\t\t\t■");
else printf("■");
}
}
system("cls");
}
void Get_Time() //获取进出车库的时间
{
time_t rawtime;
struct tm *timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
gotoxy(61,1);
printf("%d",timeinfo->tm_hour);
gotoxy(66,1);
printf(