#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义汽车结构体
typedef struct {
char licensePlate[20];
char model[50];
int repairStatus; // 0: 待维修, 1: 维修中, 2: 已修好
} Car;
// 显示菜单
void showMenu() {
printf(“1. 登记汽车\n”);
printf(“2. 更新维修状态\n”);
printf(“3. 查看汽车信息\n”);
printf(“4. 退出\n”);
}
// 登记汽车
void registerCar(Car *cars, int *numCars) {
Car newCar;
printf(“请输入车牌号: “);
scanf(”%s”, newCar.licensePlate);
printf(“请输入车型: “);
scanf(”%s”, newCar.model);
newCar.repairStatus = 0;
cars[*numCars] = newCar;
(*numCars)++;
}
// 更新维修状态
void updateRepairStatus(Car *cars, int numCars) {
char licensePlate[20];
printf(“请输入要更新状态的车牌号: “);
scanf(”%s”, licensePlate);
int found = 0;
for (int i = 0; i < numCars; i++) {
if (strcmp(cars[i].licensePlate, licensePlate) == 0) {
printf("选择新的维修状态(0: 待维修, 1: 维修中, 2: 已修好): ");
scanf("%d", &cars[i].repairStatus);
found = 1;
break;
}
}
if (!found) {
printf("未找到该车!\n");
}
}
// 查看汽车信息
void viewCarInfo(Car *cars, int numCars) {
for (int i = 0; i < numCars; i++) {
printf(“车牌号: %s, 车型: %s, 维修状态: %d\n”, cars[i].licensePlate, cars[i].model, cars[i].repairStatus);
}
}
int main() {
Car cars[100]; // 假设最多存储 100 辆车
int numCars = 0;
int choice;
do {
showMenu();
printf("请选择操作: ");
scanf("%d", &choice);
switch (choice) {
case 1:
registerCar(cars, &numCars);
break;
case 2:
updateRepairStatus(cars, numCars);
break;
case 3:
viewCarInfo(cars, numCars);
break;
case 4:
printf("退出程序\n");
break;
default:
printf("无效的选择,请重新输入!\n");
}
} while (choice!= 4);
return 0;
}