本文主要是介绍房屋租售管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>#define MAX_SIZE 100
int Money[MAX_SIZE]={0};
int Money_Num=0;typedef struct _Stuff
{int no;//工号char name[20];//姓名char sex[5];//性别char tel[20];//联系方式
}Stuff,*PStuff;//员工管理包括 添加 删除 查看typedef struct _Customer
{char name[20];//姓名char sex[5];//性别char tel[20];//联系方式int age;//年龄int Sale_Or_Buy_Or_Hire;//售还是买
}Cust,*PCust;typedef struct _House
{int no;//房子编号int price;//价格char add[30];//位置int Sale_Or_Hire;//售卖或出租
}House,*PHouse;void Save_Money_Info(int* mon,int n)
{int i;FILE* pFile = fopen("Mon_Info.dat","w");if(pFile==NULL){return;}for(i=0;i<n;i++){fwrite(&mon[i],1,sizeof(int),pFile);}fclose(pFile);
}int Read_Money_Info(int* mon)
{int i=0;FILE* pFile = fopen("Mon_Info.dat","r");if(pFile==NULL){return 0;}while(fread(&mon[i++],1,sizeof(int),pFile));fclose(pFile);if(i>=1){return i-1;}return 0;
}void Code_File_Read()
{char code[20];char temp[20];FILE* pFile=fopen("code.dat","r");system("cls");if(pFile==NULL){printf("检测到第一次使用系统,请设置管理员密码:");scanf("%s",code);pFile=fopen("code.dat","w");fwrite(code,sizeof(char),20,pFile);printf("设置成功!\n");fclose(pFile);system("pause");return ;}fread(code,sizeof(char),20,pFile);printf("请输入原密码:");scanf("%s",temp);if(strcmp(temp,code)){printf("请输入新密码:");scanf("%s",code);fwrite(code,sizeof(char),20,pFile);printf("设置成功!\n");fclose(pFile);system("pause");return ;}printf("密码错误!\n");fclose(pFile);system("pause");
}int Login()
{char code[20];char temp[20];FILE* pFile=fopen("code.dat","r");system("cls");if(pFile==NULL){printf("请先设置管理员密码!\n");system("pause");return 0;}fread(code,sizeof(char),20,pFile);printf("请输入密码:");scanf("%s",temp);if(strcmp(temp,code)){printf("密码错误!\n");fclose(pFile);system("pause");return 0;}fclose(pFile);return 1;
}void Login_Menu()
{int chioce;do{system("cls");printf("1:登录系统\n");printf("2:修改系统密码\n");printf("0:退出\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>2){printf("请重新选择:");scanf("%d",&chioce);}switch(chioce){case 0:exit(0);break;case 1:if(Login())return ;break;case 2:Code_File_Read();break;}}while(chioce!=0);
}int Main_Menu()
{int chioce;system("cls");printf("1:客户管理\n");printf("2:房源管理\n");printf("3:员工管理\n");printf("4:统计分析\n");printf("0:退出\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>4){printf("请重新选择:");scanf("%d",&chioce);}return chioce;
}int Add_Stuff(PStuff stu,int n)
{system("cls");printf("请输入员工工号:");scanf("%d",&stu[n].no);printf("请输入员工姓名:");scanf("%s",stu[n].name);printf("请输入员工性别:");scanf("%s",stu[n].sex);printf("请输入员工联系方式:");scanf("%s",stu[n].tel);printf("添加成功!\n");system("pause");return n+1;
}int Delete_Stuff(PStuff stu,int n)
{int temp,i,j;system("cls");printf("请输入员工工号:");scanf("%d",&temp);for(i=0;i<n;i++){if(temp==stu[i].no){break;}}if(i==n){printf("无该工号,删除失败!\n");system("pause");return n;}for(j=i;j<n;j++){stu[j]=stu[j+1];}printf("删除成功!\n");system("pause");return n-1;
}void Print_Stuff(PStuff stu,int n)
{int i;system("cls");printf("%10s%10s%10%20\n","工号","姓名","性别","联系方式");for(i=0;i<n;i++){printf("%10d",stu[i].no);printf("%10s",stu[i].name);printf("%10s",stu[i].sex);printf("%20s\n",stu[i].tel);}system("pause");
}void Save_Stuff_Info(PStuff stu,int n)
{int i;FILE* pFile = fopen("Stuff_Info.dat","w");if(pFile==NULL){return;}for(i=0;i<n;i++){fwrite(&stu[i],1,sizeof(Stuff),pFile);}fclose(pFile);
}int Read_Stuff_Info(PStuff stu)
{int i=0;FILE* pFile = fopen("Stuff_Info.dat","r");if(pFile==NULL){return 0;}while(fread(&stu[i++],1,sizeof(Stuff),pFile));fclose(pFile);if(i>=1){return i-1;}return 0;
}int Stuff_Menu(PStuff stu,int n)
{int chioce;do{system("cls");printf("1:添加员工\n");printf("2:删除员工\n");printf("3:显示员工\n");printf("0:返回\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>3){printf("请重新选择:");scanf("%d",&chioce);}switch(chioce){case 1:n=Add_Stuff(stu,n);Save_Stuff_Info(stu,n);break;case 2:n=Delete_Stuff(stu,n);Save_Stuff_Info(stu,n);break;case 3:Print_Stuff(stu,n);break;}}while(chioce!=0);return n;
}void Save_Cust_Info(PCust cust,int n)
{int i;FILE* pFile = fopen("Cust_Info.dat","w");if(pFile==NULL){return;}for(i=0;i<n;i++){fwrite(&cust[i],1,sizeof(Cust),pFile);}fclose(pFile);
}int Read_Cust_Info(PCust cust)
{int i=0;FILE* pFile = fopen("Cust_Info.dat","r");if(pFile==NULL){return 0;}while(fread(&cust[i++],1,sizeof(Cust),pFile));fclose(pFile);if(i>=1){return i-1;}return 0;
}int Add_Cust(PCust cust,int n)
{system("cls");printf("请输入客户姓名:");scanf("%s",&cust[n].name);printf("请输入客户年龄:");scanf("%d",&cust[n].age);printf("请输入客户性别:");scanf("%s",&cust[n].sex);printf("请输入客户联系方式:");scanf("%s",&cust[n].tel);printf("请输入客户性质:\n");printf("1:售卖\t2:购买\t3:租借\n");scanf("%d",&cust[n].Sale_Or_Buy_Or_Hire);printf("添加成功!\n");system("pause");return n+1;
}int Delete_Cust(PCust cust,int n)
{int i,j;char temp[20];system("cls");printf("请输入客户姓名:");scanf("%s",temp);for(i=0;i<n;i++){if(!strcmp(temp,cust[i].name)){break;}}if(i==n){printf("无该客户,删除失败!\n");system("pause");return n;}for(j=i;j<n;j++){cust[j]=cust[j+1];}printf("删除成功!\n");system("pause");return n-1;
}void Print_Cust(PCust cust,int n)
{int i;system("cls");printf("%10s%10s%10s%20s%10s\n","姓名","性别","年龄","联系方式","性质");for(i=0;i<n;i++){printf("%10s",cust[i].name);printf("%10s",cust[i].sex);printf("%10d",cust[i].age);printf("%20s",cust[i].tel);switch(cust[i].Sale_Or_Buy_Or_Hire){case 1:printf("%10s\n","售卖");break;case 2:printf("%10s\n","购买");break;case 3:printf("%10s\n","租借");break;}}system("pause");
}int Cust_Menu(PCust cust,int n)
{int chioce;do{system("cls");printf("1:添加客户\n");printf("2:删除客户\n");printf("3:显示客户\n");printf("0:返回\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>3){printf("请重新选择:");scanf("%d",&chioce);}switch(chioce){case 1:n=Add_Cust(cust,n);Save_Cust_Info(cust,n);break;case 2:n=Delete_Cust(cust,n);Save_Cust_Info(cust,n);break;case 3:Print_Cust(cust,n);break;}}while(chioce!=0);return n;
}void Save_House_Info(PHouse house,int n)
{int i;FILE* pFile = fopen("House_Info.dat","w");if(pFile==NULL){return;}for(i=0;i<n;i++){fwrite(&house[i],1,sizeof(House),pFile);}fclose(pFile);
}int Read_House_Info(PHouse house)
{int i=0;FILE* pFile = fopen("House_Info.dat","r");if(pFile==NULL){return 0;}while(fread(&house[i++],1,sizeof(House),pFile));fclose(pFile);if(i>=1){return i-1;}return 0;
}int Add_House(PHouse house,int n)
{system("cls");printf("请输入房源编号:");scanf("%d",&house[n].no);printf("请输入房源性质:\n");printf("1:售卖\t2:租借\n");scanf("%d",&house[n].Sale_Or_Hire);printf("请输入房源位置:");scanf("%s",&house[n].add);printf("请输入房源价格:");scanf("%d",&house[n].price);printf("添加成功!\n");system("pause");return n+1;
}int Delete_House(PHouse house,int n)
{int i,j,temp;system("cls");printf("请输入房源编号:");scanf("%d",&temp);for(i=0;i<n;i++){if(temp==house[i].no){break;}}if(i==n){printf("无该房源,删除失败!\n");system("pause");return n;}for(j=i;j<n;j++){house[j]=house[j+1];}printf("删除成功!\n");system("pause");return n-1;
}void Print_House(PHouse house,int n)
{int i;system("cls");printf("%10s%10s%10s%30s\n","编号","性质","价格","位置");for(i=0;i<n;i++){printf("%10d",house[i].no);switch(house[i].Sale_Or_Hire){case 1:printf("%10s","售卖");break;case 2:printf("%10s","租借");break;}printf("%10d",house[i].price);printf("%30s\n",house[i].add);}system("pause");
}int Sale_House(PHouse house,int n)
{int temp,i,j;system("cls");printf("请输入要交易的房屋编号:");scanf("%d",&temp);for(i=0;i<n;i++){if(temp==house[i].no){break;}}if(i==n){printf("无该房源信息!\n");system("pasue");return n;}Money[Money_Num] += house[i].price * 0.02;for(j=i;j<n;j++){house[j]=house[j+1];}printf("交易成功!\n");printf("本次交易收取手续费:%d\n",Money[Money_Num]);Money_Num++;system("pause");return n-1;}int House_Menu(PHouse house,int n)
{int chioce;do{system("cls");printf("1:添加房源\n");printf("2:删除房源\n");printf("3:显示房源\n");printf("4:进行售卖交易\n");printf("0:返回\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>4){printf("请重新选择:");scanf("%d",&chioce);}switch(chioce){case 1:n=Add_House(house,n);Save_House_Info(house,n);break;case 2:n=Delete_House(house,n);Save_House_Info(house,n);break;case 3:Print_House(house,n);break;case 4:n=Sale_House(house,n);Save_Money_Info(Money,Money_Num);break;}}while(chioce!=0);return n;
}void Total_Cust(PCust cust,int n)
{int i;int arr[3]={0};system("cls");for(i=0;i<n;i++){arr[cust[i].Sale_Or_Buy_Or_Hire-1]++;}printf("%10s%10s%10s\n","售房人数","购房人数","租借人数");printf("%10d%10d%10d\n",arr[0],arr[1],arr[2]);system("pause");
}void Print_Sale_Cust(PCust cust,int n)
{int i;system("cls");printf("%10s%10s%10s%20s%10s\n","姓名","性别","年龄","联系方式","性质");for(i=0;i<n;i++){if(cust[i].Sale_Or_Buy_Or_Hire==1){printf("%10s",cust[i].name);printf("%10s",cust[i].sex);printf("%10d",cust[i].age);printf("%20s",cust[i].tel);printf("%10s\n","售卖");}}system("pause");
}void Print_Buy_Cust(PCust cust,int n)
{int i;system("cls");printf("%10s%10s%10s%20s%10s\n","姓名","性别","年龄","联系方式","性质");for(i=0;i<n;i++){if(cust[i].Sale_Or_Buy_Or_Hire==2){printf("%10s",cust[i].name);printf("%10s",cust[i].sex);printf("%10d",cust[i].age);printf("%20s",cust[i].tel);printf("%10s\n","购买");}}system("pause");
}void Print_Hire_Cust(PCust cust,int n)
{int i;system("cls");printf("%10s%10s%10s%20s%10s\n","姓名","性别","年龄","联系方式","性质");for(i=0;i<n;i++){if(cust[i].Sale_Or_Buy_Or_Hire==3){printf("%10s",cust[i].name);printf("%10s",cust[i].sex);printf("%10d",cust[i].age);printf("%20s",cust[i].tel);printf("%10s\n","租借");}}system("pause");
}void Print_Sale_House(PHouse house,int n)
{int i;system("cls");printf("%10s%10s%10s%30s\n","编号","性质","价格","位置");for(i=0;i<n;i++){if(house[i].Sale_Or_Hire==1){printf("%10d",house[i].no);printf("%10s","售卖");printf("%10d",house[i].price);printf("%30s\n",house[i].add);}}system("pause");
}void Print_Hire_House(PHouse house,int n)
{int i;system("cls");printf("%10s%10s%10s%30s\n","编号","性质","价格","位置");for(i=0;i<n;i++){if(house[i].Sale_Or_Hire==2){printf("%10d",house[i].no);printf("%10s","租借");printf("%10d",house[i].price);printf("%30s\n",house[i].add);}}system("pause");
}void Total_House(PHouse house,int n)
{int i;int arr[2]={0};system("cls");for(i=0;i<n;i++){arr[house[i].Sale_Or_Hire-1]++;}printf("%10s%10s\n","出售房数","出租方数");printf("%10d%10d\n",arr[0],arr[1],arr[2]);system("pause");
}void Total_Money(int mon[],int n)
{int i,sum=0;system("cls");for(i=0;i<n;i++){printf("出售房源,收入佣金%d\n",mon[i]);sum+=mon[i];}printf("总计佣金:%d\n",sum);system("pause");
}void Total_Menu(PCust cust,int cn,PHouse house ,int hn,PStuff stu,int sn)
{int chioce;do{system("cls");printf("1:统计客户需求\n");printf("2:查看售房客户\n");printf("3:查看购房客户\n");printf("4:查看租房客户\n");printf("5:统计房源信息\n");printf("6:查看出售房源\n");printf("7:查看出租房源\n");printf("8:统计佣金收入\n");printf("0:返回\n");printf("请输入选择:");scanf("%d",&chioce);while(chioce<0||chioce>8){printf("请重新选择:");scanf("%d",&chioce);}switch(chioce){case 1:Total_Cust(cust,cn);break;case 2:Print_Sale_Cust(cust,cn);break;case 3:Print_Buy_Cust(cust,cn);break;case 4:Print_Hire_Cust(cust,cn);break;case 5:Total_House(house,hn);break;case 6:Print_Sale_House(house,hn);break;case 7:Print_Hire_House(house,hn);break;case 8:Total_Money(Money,Money_Num);break;}}while(chioce!=0);
}int main()
{int chioce;Stuff stu[MAX_SIZE];Cust cust[MAX_SIZE];House house[MAX_SIZE];int Stuff_NUM=0;int Cust_NUM=0;int House_NUM=0;Login_Menu();Stuff_NUM=Read_Stuff_Info(stu);Cust_NUM=Read_Cust_Info(cust);Money_Num=Read_Money_Info(Money);do{chioce=Main_Menu();switch(chioce){case 1:Cust_NUM=Cust_Menu(cust,Cust_NUM);break;case 2:House_NUM=House_Menu(house,House_NUM);break;case 3:Stuff_NUM=Stuff_Menu(stu,Stuff_NUM);break;case 4:Total_Menu(cust,Cust_NUM,house,House_NUM,stu,Stuff_NUM);break;}}while(chioce!=0);return 0;
}
这篇关于房屋租售管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!