用c语言实现景区录入系统函数
时间: 2023-10-23 14:08:28 浏览: 64
基于C语言实现的(控制台)景区旅游信息管理系统【100010647】
好的,我可以为您提供一个基本的景区录入系统函数的C语言实现。以下是一个简单的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME_LENGTH 50
#define MAX_DESC_LENGTH 100
struct ScenicSpot {
char name[MAX_NAME_LENGTH];
char description[MAX_DESC_LENGTH];
int rating;
};
void addScenicSpot(struct ScenicSpot* spots, int* numSpots);
void displayScenicSpots(struct ScenicSpot* spots, int numSpots);
int main() {
struct ScenicSpot spots[100];
int numSpots = 0;
int choice = 0;
while (1) {
printf("------------------------------\n");
printf("1. Add a scenic spot\n");
printf("2. Display all scenic spots\n");
printf("3. Exit\n");
printf("------------------------------\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addScenicSpot(spots, &numSpots);
break;
case 2:
displayScenicSpots(spots, numSpots);
break;
case 3:
printf("Exiting program...\n");
exit(0);
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}
void addScenicSpot(struct ScenicSpot* spots, int* numSpots) {
if (*numSpots >= 100) {
printf("Maximum number of scenic spots reached.\n");
return;
}
struct ScenicSpot newSpot;
printf("Enter the name of the scenic spot: ");
scanf("%s", newSpot.name);
printf("Enter a description for the scenic spot: ");
scanf("%s", newSpot.description);
printf("Enter a rating (1-5) for the scenic spot: ");
scanf("%d", &newSpot.rating);
spots[*numSpots] = newSpot;
(*numSpots)++;
printf("Scenic spot added successfully!\n");
}
void displayScenicSpots(struct ScenicSpot* spots, int numSpots) {
if (numSpots == 0) {
printf("No scenic spots to display.\n");
return;
}
printf("Scenic spots:\n");
for (int i = 0; i < numSpots; i++) {
printf("%d. %s\n", i + 1, spots[i].name);
printf(" Description: %s\n", spots[i].description);
printf(" Rating: %d\n", spots[i].rating);
}
}
```
这个示例实现了一个简单的景区录入系统,允许用户添加新的景区、显示所有景区和退出程序。当用户选择添加景区时,程序会要求他们输入景区名称、景区描述和评级,并将新景区添加到数组中。当用户选择显示所有景区时,程序会遍历数组并打印每个景区的详细信息。请注意,此示例仅提供基本功能,您可能需要根据自己的需求进行修改和扩展。
阅读全文