In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to write the code of parking management system in C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to write the code for the parking management system in C language.
Design topic
The parking lot is a narrow passageway in the north-south direction where n cars can be parked, and there is only one gate for cars to enter and exit. Cars in the parking lot are arranged from north to south according to the order of arrival time (the gate is at the southernmost end, and the first car to arrive is parked at the northernmost end of the parking lot). Then the later cars can only wait on the sidewalk outside the door, and once there is a car leaving, the first car on the sidewalk can enter. When a car in the parking lot is about to leave, the vehicle entering after it must first leave the yard to make way for it. When the car leaves the gate, other vehicles will enter the parking lot in the original order. Each car parked in the parking lot must pay a fee according to the length of time it stays when it leaves the parking lot. Try to compile a simulation program for the parking lot to manage according to the above requirements. The program is required to output the parking location (parking lot or sidewalk) after each car arrives, as well as the fee that a car should pay when it leaves the parking lot and the time it stays in the parking lot.
Demand analysis
Because there is only one gate in the parking lot, when a car in the parking lot is about to leave, the vehicle entering after it must first exit the parking lot to make way for it, and then exit after entering the parking lot, which accords with the "last in first out, first in first out" operation characteristics of the stack. therefore, a stack can be used to simulate the parking lot. When the parking lot is full, other vehicles who continue to come can only park on the sidewalk. According to the parking characteristics of the sidewalk, the vehicles in line first leave the sidewalk and enter the parking lot, which accords with the operating characteristics of the queue of "first in, first out, then in and out". Therefore, a queue can be used to simulate the sidewalk. The vehicles in the middle of the parking lot can propose to leave the parking lot, and the vehicles arriving after the vehicles that want to leave in the parking lot must first leave the parking lot to make way for it, and then these vehicles enter the parking lot in the order in which they originally arrived at the parking lot. Therefore, on the basis of a stack and a queue already set up in front, there needs to be a place to save the vehicles leaving the parking lot in order to make way. Since you exit the parking lot first and then enter the parking lot, it is clear that the site where vehicles are saved should also be simulated with a stack. Therefore, two stacks and one queue are needed in the process of solving this problem. The stack is implemented in a sequential structure and the queue is implemented in a linked list structure.
Program code # include#include#include#include#define MAXSIZE 5#define price 0.01#pragma warning (disable: 4996) using namespace std;typedef struct time {int hour; int min;} Time;/ time node / typedef struct carnews {char num [10]; Time reach; Time leave;} CarNode;/ vehicle information node / typedef struct NODE {CarNode* stack [MAXSIZE + 1]; maximum available capacity of int top; / / stack} SeqStackCar / simulated parking lot / typedef struct car {CarNode* data; struct car* next;} QueueNode; / / simulated cars enter the sidewalk, and cars on the sidewalk enter the parking lot typedef struct Node {QueueNode* head; / / head pointer QueueNode* rear; / / tail pointer} LinkQueueCar;/ simulated sidewalk / void InitStack (SeqStackCar*); / / create empty stack int InitQueue (LinkQueueCar*); / / create empty queue int Arrival (SeqStackCar*, LinkQueueCar*) / / the vehicle arrives at void Leave (SeqStackCar*, SeqStackCar*, LinkQueueCar*); / / the vehicle leaves void PRINT (CarNode*, int); / / outputs the list of information about leaving the vehicle void List (SeqStackCar, LinkQueueCar); / / A pair of functions are declared in advance int main () {SeqStackCar Enter, Temp; LinkQueueCar Wait; int ch; InitStack (& Enter); / / initialize the station InitStack (& Temp) / initialize the temporary stack InitQueue (& Wait) that gives way; / / initialize the channel while (1) {cout top] = pscape return (1);} else// depot is full, and the access road {cout next = NULL;W- > rear- > next = tress W-> rear = tress return (1);}} void Leave (SeqStackCar* Enter, SeqStackCar* Temp, LinkQueueCar* W) {/ / the vehicle leaves int room;CarNode* pscape QueueNodeQ / / determine whether there is a car if (Enter- > top > 0) / / have a car {while (1) {/ / enter the information of leaving the vehicle cout room;if (room > = 1 & & room top) break;} while (Enter- > top > room) {/ / the vehicle leaves Temp- > top++;// temporary path stack pointer Temp- > stack [temp-> top] = Enter- > stack [enter-> top]; Enter- > stack [enter-> top] = NULL;Enter- > top- } p = Enter- > Stack [enter-> top]; Enter- > Stack [enter-> top] = NULL;Enter- > top-;while (Temp- > top > = 1) {/ / determine whether there is a car on the temporary channel Enter- > top++;Enter- > Stack [enter-> top] = Temp- > stack [temp-> top]; Temp- > stack [top] = NULL;Temp- > top-;} PRINT (p, room); if ((W-> head! = W-> rear) & Enter- > top
< MAXSIZE) {//车站是未满//便道的车辆进入车场q = W->Head- > next;p = Q-> data;//p points to chain header Enter- > top++;cout 23) {cout > p-> reach.min;if (p-> reach.min)
< 0 || p->Reach.min > 59) {cout Stack [enter-> top] = pscape W-> head- > next = Q-> next;if (Q = = W-> rear) W-> rear = W-> head;free (Q); / / release Q address} else cout 23) {cout leave.hour;} cin > > p-> leave.min;if (p-> leave.min)
< 0 || p->Leave.min > 59) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.