#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\ntypedef struct {\n char type[20];\n char licensePlate[20];\n char parkingLocation[20];\n int parkingTime;\n float parkingFee;\n} Vehicle;\n\ntypedef struct {\n float carFee;\n float motorcycleFee;\n float bicycleFee;\n} Fee;\n\nvoid addVehicle(Vehicle *vehicles, int *count);\nvoid modifyVehicle(Vehicle *vehicles, int count);\nvoid deleteVehicle(Vehicle *vehicles, int *count);\nvoid customizeFee(Fee *fee);\nvoid queryVehicle(Vehicle *vehicles, int count);\nvoid payFee(Vehicle *vehicles, int count, Fee fee);\nvoid saveToFile(Vehicle *vehicles, int count);\nvoid readFromFile(Vehicle *vehicles, int *count);\n\nint main() {\n Vehicle vehicles = (Vehicle)malloc(100 * sizeof(Vehicle));\n int count = 0;\n Fee fee;\n readFromFile(vehicles, &count);\n\n int choice;\n do {\n printf("Welcome to the Parking Lot Management System\n");\n printf("1. Add Vehicle\n");\n printf("2. Modify Vehicle\n");\n printf("3. Delete Vehicle\n");\n printf("4. Customize Fee\n");\n printf("5. Query Vehicle\n");\n printf("6. Pay Fee\n");\n printf("0. Exit\n");\n printf("Please enter your choice: ");\n scanf("%d", &choice);\n\n switch (choice) \n\t\t{\n case 1:\n addVehicle(vehicles, &count);\n saveToFile(vehicles, count);\n\n break;\n case 2:\n modifyVehicle(vehicles, count);\n saveToFile(vehicles, count);\n\n break;\n case 3:\n deleteVehicle(vehicles, &count);\n saveToFile(vehicles, count);\n\n break;\n case 4:\n customizeFee(&fee);\n saveToFile(vehicles, count);\n\n break;\n case 5:\n queryVehicle(vehicles, count);\n saveToFile(vehicles, count);\n\n break;\n case 6:\n payFee(vehicles, count, fee);\n saveToFile(vehicles, count);\n\n break;\n case 0:\n printf("Thank you for using the Parking Lot Management System!\n");\n break;\n default:\n printf("Invalid choice, please try again.\n");\n }\n\n printf("\n");\n } while (choice != 0);\n\n free(vehicles);\n\n return 0;\n}\n\nvoid addVehicle(Vehicle *vehicles, int *count) {\n\n printf("Add Vehicle\n");\n\n printf("Enter vehicle type (Car/Motorcycle/Bicycle): ");\n scanf("%s", vehicles[*count].type);\n\n printf("Enter license plate: ");\n scanf("%s", vehicles[*count].licensePlate);\n\n printf("Enter parking location: ");\n scanf("%s", vehicles[*count].parkingLocation);\n\n printf("Enter parking time (in minutes): ");\n scanf("%d", &vehicles[*count].parkingTime);\n\n if (strcmp(vehicles[*count].type, "Car") == 0) {\n vehicles[*count].parkingFee = vehicles[*count].parkingTime * fee.carFee;\n } else if (strcmp(vehicles[*count].type, "Motorcycle") == 0) {\n vehicles[*count].parkingFee = vehicles[*count].parkingTime * fee.motorcycleFee;\n } else if (strcmp(vehicles[*count].type, "Bicycle") == 0) {\n vehicles[*count].parkingFee = vehicles[*count].parkingTime * fee.bicycleFee;\n }\n\n (*count)++;\n}\n\nvoid modifyVehicle(Vehicle *vehicles, int count) {\n printf("Modify Vehicle\n");\n\n char licensePlate[20];\n printf("Enter license plate of the vehicle to modify: ");\n scanf("%s", licensePlate);\n\n int found = 0;\n for (int i = 0; i < count; i++) {\n if (strcmp(vehicles[i].licensePlate, licensePlate) == 0) {\n printf("Enter new parking location: ");\n scanf("%s", vehicles[i].parkingLocation);\n\n printf("Enter new parking time (in minutes): ");\n scanf("%d", &vehicles[i].parkingTime);\n\n if (strcmp(vehicles[i].type, "Car") == 0)\n\t\t\t{\n vehicles[i].parkingFee = vehicles[i].parkingTime * fee.carFee;\n } \n\t\t\telse if (strcmp(vehicles[i].type, "Motorcycle") == 0) \n\t\t\t{\n vehicles[i].parkingFee = vehicles[i].parkingTime * fee.motorcycleFee;\n }\n\t\t\telse if (strcmp(vehicles[i].type, "Bicycle") == 0) \n\t\t\t{\n vehicles[i].parkingFee = vehicles[i].parkingTime * fee.bicycleFee;\n }\n\n printf("Vehicle information modified successfully.\n");\n found = 1;\n break;\n }\n }\n\n if (!found) {\n printf("Vehicle not found.\n");\n }\n}\n\nvoid deleteVehicle(Vehicle *vehicles, int *count) {\n printf("Delete Vehicle\n");\n\n char licensePlate[20];\n printf("Enter license plate of the vehicle to delete: ");\n scanf("%s", licensePlate);\n\n int found = 0;\n for (int i = 0; i < *count; i++) {\n if (strcmp(vehicles[i].licensePlate, licensePlate) == 0) {\n for (int j = i; j < *count - 1; j++) {\n vehicles[j] = vehicles[j + 1];\n }\n (*count)--;\n printf("Vehicle deleted successfully.\n");\n found = 1;\n break;\n }\n }\n\n if (!found) {\n printf("Vehicle not found.\n");\n }\n}\n\nvoid customizeFee(Fee *fee) {\n printf("Customize Fee\n");\n\n printf("Enter car fee per minute: ");\n scanf("%f", &fee->carFee);\n\n printf("Enter motorcycle fee per minute: ");\n scanf("%f", &fee->motorcycleFee);\n\n printf("Enter bicycle fee per minute: ");\n scanf("%f", &fee->bicycleFee);\n\n printf("Fee customized successfully.\n");\n}\n\nvoid queryVehicle(Vehicle *vehicles, int count) {\n printf("Query Vehicle\n");\n\n char licensePlate[20];\n printf("Enter license plate of the vehicle to query: ");\n scanf("%s", licensePlate);\n\n int found = 0;\n for (int i = 0; i < count; i++) {\n if (strcmp(vehicles[i].licensePlate, licensePlate) == 0) {\n printf("Vehicle Type: %s\n", vehicles[i].type);\n printf("License Plate: %s\n", vehicles[i].licensePlate);\n printf("Parking Location: %s\n", vehicles[i].parkingLocation);\n printf("Parking Time: %d minutes\n", vehicles[i].parkingTime);\n printf("Parking Fee: %.2f\n", vehicles[i].parkingFee);\n found = 1;\n break;\n }\n }\n\n if (!found) {\n printf("Vehicle not found.\n");\n }\n}\n\nvoid payFee(Vehicle *vehicles, int count, Fee fee) {\n printf("Pay Fee\n");\n\n char licensePlate[20];\n printf("Enter license plate of the vehicle to pay fee: ");\n scanf("%s", licensePlate);\n\n int found = 0;\n for (int i = 0; i < count; i++) {\n if (strcmp(vehicles[i].licensePlate, licensePlate) == 0) {\n float feeToPay = vehicles[i].parkingFee;\n printf("Fee to Pay: %.2f\n", feeToPay);\n\n int paymentMethod;\n printf("Select payment method:\n");\n printf("1. Cash\n");\n printf("2. Credit Card\n");\n printf("Please enter your choice: ");\n scanf("%d", &paymentMethod);\n\n if (paymentMethod == 1) {\n printf("Payment successful. Thank you!\n");\n found = 1;\n break;\n } else if (paymentMethod == 2) {\n float creditCardNumber;\n printf("Enter credit card number: ");\n scanf("%f", &creditCardNumber);\n\n printf("Payment successful. Thank you!\n");\n found = 1;\n break;\n } else {\n printf("Invalid payment method.\n");\n }\n }\n }\n\n if (!found) {\n printf("Vehicle not found.\n");\n }\n}\n\nvoid saveToFile(Vehicle *vehicles, int count) {\n FILE *file = fopen("C:\Users\额额\Desktop\cvb\456", "w");\n if (file == NULL) {\n printf("Failed to open file.\n");\n return;\n }\n\n for (int i = 0; i < count; i++) {\n fprintf(file, "%s %s %s %d %.2f\n", vehicles[i].type, vehicles[i].licensePlate,\n vehicles[i].parkingLocation, vehicles[i].parkingTime, vehicles[i].parkingFee);\n }\n\n fclose(file);\n printf("Data saved to file successfully.\n");\n}\n\nvoid readFromFile(Vehicle *vehicles, int *count) {\n FILE *file = fopen("C:\Users\额额\Desktop\cvb\456", "r");\n if (file == NULL) {\n printf("Failed to open file.\n");\n return;\n }\n\n *count = 0;\n while (fscanf(file, "%s %s %s %d %f", vehicles[*count].type, vehicles[*count].licensePlate,\n vehicles[*count].parkingLocation, &vehicles[*count].parkingTime, &vehicles[*count].parkingFee) != EOF) {\n (*count)++;\n }\n\n fclose(file);\n printf("Data read from file successfully.\n");\n

Parking Lot Management System - Add, Modify, Delete, Query and Pay Fees for Vehicles

原文地址: https://www.cveoy.top/t/topic/pySU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录