Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize a simple parking lot Management system with C language

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 use C language to achieve a simple parking lot management system", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use C language to achieve a simple parking lot management system.

1. Problem description

1) there is a two-story parking lot with 6 parking spaces on each floor. The second floor is allowed only when the parking space on the first floor is full (the parking lot can be implemented with a two-dimensional array). The information of each car includes license plate number, floor number, parking number and parking time, among which the parking time is calculated according to minutes.

2) assume that the initial state of the parking lot is empty on the first floor, and there are already four cars on the second floor, the parking number is No. 1-4 on the second floor, and the parking time is 2015, 1510, 5, respectively.

3) parking operation: when a car enters the parking lot, enter its license plate number first, and then assign it a floor number and a parking space number (check the usage of the parking space before allocation, if there is a space on the first floor, it must be parked on the first floor), the parking time is set to 5, and the parking time before that is increased by 5. (this problem simplifies the processing of time: add 5 minutes to other cars only when one car enters)

4) charge management (pick up): when a car leaves, enter its license plate number, first calculate the fee according to its parking time, 0.2 yuan per 5 minutes, and set the corresponding parking space of the car to be available.

5) output the information of all vehicles in the parking lot

6) exit the system

Knowledge involved

The use of structures, using arrays as function parameters, and so on.

two。 Code # include "stdio.h" # includestruct car {char car_num [10]; int floor; int position_num; int time } CAR [12] = {{"0", 1pyrrine 1, 0}, {"0", 1pyr2, 0}, {"0", 1pyrr0}, {"0", 1pyr0}, {"0", 1pyr0}, {"Ji F12345", 2pm 2pm 20}, {"Ji F17845", 2jue 2jing 15}, {"Ji F12856", 2jing 3jing 10}, {"Ji F12445", 2je 3jing 10}, {"Ji F12445", 2pm 5p}, {"0", 2pm 5pm 0}) {"0", 2, 6, 0}} Void park (struct car CAR []) {int I, jjinger k; int flag = 0; char carn [10]; printf ("\ nPlease enter the license plate number\ n"); scanf ("% s", carn); for (k = 0; k

< 12; k++) { if (strcmp(CAR[k].car_num, carn) == 0) { printf("该车已在停车场内\n"); flag = 2; break; } } for (i = 0; i < 12; i++) { if (strcmp(CAR[i].car_num,"0") == 0&&flag==0) { strcpy(CAR[i].car_num, carn); for (j = 0; j < 12; j++) { if (strcmp(CAR[j].car_num, "0") != 0) { CAR[j].time += 5; } } printf("该车可停在了%d层%d号\n", CAR[i].floor, CAR[i].position_num); flag = 1; break; } } if (flag == 0) { printf("\n停车场已满\n"); }}void leave(struct car CAR[]){ int i, j; int flag = 0; char carn[10]; float price; scanf("%s",carn); for (i = 0; i < 12; i++) { if (strcmp(CAR[i].car_num,carn)==0) { strcpy(CAR[i].car_num,"0"); price = CAR[i].time*0.04; CAR[i].time = 0; flag = 1; printf("\n停车费%f\n", price); } } if (flag == 0) { printf("\n停车场内无此车\n"); } }void information(struct car CAR[]){ printf("车牌号 \t层号\t位号\t时间\n"); for (int i = 0; i < 12; i++) { printf("%-10s\t%d\t%d\t%d\n", CAR[i].car_num, CAR[i].floor, CAR[i].position_num, CAR[i].time); }}int main(){ int n; int m = -1; while (m != 0) { printf("\n*************************\n"); printf("1.停车\n"); printf("2.离开\n"); printf("3.输出停车场信息\n"); printf("0.退出\n"); printf("*************************\n"); printf("请输入功能号0-3:"); scanf("%d", &m); while (m < 0 || m>

3) {printf ("\ ninput error! Please enter the correct function number 0-3: "); scanf ("% d ", & m);} if (m = = 1) park (CAR); else if (m = = 2) leave (CAR); else if (m = = 3) information (CAR);} return 0;} 3. Partial screenshot of the running result

At this point, I believe you have a deeper understanding of "how to use C language to achieve a simple parking lot management system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report