#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 车辆信息结构体
struct Vehicle {
string licensePlate;
string color;
string brand;
string enterTime;
string exitTime;
double payment;
};
// 车主信息结构体
struct Owner {
string name;
int age;
vector<Vehicle> vehicles;
bool hasPaid;
};
// 全局变量
vector<Owner> owners;
int totalParkingSpaces = 100;
int remainingParkingSpaces = totalParkingSpaces;
// 函数声明
void addOwner();
void removeOwner();
void addVehicle();
void removeVehicle();
void enterParkingLot();
void exitParkingLot();
void displayParkingLotStatus();
void registerPayment();
int main() {
int choice;
while (true) {
cout << "停车场管理系统" << endl;
cout << "1. 添加车主" << endl;
cout << "2. 删除车主" << endl;
cout << "3. 添加车辆" << endl;
cout << "4. 删除车辆" << endl;
cout << "5. 车辆进入停车场" << endl;
cout << "6. 车辆离开停车场" << endl;
cout << "7. 显示停车场状态" << endl;
cout << "8. 登记缴费" << endl;
cout << "0. 退出" << endl;
cout << "请选择操作:";
cin >> choice;
switch (choice) {
case 1:
addOwner();
break;
case 2:
removeOwner();
break;
case 3:
addVehicle();
break;
case 4:
removeVehicle();
break;
case 5:
enterParkingLot();
break;
case 6:
exitParkingLot();
break;
case 7:
displayParkingLotStatus();
break;
case 8:
registerPayment();
break;
case 0:
return 0;
default:
cout << "无效的选择!" << endl;
}
cout << endl;
}
return 0;
}
// 添加车主
void addOwner() {
Owner owner;
cout << "请输入车主姓名:";
cin >> owner.name;
cout << "请输入车主年龄:";
cin >> owner.age;
cout << "是否已缴费(1-是,0-否):";
cin >> owner.hasPaid;
owners.push_back(owner);
cout << "车主添加成功!" << endl;
}
// 删除车主
void removeOwner() {
string name;
cout << "请输入要删除的车主姓名:";
cin >> name;
for (int i = 0; i < owners.size(); i++) {
if (owners[ i].name == name) {
owners.erase(owners.begin() + i);
cout << "车主删除成功!" << endl;
return;
}
}
cout << "未找到该车主!" << endl;
}
// 添加车辆
void addVehicle() {
string name;
cout << "请输入车主姓名:";
cin >> name;
for (int i = 0; i < owners.size(); i++) {
if (owners[ i].name == name) {
Vehicle vehicle;
cout << "请输入车牌号:";
cin >> vehicle.licensePlate;
cout << "请输入车辆颜色:";
cin >> vehicle.color;
cout << "请输入车辆品牌:";
cin >> vehicle.brand;
owners[ i].vehicles.push_back(vehicle);
cout << "车辆添加成功!" << endl;
return;
}
}
cout << "未找到该车主!" << endl;
}
// 删除车辆
void removeVehicle() {
string name;
cout << "请输入车主姓名:";
cin >> name;
for (int i = 0; i < owners.size(); i++) {
if (owners[ i].name == name) {
string licensePlate;
cout << "请输入要删除的车牌号:";
cin >> licensePlate;
for (int j = 0; j < owners[ i].vehicles.size(); j++) {
if (owners[ i].vehicles[j].licensePlate == licensePlate) {
owners[ i].vehicles.erase(owners[ i].vehicles.begin() + j);
cout << "车辆删除成功!" << endl;
return;
}
}
cout << "未找到该车辆!" << endl;
return;
}
}
cout << "未找到该车主!" << endl;
}
// 车辆进入停车场
void enterParkingLot() {
string licensePlate;
cout << "请输入车牌号:";
cin >> licensePlate;
for (int i = 0; i < owners.size(); i++) {
for (int j = 0; j < owners[ i].vehicles.size(); j++) {
if (owners[ i].vehicles[j].licensePlate == licensePlate) {
if (remainingParkingSpaces > 0) {
owners[ i].vehicles[j].enterTime = "当前时间";
remainingParkingSpaces--;
cout << "车辆进入停车场成功!" << endl;
} else {
cout << "停车场已满,无法进入!" << endl;
}
return;
}
}
}
cout << "未找到该车辆!" << endl;
}
// 车辆离开停车场
void exitParkingLot() {
string licensePlate;
cout << "请输入车牌号:";
cin >> licensePlate;
for (int i = 0; i < owners.size(); i++) {
for (int j = 0; j < owners[ i].vehicles.size(); j++) {
if (owners[ i].vehicles[j].licensePlate == licensePlate) {
owners[ i].vehicles[j].exitTime = "当前时间";
remainingParkingSpaces++;
cout << "车辆离开停车场成功!" << endl;
return;
}
}
}
cout << "未找到该车辆!" << endl;
}
// 显示停车场状态
void displayParkingLotStatus() {
cout << "总停车位数:" << totalParkingSpaces << endl;
cout << "剩余停车位数:" << remainingParkingSpaces << endl;
cout << "在停车辆及车主信息:" << endl;
for (int i = 0; i < owners.size(); i++) {
for (int j = 0; j < owners[ i].vehicles.size(); j++) {
cout << "车主姓名:" << owners[ i].name << endl;
cout << "车辆牌照:" << owners[ i].vehicles[j].licensePlate << endl;
cout << "车辆颜色:" << owners[ i].vehicles[j].color << endl;
cout << "车辆品牌:" << owners[ i].vehicles[j].brand << endl;
cout << "进入时间:" << owners[ i].vehicles[j].enterTime << endl;
cout << "离开时间:" << owners[ i].vehicles[j].exitTime << endl;
cout << "应缴费用:" << owners[ i].vehicles[j].payment << endl;
cout << endl;
}
}
}
// 登记缴费
void registerPayment() {
string licensePlate;
cout << "请输入车牌号:";
cin >> licensePlate;
for (int i = 0; i < owners.size(); i++) {
for (int j = 0; j < owners[ i].vehicles.size(); j++) {
if (owners[ i].vehicles[j].licensePlate == licensePlate) {
owners[ i].vehicles[j].payment = 10.0; // 假设每小时停车费用为10元
owners[ i].hasPaid = true;
cout << "缴费登记成功!" << endl;
return;
}
}
}
cout << "未找到该车辆!" << endl;
}