1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
| #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <string.h> #include <time.h>
#define MAX_STOP 5 #define MAX_PAVE 4 #define MAX_History 20
typedef struct{ int TimeIn; int TimeOut; long int leave_time; char ct[50]; char Lincense[10]; }Car;
typedef struct{ Car Stop[MAX_STOP]; int top; }Stopping;
typedef struct{ Car Stop[MAX_History]; int top; }History;
typedef struct{ Car Pave[MAX_PAVE]; int count; int front, rear; }Pavement;
typedef struct{ Car Let[MAX_STOP]; int top; }Buffer;
typedef struct{ Car Wait[MAX_PAVE]; int count; int front, rear; }Waiting;
Stopping s; Pavement p; Buffer b; Car c; Waiting w; History h; char C[10];
void Car_Come(); void Car_Leave(); void Stop_To_Pave(); void Stop_To_Buff(); void Leave_Pavement(); void DisPlay(); void DisPlayPave(); void Welcome(); void SmallWelcome(); void Car_Leave_menu(); void Search(); void lucky_draw(int a); int draw_result(); int mod_price(); void history();
History* history_push(Stopping s,time_t t1) ;
float Price = 6;
void Car_Come(){ printf("请输入即将停车的车牌号:"); scanf("%s", &C); int i = s.top; while(i != -1){ if(0 == strcmp(s.Stop[i].Lincense, C)){ printf("输入有误,此汽车已存在!\n"); return; } i--; } int k = MAX_PAVE; while(k != 0){ if(0 == strcmp(p.Pave[k].Lincense, C)){ printf("输入有误,此汽车已存在!\n"); return; } k--; } if (s.top >= MAX_STOP - 1){ Stop_To_Pave(); } else{ time_t t1; long int t = time(&t1); char* t2; t2 = ctime(&t1); s.Stop[++s.top].TimeIn = t; strcpy(s.Stop[s.top].ct, t2); strcpy(s.Stop[s.top].Lincense, C); printf("牌照为%s的汽车停入停车位的%d车位,当前时间:%s\n", C, s.top+1, t2); } }
void Search(){ printf("请输入要搜索的车牌号:\n"); scanf("%s", &C); int i, j, k, flag = 0; time_t t1; long int t = time(&t1); if(s.top >= 0){ for(i = s.top; i >= 0; i--){ if(0 == strcmp(s.Stop[i].Lincense, C)){ printf("此汽车在停车场内,信息如下:\n"); printf("\t车牌号\t\t停车位序\t当前所需支付金额\t进入时间\t\n"); printf("\t%s\t第%d个\t\t%0.f元\t\t\t%s", s.Stop[i].Lincense, i+1, (Price/60) * (t - s.Stop[i].TimeIn), s.Stop[i].ct); flag = 1; break; } } } if(flag == 0 && p.count > 0){ i = p.front, k = 1, j = p.rear; while(i != j ){ if(0 == strcmp(p.Pave[i].Lincense, C)){ printf("此汽车在停便道上\n"); printf("\t车牌号\t\t停车位序\n"); printf("\t%s\t第%d个",p.Pave[i].Lincense, k); flag = 2; break; } i++; k++; } } if(0 == flag) printf("停车场内外不存在该汽车信息!\n"); }
void Car_Leave(){ printf("请输入即将离开的车牌号:"); scanf("%s", &C); int i, j, flag = 1, flag2 = 1; if(s.top >= 0){ for(i = s.top; i >=0; i-- ){ flag = flag * strcmp(s.Stop[i].Lincense, C); } }
if(0 == flag){ Stop_To_Buff(); }
if(flag !=0 ) printf("停车场内没有该汽车的信息!\n"); }
void Leave_Pavement(){ int i, j, flag = 0; printf("请输入即将离开的车牌号:"); scanf("%s", &C); if(p.count <= 0){ printf("便道上不存在汽车!\n"); return; } while(p.count > 0){ i = p.front; if(0 == strcmp(p.Pave[i].Lincense, C)){ break; } printf("牌照为%s的汽车暂时从便道进入临时便道\n", p.Pave[p.front].Lincense); strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense); p.front = (p.front + 1) % MAX_PAVE; w.rear = (w.rear + 1) % MAX_PAVE; w.count++; p.count--; } printf("\n牌照为%s的汽车从便道上开走,不收取任何费用!\n\n", p.Pave[i].Lincense); p.front = (p.front + 1) % MAX_PAVE; p.count--; while(p.count > 0){ printf("牌照为%s的汽车暂时从便道进入临时便道\n", p.Pave[p.front].Lincense); strcpy(w.Wait[w.rear].Lincense, p.Pave[p.front].Lincense); p.front = (p.front + 1) % MAX_PAVE; w.rear = (w.rear + 1) % MAX_PAVE; w.count++; p.count--; } while(w.count > 0){ printf("\n牌照为%s的汽车返回便道\n",w.Wait[w.front].Lincense); strcpy(p.Pave[p.rear].Lincense, w.Wait[w.front].Lincense); w.front = (w.front + 1) % MAX_PAVE; p.rear = (p.rear + 1) % MAX_PAVE; w.count--; p.count++; } }
void Stop_To_Buff(){ while (s.top >= 0){ if(0 == strcmp(s.Stop[s.top].Lincense, C)){ break; } strcpy(b.Let[b.top++].Lincense, s.Stop[s.top].Lincense); printf("牌照为%s的汽车暂时退出停车场\n", s.Stop[s.top--].Lincense); } printf("牌照为%s的汽车从停车场开走\n", s.Stop[s.top].Lincense); time_t t1; long int t = time(&t1); s.Stop[s.top].TimeOut = t; char* t2; t2 = ctime(&t1); printf("离开时间%s\n需付费%.0f元\n", t2,(Price/60) * (t - s.Stop[s.top].TimeIn)); history_push(s,t1) ; s.top--; while(b.top > 0){ strcpy(s.Stop[++s.top].Lincense, b.Let[--b.top].Lincense); printf("牌照为%s的汽车停回停车位%d车位\n", b.Let[b.top].Lincense, s.top+1); } while(s.top < MAX_STOP-1){ if(0 == p.count) break; else{ strcpy(s.Stop[++s.top].Lincense, p.Pave[p.front].Lincense); printf("牌照为%s的汽车从便道中进入停车位的%d车位\n", p.Pave[p.front].Lincense, s.top+1); time_t t1; long int t = time(&t1); char* t2; s.Stop[s.top].TimeIn = t; p.front = (p.front + 1) % MAX_PAVE; p.count--; } } }
History* history_push(Stopping s,time_t t1) { h.Stop[++h.top].TimeIn = s.Stop[s.top].TimeIn; h.Stop[h.top].leave_time = time(&t1); strcpy(h.Stop[h.top].ct, s.Stop[s.top].ct); strcpy(h.Stop[h.top].Lincense, s.Stop[s.top].Lincense); } void history() { int i = h.top; if(-1 == i) printf("暂时没有停车记录哦!\n"); printf("\t车牌号\t\t停放时间\t已支付金额\t停放位序\n"); while(i != -1){ printf("\t%s\t\t%d分%d秒\t\t%.0f元\t\t\t第%d个\n", h.Stop[i].Lincense, (h.Stop[i].leave_time-h.Stop[i].TimeIn)/60,(h.Stop[i].leave_time-h.Stop[i].TimeIn) % 60, (Price/60) * (h.Stop[i].leave_time - h.Stop[i].TimeIn), i+1); i--; } }
void Stop_To_Pave(){ if(p.count > 0 && (p.front == (p.rear + 1) % MAX_PAVE)) printf("便道已满,请下次再来!\n"); else{ strcpy(p.Pave[p.rear].Lincense, C); p.rear = (p.rear + 1) % MAX_PAVE; p.count++; printf("牌照为%s的汽车停入便道上\n", C); } }
void DisPlay(){ int i = s.top; if(-1 == i) printf("停车场目前为空\n"); time_t t1; long int t = time(&t1); printf("\t车牌号\t\t停放时间\t当前所需支付金额\t停放位序\n"); while(i != -1){ printf("\t%s\t\t%d分%d秒\t\t%.0f元\t\t\t第%d个\n", s.Stop[i].Lincense, (t - s.Stop[i].TimeIn)/60,(t - s.Stop[i].TimeIn) % 60, (Price/60) * (t - s.Stop[i].TimeIn), i+1); i--; } }
void DisPlayPave(){ int i = p.front; int k = 1; if(0 == p.count) printf("便道目前为空\n"); printf("\t车牌号\t\t停放位序\n"); while(i != p.rear && k <= p.count){ printf("\t%s\t第%d个\n", p.Pave[i].Lincense, k++); i = (i + 1) % MAX_PAVE; } }
void Car_Leave_menu(){ while(1){ system("cls"); SmallWelcome(); int i, cho; scanf("%d", &i); if(1 == i) Car_Leave(); if(2 == i) Leave_Pavement(); if(3 == i) draw_result(); if(4 == i) return; printf("\n返回请输入0\n"); top: scanf("%d", &cho); if(0 == cho){ continue; } else{ printf("您的输入有误,请重新输入\n"); goto top; } } }
void SmallWelcome(){ printf ("\t*******************目前停车场状况***********************\n"); printf ("\t停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d/%d辆车\n", MAX_STOP, s.top+1, (p.rear + MAX_PAVE - p.front) % MAX_PAVE, MAX_PAVE-1); printf ("\t********************************************************\n"); printf ("\t---------Welcome to Ep's Car Parking next time----------\n"); printf ("\t* *\n"); printf ("\t* 1.从停车场内驶出汽车 *\n"); printf ("\t* 2.从便道上驶出汽车 *\n"); printf ("\t* 3.进入抽奖 *\n"); printf ("\t* 4.退出子管理系统 *\n"); printf ("\t*请注意:从停车场内驶离的汽车按照%.0f元/分钟计费 *\n",Price); printf ("\t*望周知:从便道上驶离的汽车不收取费用 *\n"); printf ("\t* *\n"); printf ("\t*------------------------------------------------------*\n"); printf ("\t--------Press key(1/2/3) to continue the program--------\n"); } void HideCursor(){ CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); }
void lucky_draw(int a) { int e; if( a!=1 ) { printf("你选择了不抽奖"); return; } else srand((unsigned)time(NULL)); e=100+rand()%1000; printf("中奖号码为666或888,你的号码为%d\n",e); { if(a==666||a==888) { printf("恭喜你获得了免费停车一年特权"); return; } else { printf("很遗憾您没有中奖"); return; } } } int draw_result()
{ int select; printf("请确认是否进行抽奖,如果抽奖请按1,如果不请随意\n"); scanf("%d",&select); lucky_draw(select); return 0; }
int mod_price(){ printf("修改停车场计费(默认6元一分钟):\n"); printf("在此输入:"); int temp ; scanf("%d",&temp); Price = temp; return Price; }
void Welcome(){ time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf ("\t\t\t%s", asctime(timeinfo) ); HideCursor(); printf ("\t*******************目前停车场状况***********************\n"); printf ("\t停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d/%d辆车\n", MAX_STOP, s.top+1, (p.rear + MAX_PAVE - p.front) % MAX_PAVE, MAX_PAVE-1); printf ("\t********************************************************\n"); printf ("\t--------------Welcome to Ep's Car Parking---------------\n"); printf ("\t* *\n"); printf ("\t* 1.停车场停车信息显示 *\n"); printf ("\t* 2.便道上停车信息显示 *\n"); printf ("\t* 3.汽车到达停车场操作 *\n"); printf ("\t* 4.汽车离去停车场操作 *\n"); printf ("\t* 5.查找汽车功能 *\n"); printf ("\t* 6.停车历史记录 *\n"); printf ("\t* 7.系统设置 *\n"); printf ("\t* 8.退出管理系统 *\n"); printf ("\t* 收费标准:本停车场按照%.0f元/分钟计费,望周知 *\n",Price); printf ("\t* *\n"); printf ("\t*------------------------------------------------------*\n"); printf ("\t---------Press key(1/2/3/4/5/6/7) to run program----------\n\n\n"); printf("请输入:"); }
int main(){ s.top = -1; h.top = -1; b.top = 0; p.rear = 0; p.count = 0; p.front = 0; w.count = 0; w.front = 0; w.rear = 0; while(1){ system("color 0B"); system("cls"); Welcome(); int i, cho; scanf("%d", &i); if(1 == i) DisPlay(); if(2 == i) DisPlayPave(); if(3 == i) Car_Come(); if(4 == i) Car_Leave_menu(); if(5 == i) Search(); if(6 == i) history(); if(7 == i) mod_price();
if(8 == i) { printf("\n欢迎您再次使用本系统呦 ε=ε=ε=(~ ̄▽ ̄)~\n\n"); break; } printf("\n返回请输入0\n"); begin: scanf("%d", &cho); if(0 == cho){ continue; } else{ printf("您的输入有误,请重新输入\n"); goto begin; } } return 0; }
|