大纲
- 创建链式存储结构。
- 具备插入,删除,查询,显示等基本功能。
- 其余随意,完工。
图片示例展示
代码纯文本示例展示
#include<stdio.h>
#include<Windows.h>
struct student {
int num; //客户编号
char name[50]; //客户名称
char phone[50]; //联系方式
char home[50]; //房屋类型-楼房,平房,其他
float money; //房屋价钱(万元)
char chome[50]; //户型-三室一厅,独门独院,两室一厅,一室一厅
float sizehome; //建筑面积(平方)
char renovation[50]; //装修情况-简单装修,中档装修,高档装修,无装修
char address[50]; //房屋地址
char homenow[50]; //房屋情况-已出售,未出售
}stu, temp;
typedef struct node
{
student stu; //成员数据
struct node* next; //下一个成员
}Node, * Link;
typedef struct
{
Link front; //头
Link rear; //尾
}Emty;
int Add(Emty& Q); //增加信息建立信息表
int Insert(Emty& Q, int e); //插入记录
int Disp(Emty& Q); //查看所有信息
int Del(Emty& Q, int e); //删除功能
int Del(Emty& Q, char nameyy[50]);
int Qur(Emty& Q, int e); //查询功能
int Qur(Emty& Q, char nameyy[50]);
int Menu();
void Wrong();
int chaxun(Emty& Q);
int mydelete(Emty& Q);
void GoHome(); //结束程序
int Init(Emty& Q)
{
Q.front = Q.rear = (Link)malloc(sizeof(Node));
if (!Q.front)
{
printf("ERROR");
return 0;
}
Q.front->next = NULL;
return 1;
}
void menu()
{
printf("\t\t*************欢迎使用中介公司房产信息管理系统***************\n");
printf("\t * 1 建立信息表 *\n");
printf("\t * 2 插入新信息 *\n");
printf("\t * 3 查询信息记录 *\n");
printf("\t * 4 删除信息记录 *\n");
printf("\t * 5 显示信息 *\n");
printf("\t * 0 退出管理系统 *\n");
printf("\t\t*************欢迎使用中介公司房产信息管理系统***************\n");
}
int main()
{
Emty list;
Init(list);
int choose;
system("color 04");
while (1)
{
menu();
printf("\n\t\t\t\t请选择操作:\n请选择0-5:");
scanf("%d", &choose);
switch (choose)
{
case 0:
GoHome(); break;
case 1:Add(list); break; //增加记录
case 2: //插入记录
printf("请输入要插入的编号:");
scanf("%d", &choose);
Insert(list, choose);
break;
case 3: //查询记录
chaxun(list);
break;
case 4: //删除记录
mydelete(list);
break;
case 5:system("cls"); Disp(list); break; //显示记录
default:
Wrong();
break;
}
}
return 0;
}
int Add(Emty& Q) //增加信息建立信息表
{
int a = 1;
while (a)
{
Node* p;
p = (Link)malloc(sizeof(Node));
if (!p)
{
printf("ERROR!");
return 0;
}
printf("请输入客户编号:<输入0则返回上一级菜单>");
scanf("%d", &a);
p->stu.num = a;
if (a == 0) return 0;
printf("\n请输入客户名称:");
scanf("%s", &p->stu.name);
printf("\n请输入联系方式:");
scanf("%s", &p->stu.phone);
printf("\n请输入房屋类型:");
scanf("%s", &p->stu.home);
printf("\n请输入房屋价钱(万元):");
scanf("%f", &p->stu.money);
printf("\n请输入户型:");
scanf("%s", &p->stu.chome);
printf("\n请输入建筑面积(平方):");
scanf("%f", &p->stu.sizehome);
printf("\n请输入装修情况:");
scanf("%s", &p->stu.renovation);
printf("\n请输入房屋地址:");
scanf("%s", &p->stu.address);
printf("\n请输入房屋情况:");
scanf("%s", &p->stu.homenow);
p->next = NULL;
Q.rear->next = p; //P入链表
Q.rear = p; //将P为尾
}
return 1;
}
int Disp(Emty& Q) //查看所有信息
{
if (Q.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
//进行排序
Node* a = Q.front;
Node* b = Q.front->next;
while (b != NULL)
{
while (a->stu.num > b->stu.num)
{
Node* d = a;
Node* e = b;
temp = a->stu;
a->stu = b->stu;
b->stu = temp;
a = Q.front;
b = Q.front->next;
a = a->next;
b = b->next;
if (b == NULL)
{
a = d;
b = e;
}
}
a = a->next;
b = b->next;
}
//输出结果
Node* p = Q.front->next;
printf("\t\t\t显示结果为:\n");
printf("--------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("客户编号|\t客户名称|\t联系方式|\t房屋类型|\t房屋价钱|\t户型|\t建筑面积|\t装修情况|\t房屋地址|\t房屋情况|\n");
printf("--------------------------------------------------------------------------------------------------------------------------------------------------\n");
while (p != NULL)
{
printf(" %d\t\t%s\t\t%s\t %s\t\t%.2f\t\t%s\t%.2f\t\t%s\t\t%s\t\t%s\n",
p->stu.num,
&p->stu.name,
&p->stu.phone,
&p->stu.home,
p->stu.money,
&p->stu.chome,
p->stu.sizehome,
&p->stu.renovation,
&p->stu.address,
&p->stu.homenow);
p = p->next;
}
printf("--------------------------------------------------------------------------------------------------------------------------------------------------\n");
return 1;
}
int Insert(Emty& Q, int e) //插入记录
{
if (Q.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
//判断是否存在
Node* y = Q.front->next;
while (y != NULL)
{
if (y->stu.num == e)
{
printf("已存在该数据!\n");
return 0;
}
y = y->next;
}
Node* p = (Link)malloc(sizeof(Node));
p->stu.num = e; //客户编号
printf("\n请输入客户名称:");
scanf("%s", &p->stu.name);
printf("\n请输入联系方式:");
scanf("%s", &p->stu.phone);
printf("\n请输入房屋类型:");
scanf("%s", &p->stu.home);
printf("\n请输入房屋价钱(万元):");
scanf("%f", &p->stu.money);
printf("\n请输入户型:");
scanf("%s", &p->stu.chome);
printf("\n请输入建筑面积(平方):");
scanf("%f", &p->stu.sizehome);
printf("\n请输入装修情况:");
scanf("%s", &p->stu.renovation);
printf("\n请输入房屋地址:");
scanf("%s", &p->stu.address);
printf("\n请输入房屋情况:");
scanf("%s", &p->stu.homenow);
Node* j = Q.front->next;
while (j != NULL)
{
if (j->next == NULL)
{
j->next = p;
p->next = NULL;
}
j = j->next;
}
return 1;
}
int Del(Emty& Q, int e) //删除功能-编号
{
if (Q.front == Q.rear)
{
printf("链表为空!\n");
return 0;
}
int oo = 0;
Node* j = Q.front->next;
while (j != NULL)
{
if (j->stu.num == e)
{
Node* p = Q.front->next;
Node* k = p->next;
temp = p->stu;
p->stu = j->stu;
j->stu = temp;
Q.front->next = k;
free(p);
oo = 1;
return 1;
}
j = j->next;
}
if (oo == 0)
{
printf("不存在该编号!\n");
}
return 1;
}
int Del(Emty& Q, char nameyy[50]) //删除功能-名称
{
if (Q.front == Q.rear)
{
printf("链表为空!\n");
return 0;
}
int oo = 0;
Node* j = Q.front->next;
while (j != NULL)
{
if (!strcmp(j->stu.name, nameyy))
{
Node* p = Q.front->next;
Node* k = p->next;
temp = p->stu;
p->stu = j->stu;
j->stu = temp;
Q.front->next = k;
free(p);
oo = 1;
return 1;
}
j = j->next;
}
if (oo == 0)
{
printf("不存在该人!\n");
}
return 1;
}
void Wrong()
{
printf("请输入0-5!\n");
}
int chaxun(Emty& list) //查询
{
if (list.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
int choose;
char nameyy[50] = { 0 };
printf("请选择查询方式:\n\n1.编号查询\t2.名称查询\n\n请输入:");
scanf("%d", &choose);
switch (choose)
{
case 1: printf("请输入要查询的编号:");
scanf("%d", &choose);
Qur(list, choose);
break;
case 2: printf("请输入要查询的名称:");
scanf("%s", nameyy);
Qur(list, nameyy);
break;
default:
printf("无此项!");
break;
}
return 1;
}
int Qur(Emty& Q, int e) //查询功能-工号
{
if (Q.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
int oo = 0;
Node* j = Q.front->next;
Node* p = NULL;
while (j != NULL)
{
if (j->stu.num == e)
{
p = j;
oo = 1;
}
j = j->next;
}
if (oo == 0)
{
printf("不存在该编号!\n");
return 0;
}
printf("\n客户编号|\t客户名称|\t联系方式|\t房屋类型|\t房屋价钱|\t户型|\t建筑面积|\t装修情况|\t房屋地址|\t房屋情况|\n");
printf(" %d\t\t%s\t%s\t\t %s\t\t%.2f\t\t%s\t%.2f\t\t%s\t\t%s\t\t%s\n",
p->stu.num,
&p->stu.name,
&p->stu.phone,
&p->stu.home,
p->stu.money,
&p->stu.chome,
p->stu.sizehome,
&p->stu.renovation,
&p->stu.address,
&p->stu.homenow);
return 1;
}
int Qur(Emty& Q, char nameyy[50]) //查询功能-名称
{
if (Q.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
int oo = 0;
Node* j = Q.front->next;
Node* p = NULL;
while (j != NULL)
{
if (!strcmp(j->stu.name, nameyy))
{
p = j;
oo = 1;
}
j = j->next;
}
if (oo == 0)
{
printf("不存在该人!\n");
return 0;
}
printf("\n客户编号|\t客户名称|\t联系方式|\t房屋类型|\t房屋价钱|\t户型|\t建筑面积|\t装修情况|\t房屋地址|\t房屋情况|\n");
printf(" %d\t\t%s\t%s\t\t %s\t\t%.2f\t\t%s\t%.2f\t\t%s\t\t%s\t\t%s\n",
p->stu.num,
&p->stu.name,
&p->stu.phone,
&p->stu.home,
p->stu.money,
&p->stu.chome,
p->stu.sizehome,
&p->stu.renovation,
&p->stu.address,
&p->stu.homenow);
return 1;
}
int mydelete(Emty& list) //删除
{
if (list.front->next == NULL)
{
printf("链表为空!\n");
return 0;
}
int choose;
char nameyy[50] = { 0 };
printf("请选择删除方式:\n\n1.编号删除\t2.名称删除\n\n请输入:");
scanf("%d", &choose);
switch (choose)
{
case 1: printf("请输入要删除的编号:");
scanf("%d", &choose);
Del(list, choose);
break;
case 2: printf("请输入要删除的名称:");
scanf("%s", nameyy);
Del(list, nameyy);
break;
default:
printf("无此项!");
break;
}
return 1;
}
void GoHome() //结束程序
{
printf("即将关闭程序!\n");
exit(0);
}
实现效果图
建表功能
插入功能
查询功能
删除功能
退出程序
End
~结束,保留备忘
~~