diff --git a/宠物交易系统初步代码.cpp b/宠物交易系统初步代码.cpp new file mode 100644 index 0000000..891b0ba --- /dev/null +++ b/宠物交易系统初步代码.cpp @@ -0,0 +1,108 @@ +#include +#include +#include + +// ṹ +struct Pet { + char name[20]; + int age; + char species[20]; + char price[10]; +}; + +// ȫֱ +int petCount = 0; +struct Pet pets[100]; + +// ӳﺯ +void addPet() { + struct Pet newPet; + printf("ƣ"); + scanf("%s", newPet.name); + printf("䣺"); + scanf("%d", &newPet.age); + printf("Ʒ֣"); + scanf("%s", newPet.species); + printf("۸"); + scanf("%s", newPet.price); + pets[petCount++] = newPet; + printf("ӳɹ\n"); +} + +// 鿴гﺯ +void viewPets() { + printf("гб\n"); + for (int i = 0; i < petCount; i++) { + printf("%d. ƣ%s䣺%dƷ֣%s۸%s\n", i+1, pets[i].name, pets[i].age, pets[i].species, pets[i].price); + } +} + +// ﺯ +void searchPets() { + char keyword[20]; + printf("ҪĹؼʣ"); + scanf("%s", keyword); + printf("\n"); + for (int i = 0; i < petCount; i++) { + if (strstr(pets[i].name, keyword) != NULL || strstr(pets[i].species, keyword) != NULL) { + printf("%d. ƣ%s䣺%dƷ֣%s۸%s\n", i+1, pets[i].name, pets[i].age, pets[i].species, pets[i].price); + } + } +} + +// ﺯ +void buyPet() { + char name[20]; + printf("Ҫijƣ"); + scanf("%s", name); + for (int i = 0; i < petCount; i++) { + if (strcmp(pets[i].name, name) == 0) { + printf("ɹ\n"); + return; + } + } + printf("Ҳó롣\n"); +} + +// ۳ﺯ +void sellPet() { + char name[20]; + printf("Ҫ۵ijƣ"); + scanf("%s", name); + for (int i = 0; i < petCount; i++) { + if (strcmp(pets[i].name, name) == 0) { + printf("۳ɹ\n"); + return; + } + } + printf("Ҳó롣\n"); +} + +int main() { + int choice; + while (1) { + printf("\nサϵͳ\n"); + printf("1. ӳ\n"); + printf("2. 鿴г\n"); + printf("3. \n"); + printf("4. \n"); + printf("5. ۳\n"); + printf("6. ˳ϵͳ\n"); + printf("ѡ"); + scanf("%d", &choice); + switch (choice) { + case 1: + addPet(); + break; + case 2: + viewPets(); + break; + case 3: + searchPets(); + break; + case 4: buyPet(); break; + case 5: sellPet(); break; + default: printf ("Чѡ롣\n"); break; + } + return 0;} + return 0;}