下面展示一些 内联代码片
。
参考源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义房产信息结构体
struct HouseInfo {
char address[100];
int rooms;
float price;
};
// 全局变量,用于存储房产信息
struct HouseInfo houseData[100];
int totalHouses = 0;
// 函数声明
void inputData();
void displayData();
void insertData();
void deleteData();
void modifyData();
void sortData();
int main() {
int choice;
do {
printf("*************************************************************\n");
printf("* 房产信息管理系统 *\n");
printf("*************************************************************\n");
printf("* 1. 数据录入 *\n");
printf("* 2. 显示房产信息 *\n");
printf("* 3. 插入房产信息 *\n");
printf("* 4. 删除房产信息 *\n");
printf("* 5. 修改房产信息 *\n");
printf("* 6. 按价格排序 *\n");
printf("* 0. 退出 *\n");
printf("*************************************************************\n");
printf("请选择功能:");
scanf("%d", &choice);
switch (choice) {
case 1:
inputData();
break;
case 2:
displayData();
break;
case 3:
insertData();
break;
case 4:
deleteData();
break;
case 5:
modifyData();
break;
case 6:
sortData();
break;
case 0:
printf("退出程序。\n");
break;
default:
printf("无效的选择,请重新输入。\n");
}
} while (choice != 0);
return 0;
}
// 数据录入
void inputData() {
if (totalHouses < 100) {
printf("请输入房产信息:\n");
printf("地址:");
scanf("%s", houseData[totalHouses].address);
printf("房间数:");
scanf("%d", &houseData[totalHouses].rooms);
printf("价格:");
scanf("%f", &houseData[totalHouses].price);
totalHouses++;
printf("房产信息录入成功。\n");
} else {
printf("房产信息已满,无法继续录入。\n");
}
}
// 显示房产信息
void displayData() {
if (totalHouses > 0) {