数据结构停车场管理系统课程设计源代码
时间: 2023-06-30 16:15:38 浏览: 128
由于数据结构停车场管理系统比较复杂,所以无法在这里完整地展示源代码。以下是一个简单的停车场管理系统示例代码,供参考:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 车辆信息结构体
struct Car {
string license; // 车牌号
int type; // 车型
int enter_time; // 进入时间
int exit_time; // 离开时间
int cost; // 停车费用
};
// 车位信息结构体
struct ParkingSpot {
int id; // 车位号
bool used; // 是否被占用
};
// 停车场类
class ParkingLot {
public:
ParkingLot(int capacity) {
// 初始化车位
for (int i = 0; i < capacity; i++) {
ParkingSpot spot = {i + 1, false};
spots.push_back(spot);
}
}
// 车辆进入停车场
bool enter(Car car) {
// 找到一个空闲车位
for (int i = 0; i < spots.size(); i++) {
if (!spots[i].used) {
spots[i].used = true;
car.enter_time = get_time();
cars.push_back(car);
cout << "车辆 " << car.license << " 进入了停车场,停在了车位 " << spots[i].id << endl;
return true;
}
}
return false;
}
// 车辆离开停车场
bool exit(string license) {
// 找到对应车牌号的车辆
for (int i = 0; i < cars.size(); i++) {
if (cars[i].license == license) {
cars[i].exit_time = get_time();
cars[i].cost = calc_cost(cars[i]);
spots[i].used = false;
cout << "车辆 " << license << " 离开了停车场,共停车 " << (cars[i].exit_time - cars[i].enter_time) / 60 << " 分钟,停车费用为 " << cars[i].cost << " 元" << endl;
return true;
}
}
return false;
}
private:
int get_time() { return time(0); }
int calc_cost(Car car) {
// 计算停车费用
int time_diff = car.exit_time - car.enter_time;
int cost = 0;
if (car.type == 1) {
cost = time_diff / 60 * 5;
} else if (car.type == 2) {
cost = time_diff / 60 * 10;
} else if (car.type == 3) {
cost = time_diff / 60 * 15;
}
return cost;
}
vector<Car> cars; // 车辆列表
vector<ParkingSpot> spots; // 车位列表
};
int main() {
ParkingLot lot(100);
Car car1 = {"京A12345", 1};
lot.enter(car1);
Car car2 = {"京B12345", 2};
lot.enter(car2);
Car car3 = {"京C12345", 3};
lot.enter(car3);
lot.exit(car1.license);
lot.exit(car2.license);
lot.exit(car3.license);
return 0;
}
```
这个示例代码实现了一个简单的停车场管理系统,包括车辆的进出管理、车位的管理、计费管理等功能。在程序中,使用了结构体来存储车辆信息和车位信息,使用了 vector 容器来存储车辆列表和车位列表。同时,程序也实现了计算停车费用的功能,根据车型和停留时间计算停车费用。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)