# Include <stdio. h> # include <stdlib. h> # include <malloc. h> # define max 20 // parking capacity # define price 20 // 20 RMB/hour typedef struct {float hour; float min;} time; typedef struct {char license [10]; time reach, leave;} carnode; typedef struct {carnode * base; carnode * Top; int Len;} sqstack; void initstack (sqstack & S) {S. base = (carnode *) malloc (max * sizeof (carnode); If (! S. base) Exit (0); S. top = S. base; S. len = max;} int emptystack (sqstack s) {If (S. top = S. base) return 1; else return 0;} void push (sqstack & S, carnode e) {* s. top ++ = E;} void POP (sqstack & S, carnode & E) {e = * -- S. top;} typedef struct node {carnode data; node * Next;} qnode, * queueptr; typedef struct {queueptr front; queueptr rear;} linkqueue; void initqueue (linkqueue & Q) {q. rear = (queueptr) malloc (sizeof (carnode); If (! Q. rear) Exit (0); q. front = Q. rear; q. front-> next = NULL;} void enqueue (linkqueue & Q, carnode e) {queueptr P; P = (queueptr) malloc (sizeof (carnode); If (! P) Exit (0); P-> DATA = E; P-> next = NULL; q. rear-> next = P; q. rear = P;} void dequeue (linkqueue & Q, carnode & E) {queueptr P; P = Q. front-> next; E = p-> data; q. front-> next = p-> next; If (P = Q. rear) Q. front = Q. rear; free (p);} int emptyqueue (linkqueue q) {If (Q. front = Q. rear) return 1; else return 0;} void reach (sqstack & Park, linkqueue & PAVE) {carnode E; printf ("Enter the license plate number :"); scanf ("% s", E. license); If (Park. top-park.base <Park. Len) {// there is space available in the parking lot printf ("Enter % s into the parking lot time:", E. license); scanf ("% F", & E. reach. hour, & E. reach. min); printf ("please park % s at LOCATION % d! \ N ", E. License, park. top-park.base + 1); push (Park, e);} else {printf (" Please wait! \ N "); dequeue (PAVE, e) ;}} void leave (sqstack & Park, linkqueue & pave, sqstack & temp) {int locate; float PRI; carnode E; if (! Emptystack (Park) {printf ("Enter the parking space number (1 ~ % D): ", Park. the top-park.base); scanf ("% d", & locate); While (Park. top-park.base> locate) {Pop (Park, e); push (temp, e);} POP (Park, e); printf ("Enter % s departure time :", e. license); scanf ("% F", & E. leave. hour, & E. leave. min); pri = (E. leave. hour-e.reach.hour) + (E. leave. min-e.reach.min)/60) * price; printf ("license plate number \ t entry time departure time payment fee \ n"); printf ("% s \ t %. 0f: %. 0f \ t %. 0f: %. 0f \ t %. 3f \ n ", E. license, E. reach. hour, E. reach. min, E. leave. hour, E. leave. Min, PRI); While (temp. top-temp.base> = 1) {Pop (temp, e); push (Park, e);} If (Park. top-park.base = Park. len-1 & pave. front! = Pave. rear) {printf ("Enter the parking space % d", Park. len); dequeue (PAVE, e); printf ("Please take the % s car on the driveway to the location % d stop! \ N ", E. license, Park. len); printf ("Enter % s into the parking lot time:", E. license); scanf ("% F", & E. reach. hour, & E. reach. min); push (Park, e);} else {printf ("no car is waiting in the driveway! \ N ") ;}} else printf (" no car in the parking lot! \ N ") ;}void seepark (sqstack s) {int I; carnode * P; P = S. Base; If (emptystack (s) printf (" parking lot is blank! \ N "); for (I = 1; I <= S. top-S.base; I ++) {printf ("license plate number \ t entry time \ n"); printf ("% s \ t %. 0f: %. 0f \ n ", p-> license, p-> reach. hour, p-> reach. min); P ++ ;}} void seepave (linkqueue q) {queueptr P; P = Q. front-> next; If (emptyqueue (q) printf ("it's empty! \ N "); While (p) printf (" license plate number: % s \ n ", p-> data. license) ;}int main () {sqstack temp, Park; linkqueue pave; int choice; initstack (Park); initstack (temp); initqueue (PAVE ); printf ("------- welcome to this parking system ---------- \ n"); printf ("\ t 1. vehicle arrival registration \ n "); printf (" \ t 2. vehicle departure statistics \ n "); printf (" \ t 3. display parking lot information \ n "); printf (" \ t 4. display convenience Vehicle Information \ n "); printf (" \ t 0. log out of the system \ n "); do {printf (" Enter the ID of the information you want to view (1 2 3 4), and press 0 to exit \ n "); scanf ("% d", & choice); If (Cho Ice> 4 & choice <0) {printf ("incorrect input. Please try again! \ N "); continue;} switch (choice) {Case 1: REACH (Park, pave); break; Case 2: Leave (Park, pave, temp); break; case 3: seepark (Park); break; Case 4: seepave (PAVE); break; Case 0: exit (0); // exit the main program default: break ;}} while (1); Return 0 ;}