-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar Parking.cpp
107 lines (94 loc) · 2.06 KB
/
Car Parking.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
#include <iostream>
#include <conio.h>
using namespace std;
int pre;
void parking_exit(int parking_lot[3][5]);
void moving(int stair, int pos );
void floor(int x, int parking_lot[3][5]);
void takeInput(int parking_lot[][5]);
void Print(int parking_lot[][5]);
main()
{
int parking_lot[3][5] = {{2, 0, 0, 1, 0},
{1, 0, 0, 0, 0},
{0, 0, 0, 0, 0}};
takeInput( parking_lot);
Print(parking_lot);
parking_exit(parking_lot);
}
void takeInput(int parking_lot[][5])
{
int a = 2;
for(int x = 0; x < 3; x++)
{
if ( x != 2)
{
cout << " For Floor " << a << endl;
}
else{
cout << " For ground floor "<<endl;
}
for ( int y = 0; y < 5; y++)
{
cout << " Enter the " << y + 1 << " place value : ";
cin >> parking_lot[x][y];
cout << endl;
}
a--;
}
}
void Print(int parking_lot[][5])
{
for ( int x = 0; x< 3; x ++)
{
for ( int y = 0; y < 5; y++)
{
cout << "\t" << parking_lot[x][y];
}
cout << endl;
}
}
void parking_exit(int parking_lot[3][5])
{
int pos;
floor(0, parking_lot);
floor(1, parking_lot);
if (pre != 4)
{
cout << " Move Right : " << 4 - pre;
}
}
void floor(int x, int parking_lot[3][5])
{
int stair;
int position;
if (x == 1)
{
position = pre;
}
for (int i = 0; i < 5; i++)
{
if (parking_lot[x][i] == 1)
{
stair = i;
pre = i;
}
if (parking_lot[x][i] == 2)
{
position = i;
}
}
moving(stair, position);
}
void moving(int stair, int pos)
{
if (pos > stair)
{
cout << " Move Left : " << pos - stair << endl;
}
else if (pos < stair)
{
cout << " Move Right : " << stair - pos << endl;
}
cout << " Move Down : 1" << endl;
}