Parking Lot Management System - Add, Modify, Delete, Query, and Pay Fees
#include<stdio.h>\n#include<stdlib.h>\n#include<string.h>\n\ntypedef\ struct\ {\n\tchar\ type[20];\n\tchar\ licensePlate[20];\n\tchar\ parkingLocation[20];\n\tint\ parkingTime;\n\tfloat\ parkingFee;\n}Vehicle;\n\ntypedef\ struct\ {\n\tfloat\ carFee;\n\tfloat\ motorcycleFee;\n\tfloat\ bicycleFee;\n}Fee;\n\nvoid\ addVehicle(Vehicle\ *vehicles,\ int\ *count,\ FILE\ *file);\nvoid\ modifyVehicle(Vehicle\ *vehicles,\ int\ count,\ FILE\ *file);\nvoid\ deleteVehicle(Vehicle\ *vehicles,\ int\ *count,\ FILE\ *file);\nvoid\ customizeFee(Fee\ *fee,\ FILE\ *file);\nvoid\ queryVehicle(Vehicle\ *vehicles,\ int\ count);\nvoid\ payFee(Vehicle\ *vehicles,\ int\ count,\ FILE\ *file);\n\nint\ main()\ {\n\tVehicle\ vehicles\ =\ (Vehicle)malloc(100\ *\ sizeof(Vehicle));\n\tint\ count\ =\ 0;\n\tFee\ fee\ =\ {5.0,\ 3.0,\ 1.0};\n\tFILE\ *file\ =\ fopen("vehicles.txt",\ "a+");\n\n\tint\ choice;\n\tdo\ {\n\t printf("Welcome\ to\ the\ Parking\ Lot\ Management\ System\n");\n\t printf("1.\ Add\ Vehicle\n");\n\t printf("2.\ Modify\ Vehicle\n");\n\t printf("3.\ Delete\ Vehicle\n");\n\t printf("4.\ Customize\ Fee\n");\n\t printf("5.\ Query\ Vehicle\n");\n\t printf("6.\ Pay\ Fee\n");\n\t printf("0.\ Exit\n");\n\t printf("Please\ enter\ your\ choice:\ ");\n\t scanf("%d",\ &choice);\n\n\t switch\ (choice)\ {\n\t case\ 1:\n\t addVehicle(vehicles,\ &count,\ file);\n\t break;\n\t case\ 2:\n\t modifyVehicle(vehicles,\ count,\ file);\n\t break;\n\t case\ 3:\n\t deleteVehicle(vehicles,\ &count,\ file);\n\t break;\n\t case\ 4:\n\t customizeFee(&fee,\ file);\n\t break;\n\t case\ 5:\n\t queryVehicle(vehicles,\ count);\n\t break;\n\t case\ 6:\n\t payFee(vehicles,\ count,\ file);\n\t break;\n\t case\ 0:\n\t printf("Thank\ you\ for\ using\ the\ Parking\ Lot\ Management\ System!\n");\n\t break;\n\t default:\n\t printf("Invalid\ choice,\ please\ try\ again.\n");\n\t }\n\n\t printf("\n");\n\t}\ while\ (choice\ !=\ 0);\n\n\tfree(vehicles);\n\tfclose(file);\n\n\treturn\ 0;\n}\n\nvoid\ addVehicle(Vehicle\ *vehicles,\ int\ *count,\ FILE\ *file)\ {\n\tprintf("Add\ Vehicle\n");\n\n\tprintf("Enter\ vehicle\ type\ (Car/Motorcycle/Bicycle):\ ");\n\tscanf("%s",\ vehicles[*count].type);\n\n\tprintf("Enter\ license\ plate:\ ");\n\tscanf("%s",\ vehicles[*count].licensePlate);\n\n\tprintf("Enter\ parking\ location:\ ");\n\tscanf("%s",\ vehicles[*count].parkingLocation);\n\n\tprintf("Enter\ parking\ time\ (in\ minutes):\ ");\n\tscanf("%d",\ &vehicles[*count].parkingTime);\n\n\tif\ (strcmp(vehicles[*count].type,\ "Car")\ ==\ 0)\ {\n\t vehicles[*count].parkingFee\ =\ vehicles[*count].parkingTime\ *\ 0.01;\n\t}\ else\ if\ (strcmp(vehicles[*count].type,\ "Motorcycle")\ ==\ 0)\ {\n\t vehicles[*count].parkingFee\ =\ vehicles[*count].parkingTime\ *\ 0.02;\n\t}\ else\ if\ (strcmp(vehicles[*count].type,\ "Bicycle")\ ==\ 0)\ {\n\t vehicles[*count].parkingFee\ =\ vehicles[*count].parkingTime\ *\ 0.03;\n\t}\n\n\tfprintf(file,\ "%s\ %s\ %s\ %d\ %.2f\n",\ vehicles[*count].type,\ vehicles[*count].licensePlate,\ vehicles[*count].parkingLocation,\ vehicles[*count].parkingTime,\ vehicles[*count].parkingFee);\n\n\t(*count)++;\n}\n\nvoid\ modifyVehicle(Vehicle\ *vehicles,\ int\ count,\ FILE\ *file)\ {\n\tprintf("Modify\ Vehicle\n");\n\n\tchar\ licensePlate[20];\n\tprintf("Enter\ license\ plate\ of\ the\ vehicle\ to\ modify:\ ");\n\tscanf("%s",\ licensePlate);\n\n\tint\ found\ =\ 0;\n\tfor\ (int\ i\ =\ 0;\ i\ <\ count;\ i++)\ {\n\t if\ (strcmp(vehicles[i].licensePlate,\ licensePlate)\ ==\ 0)\ {\n\t printf("Enter\ new\ parking\ location:\ ");\n\t scanf("%s",\ vehicles[i].parkingLocation);\n\n\t printf("Enter\ new\ parking\ time\ (in\ minutes):\ ");\n\t scanf("%d",\ &vehicles[i].parkingTime);\n\n\t if\ (strcmp(vehicles[i].type,\ "Car")\ ==\ 0)\ {\n\t vehicles[i].parkingFee\ =\ vehicles[i].parkingTime\ *\ 0.01;\n\t }\ else\ if\ (strcmp(vehicles[i].type,\ "Motorcycle")\ ==\ 0)\ {\n\t vehicles[i].parkingFee\ =\ vehicles[i].parkingTime\ *\ 0.02;\n\t }\ else\ if\ (strcmp(vehicles[i].type,\ "Bicycle")\ ==\ 0)\ {\n\t vehicles[i].parkingFee\ =\ vehicles[i].parkingTime\ *\ 0.03;\n\t }\n\n\t fprintf(file,\ "%s\ %s\ %s\ %d\ %.2f\n",\ vehicles[i].type,\ vehicles[i].licensePlate,\ vehicles[i].parkingLocation,\ vehicles[i].parkingTime,\ vehicles[i].parkingFee);\n\n\t printf("Vehicle\ information\ modified\ successfully.\n");\n\t found\ =\ 1;\n\t break;\n\t }\n\t}\n\n\tif\ (!found)\ {\n\t printf("Vehicle\ not\ found.\n");\n\t}\n}\n\nvoid\ deleteVehicle(Vehicle\ *vehicles,\ int\ *count,\ FILE\ *file)\ {\n\tprintf("Delete\ Vehicle\n");\n\n\tchar\ licensePlate[20];\n\tprintf("Enter\ license\ plate\ of\ the\ vehicle\ to\ delete:\ ");\n\tscanf("%s",\ licensePlate);\n\n\tint\ found\ =\ 0;\n\tfor\ (int\ i\ =\ 0;\ i\ <\ *count;\ i++)\ {\n\t if\ (strcmp(vehicles[i].licensePlate,\ licensePlate)\ ==\ 0)\ {\n\t for\ (int\ j\ =\ i;\ j\ <\ *count\ -\ 1;\ j++)\ {\n\t vehicles[j]\ =\ vehicles[j\ +\ 1];\n\t }\n\t (*count)--;\n\t printf("Vehicle\ deleted\ successfully.\n");\n\t found\ =\ 1;\n\t break;\n\t }\n\t}\n\n\tif\ (!found)\ {\n\t printf("Vehicle\ not\ found.\n");\n\t}\n\n\t//\ Rewrite\ the\ file\ with\ the\ updated\ vehicle\ information\n\tfclose(file);\n\tfile\ =\ fopen("vehicles.txt",\ "w");\n\tfor\ (int\ i\ =\ 0;\ i\ <\ *count;\ i++)\ {\n\t fprintf(file,\ "%s\ %s\ %s\ %d\ %.2f\n",\ vehicles[i].type,\ vehicles[i].licensePlate,\ vehicles[i].parkingLocation,\ vehicles[i].parkingTime,\ vehicles[i].parkingFee);\n\t}\n}\n\nvoid\ customizeFee(Fee\ *fee,\ FILE\ *file)\ {\n\tprintf("Customize\ Fee\n");\n\n\tprintf("Enter\ car\ fee\ per\ minute:\ ");\n\tscanf("%f",\ &fee->carFee);\n\n\tprintf("Enter\ motorcycle\ fee\ per\ minute:\ ");\n\tscanf("%f",\ &fee->motorcycleFee);\n\n\tprintf("Enter\ bicycle\ fee\ per\ minute:\ ");\n\tscanf("%f",\ &fee->bicycleFee);\n\n\tfprintf(file,\ "%.2f\ %.2f\ %.2f\n",\ fee->carFee,\ fee->motorcycleFee,\ fee->bicycleFee);\n\n\tprintf("Fee\ customized\ successfully.\n");\n}\n\nvoid\ queryVehicle(Vehicle\ *vehicles,\ int\ count)\ {\n\tprintf("Query\ Vehicle\n");\n\n\tchar\ licensePlate[20];\n\tprintf("Enter\ license\ plate\ of\ the\ vehicle\ to\ query:\ ");\n\tscanf("%s",\ licensePlate);\n\n\tint\ found\ =\ 0;\n\tfor\ (int\ i\ =\ 0;\ i\ <\ count;\ i++)\ {\n\t if\ (strcmp(vehicles[i].licensePlate,\ licensePlate)\ ==\ 0)\ {\n\t printf("Vehicle\ Type:\ %s\n",\ vehicles[i].type);\n\t printf("License\ Plate:\ %s\n",\ vehicles[i].licensePlate);\n\t printf("Parking\ Location:\ %s\n",\ vehicles[i].parkingLocation);\n\t printf("Parking\ Time:\ %d\ minutes\n",\ vehicles[i].parkingTime);\n\t printf("Parking\ Fee:\ %.2f\n",\ vehicles[i].parkingFee);\n\t found\ =\ 1;\n\t break;\n\t }\n\t}\n\n\tif\ (!found)\ {\n\t printf("Vehicle\ not\ found.\n");\n\t}\n}\n\nvoid\ payFee(Vehicle\ *vehicles,\ int\ count,\ FILE\ *file)\ {\n\tprintf("Pay\ Fee\n");\n\n\tchar\ licensePlate[20];\n\tprintf("Enter\ license\ plate\ of\ the\ vehicle\ to\ pay\ fee:\ ");\n\tscanf("%s",\ licensePlate);\n\n\tint\ found\ =\ 0;\n\tfor\ (int\ i\ =\ 0;\ i\ <\ count;\ i++)\ {\n\t if\ (strcmp(vehicles[i].licensePlate,\ licensePlate)\ ==\ 0)\ {\n\t float\ feeToPay\ =\ vehicles[i].parkingFee;\n\t printf("Fee\ to\ Pay:\ %.2f\n",\ feeToPay);\n\n\t int\ paymentMethod;\n\t printf("Select\ payment\ method:\n");\n\t printf("1.\ Cash\n");\n\t printf("2.\ Credit\ Card\n");\n\t printf("Please\ enter\ your\ choice:\ ");\n\t scanf("%d",\ &paymentMethod);\n\n\t if\ (paymentMethod\ ==\ 1)\ {\n\t printf("Payment\ successful.\ Thank\ you!\n");\n\t found\ =\ 1;\n\t break;\n\t }\ else\ if\ (paymentMethod\ ==\ 2)\ {\n\t float\ creditCardNumber;\n\t printf("Enter\ credit\ card\ number:\ ");\n\t scanf("%f",\ &creditCardNumber);\n\n\t printf("Payment\ successful.\ Thank\ you!\n");\n\t found\ =\ 1;\n\t break;\n\t }\ else\ {\n\t printf("Invalid\ payment\ method.\n");\n\t }\n\t }\n\t}\n\n\tif\ (!found)\ {\n\t printf("Vehicle\ not\ found.\n");\n\t}\n
原文地址: https://www.cveoy.top/t/topic/pyJp 著作权归作者所有。请勿转载和采集!