该系统具有以下功能:

– 停车:输入车牌号和进入时间,自动分配停车位编号,如果停车场已满则提示停车场已满。

– 离开停车场结算停车费用:输入停车位编号和离开时间,自动计算停车费用,如果已结算则提示已结算。

– 显示停车记录:按照停车位编号顺序显示停车记录,包括车牌号、进入时间、离开时间和停车费用。

– 退出系统:结束程序。

该程序通过使用 vector 存储停车记录,动态分配停车位编号,并通过 switch-case 语句实现菜单选择功能。

#include #include #include using namespace std;const int MAX_CAPACITY = 100;// 停车记录结构体struct ParkingRecord {int id; // 停车位编号string licensePlate;// 车牌号int timeIn; // 进入时间int timeOut;// 离开时间float cost; // 停车费用};// 停车场类class ParkingLot {public:ParkingLot();// 显示菜单void showMenu();// 停车void parkCar();// 离开停车场结算停车费用void checkOutCar();// 显示停车记录void showParkingRecords();private:vector parkingLot; // 停车场int currentCapacity;// 当前停车场容量};// 构造函数ParkingLot::ParkingLot() {currentCapacity = 0;}// 显示菜单void ParkingLot::showMenu() {cout << "Welcome to the Parking Lot Management System!" << endl;cout << "1. Park a car" << endl;cout << "2. Check out a car" << endl;cout << "3. Show parking records" << endl;cout << "4. Exit" << endl;cout <= MAX_CAPACITY) {cout << "Sorry, the parking lot is full." << endl;return;}ParkingRecord newRecord;cout <> newRecord.licensePlate;cout <> newRecord.timeIn;newRecord.id = currentCapacity + 1;parkingLot.push_back(newRecord);currentCapacity++;cout << "The car is parked at spot " << newRecord.id << "." << endl;}// 离开停车场结算停车费用void ParkingLot::checkOutCar() {int id;cout <> id;if (id  currentCapacity) {cout << "Invalid parking spot number." <timeOut > 0) {cout << "The car has already been checked out." << endl;return;}cout <> record->timeOut;float hours = (record->timeOut - record->timeIn) / 60.0;record->cost = hours * 1.5;cout << "The cost for parking is $" <cost << "." << endl;}// 显示停车记录void ParkingLot::showParkingRecords() {if (currentCapacity == 0) {cout << "There is no car parked in the parking lot." << endl;return;}cout << "Parking records:" << endl;cout << "ID\tLicense Plate\tTime In\tTime Out\tCost" << endl;for (int i = 0; i < currentCapacity; i++) {ParkingRecord record = parkingLot[i];cout << record.id << "\t" << record.licensePlate << "\t\t"<< record.timeIn << "\t" << record.timeOut << "\t"<< record.cost <> choice;switch (choice) {case 1:parkingLot.parkCar();break;case 2:parkingLot.checkOutCar();break;case 3:parkingLot.showParkingRecords();break;case 4:cout << "Thank you for using the Parking Lot Management System." << endl;break;default:cout << "Invalid choice." << endl;break;}cout << endl;} while (choice != 4);return 0;