- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章C语言源码实现停车场管理系统由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了C语言停车场管理系统的具体代码,供大家参考,具体内容如下 。
题目要求:
刚开始在Codeblocks下用C语言写的,但是用指针传递参数的时候总是出问题。后来就用C++,但是调用了C的输入输出和文件操作的头文件,所以代码都是C的 。
main.cpp 。
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
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <ctime>
#include <cstring>
#include <conio.h>
#define N 100
using
namespace
std;
typedef
struct
{
char
num[8];
//车牌号
long
int
time_in;
int
pos;
//车辆的状态,0表示停在便道中,1表示停在停车场
} vehicle;
//定义车辆类型
typedef
struct
{
vehicle veh[N];
int
top;
} SqStack;
//用栈表示停车场
typedef
struct
LNode
{
vehicle veh;
struct
LNode *next;
} LinkList;
//用单链表表示便道
void
Load(
FILE
*,SqStack *,LinkList *);
void
ShowMenu(
int
);
int
MakeChoice(
int
,
int
);
void
Parking(SqStack *,LinkList *);
void
Back(SqStack *);
void
EnterPkl(SqStack *,LinkList *);
void
LeavePath(LinkList *);
void
View(SqStack *,LinkList *);
void
Write_and_Quit(
FILE
*,SqStack *,LinkList *);
int
main()
{
SqStack *pkl;
LinkList *path;
FILE
*fp;
pkl=(SqStack *)
malloc
(
sizeof
(SqStack));
path=(LinkList *)
malloc
(
sizeof
(LinkList));
fp=
fopen
(
"Parking_lot.txt"
,
"r+"
);
if
(fp==NULL)
{
printf
(
"数据加载失败!按任意键退出程序"
);
getch();
return
0;
}
Load(fp,pkl,path);
while
(1)
{
system
(
"cls"
);
ShowMenu(pkl->top);
switch
(MakeChoice(1,6))
{
case
1:
system
(
"cls"
);
Parking(pkl,path);
break
;
case
2:
system
(
"cls"
);
Back(pkl);
break
;
case
3:
system
(
"cls"
);
EnterPkl(pkl,path);
break
;
case
4:
system
(
"cls"
);
LeavePath(path);
break
;
case
5:
system
(
"cls"
);
View(pkl,path);
break
;
default
:
system
(
"cls"
);
Write_and_Quit(fp,pkl,path);
return
0;
}
}
return
0;
}
|
function.cpp 。
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
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <ctime>
#include <cstring>
#include <conio.h>
#define N 100
using
namespace
std;
typedef
struct
{
char
num[8];
//车牌号
long
int
time_in;
int
pos;
//车辆的状态,0表示停在便道中,1表示停在停车场
} vehicle;
//定义车辆类型
typedef
struct
{
vehicle veh[N];
int
top;
} SqStack;
//用栈表示停车场
typedef
struct
LNode
{
vehicle veh;
struct
LNode *next;
} LinkList;
//用单链表表示便道
void
Load(
FILE
* fp,SqStack * pkl,LinkList * path)
{
pkl->top=-1;
path->next=NULL;
LinkList *p;
char
num[8];
long
int
time_in;
int
pos;
while
(
fscanf
(fp,
"%s %ld %d\n"
,num,&time_in,&pos)!=EOF)
{
if
(pos==0)
//该车辆在便道中
{
//尾插法建立单链表
p=(LinkList *)
malloc
(
sizeof
(LinkList));
strcpy
(p->veh.num,num);
p->veh.time_in=time_in;
p->veh.pos=pos;
path->next=p;
path=p;
}
else
//该车辆在停车场中
{
++pkl->top;
strcpy
(pkl->veh[pkl->top].num,num);
pkl->veh[pkl->top].time_in=time_in;
pkl->veh[pkl->top].pos=pos;
}
}
path->next=NULL;
}
void
ShowMenu(
int
n)
{
printf
(
"********一个简单的停车场管理系统********\n"
);
if
(n+1==N)
printf
(
"***************停车场已满***************\n"
);
else
printf
(
"**********当前停车场共有%03d辆车**********\n"
,n+1);
printf
(
"********说明:停车场每小时收费5元********\n"
);
printf
(
"****************1.停车******************\n"
);
printf
(
"****************2.取车******************\n"
);
printf
(
"*********3.便道车辆进入停车场***********\n"
);
printf
(
"**************4.离开便道****************\n"
);
printf
(
"**************5.查看车辆****************\n"
);
printf
(
"****************6.退出******************\n"
);
}
int
MakeChoice(
int
m,
int
n)
{
int
judge;
printf
(
"请输入%d~%d\n"
,m,n);
scanf
(
"%d"
,&judge);
while
(judge<m||judge>n)
//确保输入的是1~n
{
printf
(
"输入不合法,请输入%d~%d\n"
,m,n);
fflush
(stdin);
//如果不加这句,输入一些字母会导致函数无限循环
scanf
(
"%d"
,&judge);
}
return
judge;
}
void
Parking(SqStack *pkl,LinkList *path)
{
LinkList *r;
printf
(
"请输入车牌号:"
);
if
(pkl->top<N-1)
{
fflush
(stdin);
scanf
(
"%8s"
,pkl->veh[++pkl->top].num);
time
(&(pkl->veh[pkl->top].time_in));
pkl->veh[pkl->top].pos=1;
printf
(
"您的车辆已停至%2d号车位\n"
,pkl->top);
}
else
{
fflush
(stdin);
r=(LinkList *)
malloc
(
sizeof
(LinkList));
scanf
(
"%8s"
,r->veh.num);
printf
(
"停车场已满,您要暂时停放在便道中吗?\n"
);
printf
(
"1.确定 2.取消\n"
);
if
(MakeChoice(1,2)==1)
{
while
(path->next!=NULL)
path=path->next;
r->veh.time_in=0;
r->veh.pos=0;
path->next=r;
r->next=NULL;
printf
(
"您的车辆已停放到便道中\n"
);
}
else
free
(r);
}
printf
(
"按任意键返回主菜单"
);
getch();
return
;
}
void
Back(SqStack *pkl)
{
int
n,i=0;
long
int
time_out;
double
hours;
vehicle t_pkl[N];
printf
(
"请输入您的车辆所在的车位(目前还有个小问题,前面的车走了之后当前车位会-1):"
);
n=MakeChoice(0,pkl->top);
printf
(
"%2d上的车辆车牌号为%s,您确定要取走该车辆吗?\n"
,n,pkl->veh[n].num);
printf
(
"1.确定 2.取消\n"
);
if
(MakeChoice(1,2)==1)
{
time
(&time_out);
hours=(time_out-pkl->veh[n].time_in)/3600.0;
printf
(
"本次停车共计%lf小时,收费%lf元,请按任意键确认支付\n"
,hours,hours*5);
getch();
for
(i=0; pkl->top>=n; --pkl->top,++i)
//把第n辆到第pkl->top辆车移到t_pkl
t_pkl[i]=pkl->veh[pkl->top];
//此时pkl->top指向第n-1辆车
for
(i-=2; i>=0; --i)
//把第n+1辆到第pkl->top辆车移回pkl
pkl->veh[++pkl->top]=t_pkl[i];
printf
(
"支付成功!\n"
);
printf
(
"取车成功,按任意键返回主菜单"
);
getch();
return
;
}
else
{
printf
(
"按任意键返回主菜单"
);
getch();
return
;
}
}
void
EnterPkl(SqStack *pkl,LinkList *path)
{
if
(pkl->top==N-1)
printf
(
"停车场已满!"
);
else
{
printf
(
"您确定将便道中第一辆车(车牌号:%8s)停入停车场吗?\n"
,path->next->veh.num);
printf
(
"1.确定 2.取消\n"
);
if
(MakeChoice(1,2)==1)
{
pkl->veh[++pkl->top]=path->next->veh;
time
(&pkl->veh[pkl->top].time_in);
path->next=path->next->next;
printf
(
"已停入停车场\n"
);
}
}
printf
(
"按任意键返回主菜单"
);
getch();
return
;
}
void
LeavePath(LinkList *path)
{
int
i=0,n;
LinkList *q;
printf
(
"请输入要离开便道的车辆的位序:"
);
scanf
(
"%d"
,&n);
while
(i<n&&path!=NULL)
{
++i;
q=path;
//保存当前节点的前一个节点,如果找到的位置在链表最后,需要将前一个节点的指针域置为NULL
path=path->next;
}
if
(path!=NULL)
{
printf
(
"您确定便道中第%03d辆车(车牌号:%8s)离开便道吗?\n"
,n,path->veh.num);
printf
(
"1.确定 2.取消\n"
);
if
(MakeChoice(1,2)==1)
{
if
(path->next!=NULL)
//确定离开并且不是便道中最后一辆车
{
q=path->next;
path->next=q->next;
free
(q);
printf
(
"第%03d辆车已离开便道\n"
,n);
}
else
//确定离开并且是便道中最后一辆车
{
printf
(
"第%03d辆车已离开便道\n"
,n);
q->next=NULL;
free
(path);
}
}
}
else
printf
(
"没有找到第%03d辆车\n"
,n);
printf
(
"按任意键返回主菜单"
);
getch();
return
;
}
void
View(SqStack *pkl,LinkList *path)
{
int
i;
long
int
time_out;
double
hours;
time
(&time_out);
printf
(
"停车场共有%03d辆车:\n"
,pkl->top+1);
for
(i=0; i<=pkl->top; ++i)
{
hours=(time_out-pkl->veh[i].time_in)/3600.0;
printf
(
"车位:%2d 车牌号:%8s 停车时长:%lf 应缴费用:%lf\n"
,i,pkl->veh[i].num,hours,hours*5);
}
printf
(
"便道车辆:\n"
);
if
(path->next==NULL)
printf
(
"无\n"
);
while
(path->next!=NULL)
{
path=path->next;
printf
(
"车牌号:%s\n"
,path->veh.num);
}
printf
(
"按任意键返回主菜单"
);
getch();
return
;
}
void
Write_and_Quit(
FILE
*fp,SqStack *pkl,LinkList *path)
{
rewind
(fp);
LinkList *pre=path,*p=path->next;
for
(; pkl->top>-1; --pkl->top)
fprintf
(fp,
"%s %ld %d\n"
,pkl->veh[pkl->top].num,pkl->veh[pkl->top].time_in,pkl->veh[pkl->top].pos);
while
(p!=NULL)
{
free
(pre);
fprintf
(fp,
"%s %ld %d\n"
,p->veh.num,p->veh.time_in,p->veh.pos);
pre=p;
p=pre->next;
}
free
(pre);
free
(pkl);
fclose
(fp);
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/qq920444182/article/details/73694889 。
最后此篇关于C语言源码实现停车场管理系统的文章就讲到这里了,如果你想了解更多关于C语言源码实现停车场管理系统的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
至少在某些 ML 系列语言中,您可以定义可以执行模式匹配的记录,例如http://learnyouahaskell.com/making-our-own-types-and-typeclasses -
这可能是其他人已经看到的一个问题,但我正在尝试寻找一种专为(或支持)并发编程而设计的语言,该语言可以在 .net 平台上运行。 我一直在 erlang 中进行辅助开发,以了解该语言,并且喜欢建立一个稳
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
我正在寻找一种进程间通信工具,可以在相同或不同系统上运行的语言和/或环境之间使用。例如,它应该允许在 Java、C# 和/或 C++ 组件之间发送信号,并且还应该支持某种排队机制。唯一明显与环境和语言
我有一些以不同语言返回的文本。现在,客户端返回的文本格式为(en-us,又名美国英语): Stuff here to keep. -- Delete Here -- all of this below
问题:我希望在 R 中找到类似 findInterval 的函数,它为输入提供一个标量和一个表示区间起点的向量,并返回标量落入的区间的索引。例如在 R 中: findInterval(x = 2.6,
我是安卓新手。我正在尝试进行简单的登录 Activity ,但当我单击“登录”按钮时出现运行时错误。我认为我没有正确获取数据。我已经检查过,SQLite 中有一个与该 PK 相对应的数据。 日志猫。
大家好,感谢您帮助我。 我用 C# 制作了这个计算器,但遇到了一个问题。 当我添加像 5+5+5 这样的东西时,它给了我正确的结果,但是当我想减去两个以上的数字并且还想除或乘以两个以上的数字时,我没有
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 4 年前。 Improve th
这就是我所拥有的 #include #include void print(int a[], int size); void sort (int a[], int size); v
你好,我正在寻找我哪里做错了? #include #include int main(int argc, char *argv[]) { int account_on_the_ban
嘿,当我开始向数组输入数据时,我的代码崩溃了。该程序应该将数字读入数组,然后将新数字插入数组中,最后按升序排列所有内容。我不确定它出了什么问题。有人有建议吗? 这是我的代码 #include #in
我已经盯着这个问题好几个星期了,但我一无所获!它不起作用,我知道那么多,但我不知道为什么或出了什么问题。我确实知道开发人员针对我突出显示的行吐出了“错误:预期表达式”,但这实际上只是冰山一角。如果有人
我正在编写一个点对点聊天程序。在此程序中,客户端和服务器功能写入一个唯一的文件中。首先我想问一下我程序中的机制是否正确? I fork() two processes, one for client
基本上我需要找到一种方法来发现段落是否以句点 (.) 结束。 此时我已经可以计算给定文本的段落数,但我没有想出任何东西来检查它是否在句点内结束。 任何帮助都会帮助我,谢谢 char ch; FI
我的函数 save_words 接收 Armazena 和大小。 Armazena 是一个包含段落的动态数组,size 是数组的大小。在这个函数中,我想将单词放入其他称为单词的动态数组中。当我运行它时
我有一个结构 struct Human { char *name; struct location *location; int
我正在尝试缩进以下代码的字符串输出,但由于某种原因,我的变量不断从文件中提取,并且具有不同长度的噪声或空间(我不确定)。 这是我的代码: #include #include int main (v
我想让用户选择一个选项。所以我声明了一个名为 Choice 的变量,我希望它输入一个只能是 'M' 的 char 、'C'、'O' 或 'P'。 这是我的代码: char Choice; printf
我正在寻找一种解决方案,将定义和变量的值连接到数组中。我已经尝试过像这样使用 memcpy 但它不起作用: #define ADDRESS {0x00, 0x00, 0x00, 0x00, 0x0
我是一名优秀的程序员,十分优秀!