C++课程设计 房产中介管理系统(代码全)

  • 房屋中介公司需要对日常工作中涉及到的房屋、房主和租房顾客等各类数据进行有效地管理,以实现业务的自动化,提高运行效率的同时也能够降低人力成本。本设计主要针对房屋中介公司建立一个简单应用系统。

1 需求分析

房屋中间管理系统主要的是:
(1)房主能够发布房屋信息,并能够对房屋信息进行修改和删除;
(2)租房顾客能够查询房屋信息,请求看房,并确定租房完成租房交易。

在这里插入图片描述

话不多说直接上代码:

主函数:调用创建的各种类和方法

#include"deal.h"
#include"house.h"
#include"house_owner.h"
#include"look_house.h"
#include"staff.h"
#include"tenant.h"
#include <iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<fstream>
#include<iomanip>
static int kk = 100;
using namespace std;
class customer_information :public house_owner, public tenant {                  //派生租房者类及房主类的子类
public:
    void display() {                                                       //输出客户信息
        dis_information();
        cout << endl << endl;
        dis_tenant();
    }
    bool find(string a,char *b);                                      //判断登录密码是否正确
    void amend();                                                   //修改密码

};


bool customer_information::find(string a,char *b) {                                   //判断用户登录密码是否正确
    if (findt(a, b,0) || findh(a, b,0)) {
        return true;
    }
    else return false;
}

void customer_information::amend() {                                           //修改用户密码
    system("cls");
    string a;
    char  b[20];;
        cout << "请输入你的用户名:"; cin >> a;
        cout << "请输入你的原密码:"; cin >> b;
        customer_information s;
        while (!s.find(a, b)) {
            cout << "用户名或密码错误!" << endl;
            cout << "请重新输入用户名:"; cin >> a;
            cout << "请重新输入密码:"; cin >> b;
        }
        cout << "请输入你要修改的密码:"; cin >> b;
        if (s.findh(a, b, 1) || s.findt(a, b, 1)) {
            cout << "修改成功!" << endl;   
        }
    system("pause");
}

void code_file_Read() {                                     //设置系统使用者密码,第一次使用系统时设置,录入第一位管理者
    char code[20];
    char temp[20];
    ifstream fin("code.dat");
    system("cls");
    int k = 0;
    while (fin >> code) {
        k++;
    }
    if (k == 0) {
        cout << "检测到第一次使用系统,请先设置系统密码:";
        ofstream fout("code.dat");
        if (!fout) {
            cout << "打开code.dat文件失败!" << endl;
            abort();
        }
        cin >> code;
        fout << code << "\n";                         //写入密码文件
        cout << "密码设置成功!" << endl;
        system("pause");
        fin.close();
        fout.close();
        return;
    }
    fin.close();
} 

void code_file_delete(){                                                              //修改系统管理者密码
          char code[20];
         char temp[20];
        ifstream fin("code.dat");
        if (!fin) {
            cout << "打开文件code.dat失败!" << endl;
            abort();
        }
        fin >> code;
        cout << "请输入原密码:";
        do {
            cin >> temp;
            if (strcmp(temp, code) == 0) {
                ofstream fout("code.dat");
                if (!fout) {
                    cout << "打开code.dat文件失败!" << endl;
                    abort();
                }
                cout << "请输入新密码:";
                cin >> code;
                fout << code << "\n";
                cout << "设置成功!";
                fin.close();
                fout.close();
                system("pause");
                return;
            }
            else {
                cout << "密码错误,请重新输入原密码:";
                cin >> temp;
            }
        } while (1);
}

int main_menu() {                                           //管理员登录之后界面
    int chioce;
    system("cls");
    cout << "1:客户管理\n";
    cout << "2:房源管理\n";
    cout << "3:员工管理\n";
    cout << "4:查看交易信息\n";
    cout << "5:修改密码\n";
    cout << "6.查看佣金\n";
    cout << "7.看房信息管理\n";
    cout << "0:退出\n";
    cout << "请输入选择:";
    cin >> chioce;
    while (chioce < 0 || chioce>7) {
        cout << "请重新选择:";
        cin >> chioce;
    }
    return chioce;
}

void add_customer() {                                        //添加客户信息
    int chioce;
    house_owner s1;
    tenant s;
    do {
        system("cls");
        cout << "1.添加租房者客户信息" << endl;
        cout << "2.添加房主客户信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce > 2 || chioce < 0) {
            cout << "请重新输入你的选择:" << endl;
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.get_tenant();
            break;
        case 2:
            s1.get_information();
            break;
        case 0:
            break;
        }
    } while (chioce != 0);
    system("pause");
}

void delete_customer() {                                                 //删除客户信息
    int chioce;
    tenant s;
    house_owner s1;
    do {
        system("cls");
        cout << "1.删除租房者客户信息" << endl;
        cout << "2.删除房主客户信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce > 2 || chioce < 0) {
            cout << "请重新输入你的选择:" << endl;
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.delete_tenant();
            break;
        case 2:
            s1.delete_information();
            break;
        case 0:
            break;
        }
        system("pause");
    } while (chioce != 0);
   
}

void modify_customer() {                                                //修改客户信息
    int chioce;
    tenant s;
    house_owner s1;
    do {
        system("cls");
        cout << "1.修改租房者客户信息" << endl;
        cout << "2.修改房主客户信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce > 2 || chioce < 0) {
            cout << "请重新输入你的选择:" << endl;
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.amend_tenant();
            break;
        case 2:
            s1.amend_information();
            break;
        }
        system("pause");
    } while (chioce != 0);
}

void query_customer() {                                        //查询客户信息
    int chioce;
    tenant s;
    house_owner s1;
    do {
        system("cls");
        cout << "1.查询租房者客户信息" << endl;
        cout << "2.查询房主客户信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce > 2 || chioce < 0) {
            cout << "请重新输入你的选择:" << endl;
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.find_tenant();
            break;
        case 2:
            s1.find_information();
            break;
        case 0:
            break;
        }
    } while (chioce != 0);
}

int Customer_management() {                                      //管理客户的功能函数
    int chioce;
    customer_information s;
    do {
        system("cls");
        cout << "1.显示客户信息" << endl;
        cout << "2.添加客户" << endl;
        cout << "3.删除客户" << endl;
        cout << "4.修改客户信息" << endl;
        cout << "5.查询客户信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce < 0 || chioce>5) {
            cout << "请重新选择:";
            cin >> chioce;
        }
        switch (chioce) {                                    
        case 1:
            s.display();
            break;
        case 2:
            add_customer();
            break;
        case 3:
            delete_customer();
            break;
        case 4:
            modify_customer();
            break;
        case 5:
            query_customer();
            break;
        case 0:
            break;
        }
    } while (chioce != 0);
        return chioce;
}

void housing_management() {                                            //房源管理信息
    int chioce;
    house s;
    do {
        system("cls");
        cout << "1.显示房屋信息" << endl;
        cout << "2.添加房屋信息" << endl;
        cout << "3.删除房屋信息" << endl;
        cout << "4.修改房屋信息" << endl;
        cout << "5.查询房屋信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce < 0 || chioce>5) {
            cout << "请重新输入你的选择:";
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.dis_house();
            break;
        case 2:
            s.get_house();
            break;
        case 3:
            s.delete_house();
            break;
        case 4:
            s.amend_house();
            break;
        case 5:
            s.find_house();
            break;
        case 0: break;
        }
       
    } while (chioce != 0);
}
 
void staff_management() {                                             //员工信息管理界面
    int chioce;
    staff s;
    do {
        system("cls");
        cout << "1.显示员工信息" << endl;
        cout << "2.添加员工信息" << endl;
        cout << "3.删除员工信息" << endl;
        cout << "4.修改员工信息" << endl;
        cout << "5.查询员工信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce < 0 || chioce>5) {
            cout << "请重新输入你的选择:";
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.dis_staff();
            break;
        case 2:
            s.get_staff();
            break;
        case 3:
            s.delete_staff();
            break;
        case 4:
            s.amend_staff();
            break;
        case 5:
            s.find_staff();
            break;
        case 0: break;
        }
       
    } while (chioce != 0);
    system("pause");
}

void trader() {                                                 //交易信息管理界面
    int chioce;
    deal s;
    system("cls");
    do {
        system("cls");
        cout << "1.显示交易信息" << endl;
        cout << "2.添加交易信息" << endl;
        cout << "3.删除交易信息" << endl;
        cout << "4.查询交易信息" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce < 0 || chioce>5) {
            cout << "请重新输入你的选择:";
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.dis_deal();
            break;
        case 2:
            s.get_deal();
            break;
        case 3:
            s.delete_deal();
            break;
        case 4:
            s.find_deal();
            break;
        }
    } while (chioce != 0);
    system("pause");
}

void rental() {                                                              //用户租赁房屋
    cout << "请选择你要租赁得房屋编号:";
    char a[20];
    cin >> a;
    house s;
    deal s1;
    float b=s.amend_status(a);
    s1.auto_deal(b);
    cout << "租赁成功!" << endl;
    system("pause");
}

void UI() {
    system("cls");
    int chioce;
    int n = 1;
    do {
        cout << "请输入用户名:";
        char a[20]; cin >> a;
        cout << "请输入密码:";
        char b[20]; cin >> b;
        customer_information s;
        while (!s.find(a, b)) {
            cout << "请重新输入用户名:"; cin >> a;
            cout << "请重新输入密码:"; cin >> b;
        }
        if (s.find(a, b)) {
            n = 0;
            cout << "登录成功!" << endl;
            system("pause");
        }
    } while (n);
    system("cls");
    house s;
    look_house sss;
    customer_information ss;
    do {
        system("cls");
        cout << "1.显示房屋信息" << endl;
        cout << "2.租赁房屋" << endl;
        cout << "3.实地看房" << endl;
        cout << "4.修改密码" << endl;
        cout << "0.返回" << endl;
        cout << "请输入你的选择:";
        cin >> chioce;
        switch (chioce) {
        case 1:
            s.dis_house();
            break;
        case 2:
            s.dis_house();
            rental();
            break;
        case 3:
            s.dis_house();
            sss.get_look();
            break;
        case 4:
            ss.amend();
            break;
        
        }
    } while (chioce);
}

bool login_management() {
    bool m = false;
    system("cls");
    char code[20];
    char temp[20];
    ifstream fin("code.dat");
    if (!fin) {
        cout << "打开文件code.dat失败!" << endl;
        abort();
    }
    int chioce = 1;
    fin >> code;
    fin.close();
    cout << "请输入密码:";
    cin >> temp;
    do {
        if (strcmp(code, temp) == 0) { m = true; chioce = 0; }
        else { cout << "密码错误!请重新输入:"; cin >> temp; }
    } while (chioce);
    return m;
}

void look_look() {
    look_house s;
    int chioce = 1;
    do {
        system("cls");
        cout << "1.显示看房信息\n";
        cout << "2.修改看房信息\n";
        cout << "3.删除看房信息\n";
        cout << "4.查询看房信息\n";
        cout << "0.返回\n";
        cout << "请输入你的选择:";
        cin >> chioce;
        while (chioce > 4 || chioce < 0) {
            cout << "请重新输入你的选择:";
            cin >> chioce;
        }
        switch (chioce) {
        case 1:
            s.dis_look();
            break;
        case 2:
            s.amend_look();
            break;
        case 3:
            s.delete_look();
            break;
        case 4:
            s.find_look();
            break;
        }

    } while (chioce);
}

void chioces(int chioce) {
    system("cls");
    deal s;
    switch (chioce) {
    case 1:
        Customer_management();
        break;
    case 2:
        housing_management();
        break;
    case 3:
        staff_management();
        break;
    case 4:
        trader();
        break;
    case 5:
        code_file_delete();
        break;
    case 6:
        cout << "总佣金收入:" << s.brokerage() << endl;
        system("pause");
        break;
    case 7:
        look_look();
        break;
    case 0:
        break;
    }
    
}

void sign_in() {                                       //注册函数
    system("cls");
    string name;                //租房者姓名 
    char password[20];          //租房者密码 
    string sex;                 //租房者性别 
    char phone[20];             //租房者电话号码 
    string profession;           //租房者职业 
    cout << "请输入你的用户名:"; cin >> name;
    cout << "请设置你的密码:"; cin >> password;
    cout << "请输入你的性别:"; cin >> sex;
    cout << "请输入你的电话号码:"; cin >> phone;
    cout << "请输入你的职业:"; cin >> profession;
    ofstream fout("tenant.txt", ios::app);
    if (!fout) {
        cout << "打开文件tenant.txt失败!" << endl;
        abort();
    }
    kk = kk + 1;
    fout << kk << " " << name << " " << password << " " << sex << " " << phone << " " << profession << "\n";
    fout.close();
    cout << "注册成功!" << endl;
    system("pause");
}

int main()
{
    int flag = true;
    int chioce;
    code_file_Read();
    while (flag)

    {

        system("cls");

        cout << endl;

        cout << endl;

        cout << endl;

        cout << setw(60) << "        欢迎进入房屋租赁系统          " << endl;

        cout << endl;

        cout << endl;

        cout << endl;

        cout << setw(60) << "  ══════════════════" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║           管理员登录(1):          ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║            用户登录(2):           ║" << endl;
        
        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║              注册(3)               ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║            退出系统(4):           ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "║                                    ║" << endl;

        cout << setw(60) << "  ══════════════════" << endl;

        cout << endl;

        cout << endl;

        cout << endl;

        cout << setw(54) << "请输入您接下来的操作(1-4):";

        int t;

        cin >> t;

        while (t < 1 || t>4) {
            cout << setw(54) << "请重新输入您的操作(1-4):";
            cin >> t;
        }

        switch (t)

        {
        case 1:
            if (login_management()) {
                do {
                    chioce = main_menu();
                    chioces(chioce);
                } while (chioce);
            }
            break;
        case 2:
            UI();
            break;
        case 3:
            sign_in();
            break;
        case 4: flag = false; break;
        }

    }

    return 0;

}

交易类:

#pragma once
#include<iostream>
#include<string>
using namespace std;
class deal {                        //交易信息类
public:
	deal();
	void get_deal();                //交易信息的录入
	void dis_deal();               //交易信息的输出
	void delete_deal();             //交易信息的删除
	void find_deal();                //信息查询
	void auto_deal(float a);                //自动生成交易信息
	double brokerage();                     //记录佣金,返回佣金
	friend ofstream& operator<<(ofstream& out, deal stu);
private:
	char deal_number[20];          //交易信息编号
	float deal_money;              //交易金额
	time_t deal_creation_time;      //记录交易的时间  
	static int bianhao;                  //交易编号               
};



交易的实现

#include "deal.h"
#include<iostream>
#include<fstream>
#include<Windows.h>
#include<iomanip>
#include<time.h>
#include<string>
#include<cstring>
using namespace std;
int deal::bianhao = 50;
deal::deal() {
	strcpy_s(deal_number, "0");
	deal_money = 0;
	deal_creation_time = '0';
}

ofstream& operator<<(ofstream& out, deal stu) {                 //重载流插入运算符
	out << stu.deal_number << " ";
	out << stu.deal_money << " ";
	out << stu.deal_creation_time << "\n";
	return out;
}

void deal::get_deal() {                                               
	system("cls");
	ofstream fout("deal.txt", ios::app);
	if (!fout) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	cout << "请输入交易编号:"; cin >> deal_number; fout << deal_number << " ";
	cout << "请输入交易金额:"; cin >> deal_money; fout << deal_money << " ";
	deal_creation_time=time(NULL); fout << deal_creation_time << "\n";
	cout << "录入成功!" << endl;
	system("pause");
	fout.close();
}

void deal::dis_deal() {                                                   //编号排序输出-冒泡排序
	system("cls");
	ifstream fin("deal.txt");
	if (!fin) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	cout << setw(10) << "交易编号" << setw(10) << "交易金额" << setw(15) << "收取的中介费" << setw(20) << "交易时间" << endl;
	deal stu[205];
	int n = 0;
	while (fin >> stu[n].deal_number >> stu[n].deal_money >> stu[n].deal_creation_time) {
		n++;
	}
	fin.close();
	for (int j = 0; j < n; j++) {
		for (int k = 0; k < n - j - 1; k++) {
			if (strcmp(stu[k].deal_number,stu[k + 1].deal_number)>0) {
				deal temp1 = stu[k];
				stu[k] = stu[k + 1];
				stu[k + 1] = temp1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << setw(10) << stu[i].deal_number << setw(10) << stu[i].deal_money << setw(15) << stu[i].deal_money * 0.05 << setw(20) << stu[i].deal_creation_time << endl;
	}
	system("pause");
}
void deal::delete_deal() {                                                  //删除交易信息
	system("cls");
	cout << "请输入你要删除的交易编号:";
	char temp[20];
	cin >> temp;
	deal str[205];
	ifstream fin("deal.txt");
	if (!fin) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	int n = 0;
	while (!fin.eof()) {
		fin >> str[n].deal_number >> str[n].deal_money >> str[n].deal_creation_time;
		n++;
	}
	n = n - 1;                                         //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
	fin.close();
	ofstream fout("deal.txt");
	if (!fout) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	int k = 0;
	bool l = true;
	for (int i = 0; i < n; i++) {
		if (strcmp(str[i].deal_number, temp) == 0) {
			k = i;
			l = false;
			break;
		}
	}
	if (l) {
		for (int i = 0; i < n ; i++) {
			fout << str[i] << "\n";
		}
		cout << "此编号的交易信息不存在!删除失败!" << endl;
	}
	else {
		for (int i = k; i < n - 1; i++) {
			str[i] = str[i + 1];
		}
		for (int i = 0; i < n - 1; i++) {
			fout << str[i] << "\n";
		}
		cout << "删除成功!" << endl;
	}
	system("pause");
	fout.close();
}

void deal::find_deal() {                                             //查找交易信息
	system("cls");
	cout << "请输入你想查找的交易信息编号" << endl;
	char temp[20];
	cin >> temp;
	bool k = true;
	ifstream fin("deal.txt");
	if (!fin) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	deal stu[205];
	int n = 0;
	while (fin >> stu[n].deal_number >> stu[n].deal_money >> stu[n].deal_creation_time) {
		n++;
	}
	fin.close();
	do {
		for (int i = 0; i < n; i++) {
			if (strcmp(stu[i].deal_number, temp) == 0) {
				cout << setw(10) << "交易编号" << setw(10) << "交易金额" << setw(15)<<"收取的中介费" << setw(20) << "交易时间" << endl;
				cout << setw(10) << stu[i].deal_number << setw(10) << stu[i].deal_money << setw(15) << stu[i].deal_money * 0.05 << setw(20) << stu[i].deal_creation_time << endl;
				k = false;
				break;
			}
		}
		if (k) {
			cout << "该编号交易信息不存在!请重新输入交易信息编号:";
			cin >> temp;
		}
	} while (k);
	system("pause");
}

void deal::auto_deal(float a) {                         //增加交易信息
	ofstream fout("deal.txt", ios::app);
	if (!fout) {
		cout << "打开deal.txt失败!" << endl;
		abort();
	}
	bianhao += 1;
	SYSTEMTIME s;
	GetLocalTime(&s);
	fout << bianhao << " " << a  << " " << s.wYear << s.wMonth << s.wDay << "\n";
	cout << setw(10) << "交易编号" << setw(10) << "交易金额" << setw(15) << "交易时间" << endl;
	cout << setw(10) << bianhao << setw(10) << a << setw(15) << s.wYear <<"-"<< s.wMonth << "-" << s.wDay << endl;
	fout.close();
}

double deal::brokerage() {                                //返回佣金值
	ifstream fin("deal.txt");
	if (!fin) {
		cout << "打开文件deal.txt失败!" << endl;
		abort();
	}
	deal stu[105];
	int n = 0;
	double sum = 0;
	while (fin >> stu[n].deal_number >> stu[n].deal_money >> stu[n].deal_creation_time) {
		n++;
	}
	fin.close();
	for (int i = 0; i < n; i++) {
		sum += stu[i].deal_money * 0.05;
	}
	cout << "共租赁出" << n << "套房屋." << endl;
	return sum;
}

房屋类:主要管理房屋信息

#pragma once
#include<iostream>
#include<string>
using namespace std;
class house {                           //房屋类
public: 
	house();
	friend ofstream& operator<<(ofstream& out,house stu);         //重载插入运算符
	void get_house();                                             //用于房屋信息录入采集
	void dis_house();                                             //用于房屋信息输出
	void delete_house();                                                //房屋信息删除
	void find_house();                                             //信息查询
	void amend_house();                                            //修改信息
	float amend_status(char* a);                                   //修改房屋状态
private:
	char house_number[20];           //房屋编号 
	string building_site;             //房屋地点 
	float house_area;                //房屋面积 
	string house_type;               //房屋户型 
	float house_price;               //房屋价格 
	string house_status;             //房屋出租状态 
};

房屋类的实现:

#include "house.h"
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
house::house() {
	strcpy_s(house_number, "0");
	house_area = 0;
	house_type = '0';
	house_price = 0;
	house_status = '0';
	building_site = '0';
}

ofstream& operator <<(ofstream& out,house stu) {
	out << stu.house_number << " ";
	out << stu.building_site << " ";
	out << stu.house_area << " ";
	out << stu.house_type << " ";
	out << stu.house_price << " ";
	out << stu.house_status << "\n";
	return out;
}
void house::get_house() {                                          //录入房屋信息
	system("cls");
	ofstream fout("house.txt", ios::app);
	if (!fout) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	cout << "请输入房屋编号:"; cin >> house_number; fout << house_number << " ";                             //输入房屋编号,并将数据录入文件
	cout << "请输入房屋地址:"; cin >> building_site; fout << building_site << " ";                            //输入房屋地址
	cout << "请输入房屋面积(m^2):"; cin >> house_area; fout << house_area << " ";                          //输入房屋面积
	cout << "请输入房屋户型:"; cin >> house_type; fout << house_type << " ";                               //输入房屋户型
	cout << "请输入房屋价格(元):"; cin >> house_price; fout << house_price << " ";                       //输入房屋价格
	cout << "请输入房屋的出租状态(Y/N):"; cin >> house_status; fout << house_status << "\n";              //输入房屋出租状态
	fout.close();                                                                                       
	cout << "添加成功!" << endl;
	system("pause");
}

void house::dis_house() {                                           //以编号排序输出-冒泡排序
	system("cls");
	ifstream fin("house.txt");
	if (!fin) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	cout << setw(10) << "房屋编号" << setw(25) << "房屋地址" << setw(10) << "房屋面积(m^2)" << setw(10) << "房屋户型" << setw(10) << "房屋价格(元)"<<setw(15)<<"状态(Y为未出售,N为出售)" << endl;
		house stu[105];
		int n = 0;
		while (fin >> stu[n].house_number >> stu[n].building_site >> stu[n].house_area >> stu[n].house_type >> stu[n].house_price >> stu[n].house_status) {
			n++;
	}
		house temp1;
	fin.close();
	for (int j = 0; j < n-1; j++) {
		for (int k = 0; k < n - j - 1; k++) {
			if (strcmp(stu[k].house_number,stu[k + 1].house_number)>0) {
				temp1 = stu[k];
				stu[k] = stu[k + 1];
				stu[k + 1] = temp1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << setw(10) << stu[i].house_number << setw(25) << stu[i].building_site << setw(10) << stu[i].house_area << setw(10) << stu[i].house_type << setw(10) << stu[i].house_price << setw(15) << stu[i].house_status << endl;
	}
	system("pause");
}

void house::delete_house() {                                   //删除房屋信息
	system("cls");
	cout << "请输入你要删除的房屋编号:";
	char temp[20];
	cin >> temp;
	house str[105];
	ifstream fin("house.txt");
	if (!fin) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	int n = 0;
	while (!fin.eof()) {
		fin >> str[n].house_number >> str[n].building_site >> str[n].house_area >> str[n].house_type >> str[n].house_price >> str[n].house_status;
		n++;
	}
	n = n - 1;                                //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
	fin.close();
	int k = 0;
	bool l = true;
	for (int i = 0; i < n; i++) {
		if (strcmp(str[i].house_number, temp)==0) {
			k = i;
			l = false;
			break;
		}
	}
	if (l) cout << "此编号的房屋不存在!删除失败!" << endl;
	else {
		ofstream fout("house.txt");
		if (!fout) {
			cout << "打开文件house.txt失败!" << endl;
			abort();
		}
		for (int i = k; i < n - 1; i++) {
			str[i] = str[i + 1];
		}
		for (int i = 0; i < n - 1; i++) {
			fout << str[i] << "\n";
		}
		cout << "删除成功!" << endl;
		fout.close();
	}
	system("pause");
}

void house::find_house() {                                               //查找房屋信息
	system("cls");
	cout << "请输入你想查找房屋的编号" << endl;
	char temp[20];
	cin >> temp;
	bool k = true;
	ifstream fin("house.txt");
	if (!fin) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	house stu[105];
	int n = 0;
	while (fin >> stu[n].house_number >> stu[n].building_site >> stu[n].house_area >> stu[n].house_type >> stu[n].house_price >> stu[n].house_status) {   //从文件提取信息
		n++;
	}
	fin.close();
	do {
		for (int i = 0; i < n; i++) {
			if (strcmp(stu[i].house_number, temp) == 0) {                          //判断信息是否存在,存在则输出该信息
				cout << setw(10) << "房屋编号" << setw(25) << "房屋地址" << setw(10) << "房屋面积(m^2)" << setw(10) << "房屋户型" << setw(10) << "房屋价格(元)" << setw(15) << "状态(Y为未出售,N为出售)" << endl;
				cout << setw(10) << stu[i].house_number << setw(25) << stu[i].building_site << setw(10) << stu[i].house_area << setw(10) << stu[i].house_type << setw(10) << stu[i].house_price << setw(15) << stu[i].house_status << endl;
				k = false;
				break;
			}
		}
		if (k) {
			cout << "该编号房屋不存在!请重新输入房屋编号:";
			cin >> temp;
		}
	} while (k);
	system("pause");
}

void house::amend_house() {                                                //修改房屋信息
	system("cls");
	cout << "请选择你要修改的房屋信息编号:";
	char temp[20];
	cin >> temp;
	ifstream fin("house.txt");
	if (!fin) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	house stu[105];
	int n = 0;
	while (fin >> stu[n].house_number >> stu[n].building_site >> stu[n].house_area >> stu[n].house_type >> stu[n].house_price >> stu[n].house_status) {
		n++;
	}
	fin.close();
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (strcmp(stu[i].house_number, temp) == 0) {
			k = i;
			break;
		}
	}
	cout << "你要修改的房屋信息为:" << endl;
	cout << setw(10) << "房屋编号" << setw(25) << "房屋地址" << setw(10) << "房屋面积(m^2)" << setw(10) << "房屋户型" << setw(10) << "房屋价格(元)" << setw(15) << "状态(Y为未出售,N为出售)" << endl;
	cout << setw(10) << stu[k].house_number << setw(25) << stu[k].building_site << setw(10) << stu[k].house_area << setw(10) << stu[k].house_type << setw(10) << stu[k].house_price << setw(15) << stu[k].house_status << endl;
	int ch;
	do {
		system("cls");
		cout << "1.房屋地点" << endl;
		cout << "2.房屋面积" << endl;
		cout << "3.房屋户型" << endl;
		cout << "4.房屋价格" << endl;
		cout << "5.房屋出租状态" << endl;
		cout << "0:返回" << endl;
	
		cin >> ch;
		string s;
		float a;
		switch (ch) {
		case 1:			
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].building_site = s;
			break;
		case 2:
			cout << "请输入你要修改的内容:";
			cin >> a;
			stu[k].house_area = a;
			break;
		case 3:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].house_type = s;
			break;
		case 4:
			cout << "请输入你要修改的内容:";
			cin >> a;
			stu[k].house_price = a;
			break;
		case 5:		
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].house_status = s;
			break;
		case 0:
			break;
		}
		cout << "修改成功!" << endl;
		system("pause");
	} while (ch);
	ofstream fout("house.txt");
	for (int i = 0; i < n - 1; i++) {
		fout << stu[i] << "\n";
	}
	fout.close();
	system("pause");
}

float house::amend_status(char *a) {                              //修改房屋状态
	ifstream fin("house.txt");
	if (!fin) {
		cout << "打开文件house.txt失败!" << endl;
		abort();
	}
	house stu[105];
	int n = 0;
	while (fin >> stu[n].house_number >> stu[n].building_site >> stu[n].house_area >> stu[n].house_type >> stu[n].house_price >> stu[n].house_status) {
		n++;
	}
	fin.close();
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (strcmp(stu[i].house_number, a) == 0) {
			k = i;
			break;
		}
	}
	stu[k].house_status = 'N';
	ofstream fout("house.txt");
	for (int i = 0; i < n; i++) {
		fout << stu[i] << "\n";
	}
	fout.close();
	return stu[k].house_price;
}

房主信息:管理房屋主人的信息

#pragma once
#include<iostream>
#include<string>
using namespace std;
class  house_owner {                               //房主信息类 
public:
	house_owner();
	house_owner(const house_owner& s);                      //拷贝构造函数
	void get_information();                         //录入房主信息
	void dis_information();                       //输出房主信息
	void delete_information();                    //删除房主信息
	void find_information();                        //信息查询
	void amend_information();                      //修改信息
	bool findh(string a, char* b,int c);             //用户登录查找
	friend ofstream& operator<<(ofstream& out, house_owner stu);
private:
	char house_owner_number[20];             //编号 
	string name;               //房主名 
	char password[20];         //密码 
	string sex;                //性别
	char phone[20];            //电话
	string address;            //家庭住址
};

房主的实现:

#include "house_owner.h"
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
house_owner::house_owner() {
    strcpy_s(house_owner_number, "0");
    name = '0';
    strcpy_s(password, "0");
    sex = '0';
    strcpy_s(phone, "0");
    address = '0';
}

house_owner::house_owner(const house_owner& s){                            //拷贝构造函数
    
    strcpy_s(house_owner_number,s.house_owner_number);             
    name=s.name;               
    strcpy_s(password, s.password);
    sex=s.sex;               
    strcpy_s(phone, s.phone);
    address=s.address;
}

ofstream& operator <<(ofstream& out, house_owner stu) {
    out << stu.house_owner_number << " ";
    out << stu.name << " ";
    out << stu.password << " ";
    out << stu.sex << " ";
    out << stu.phone << " ";
    out << stu.address << "\n";
    return out;
}

void house_owner::get_information() {                                       //输入房主信息类容,存储进文件
    system("cls");
    ofstream fout("house_owner.dat",ios::app);
    if (!fout) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    cout << "请输入房主信息:" << endl;
    cout << "请输入房主编号:"; cin >> house_owner_number; fout << house_owner_number << " ";
    cout << "请输入房主名:"; cin >> name; fout << name << " ";
    cout << "请输入用户密码:"; cin >> password; fout << password << " ";
    cout << "请输入用户性别:"; cin >> sex; fout << sex << " ";
    cout << "请输入用户电话号码:"; cin >> phone; fout << phone << " ";
    cout << "请输入家庭住址:"; cin >> address; fout << address << "\n";
    
    fout.close();
}

void house_owner::dis_information() {                                          //以编号从小到大进行输出房主信息-冒泡排序
    system("cls");
    cout << setw(10) << "房主编号" << setw(10) << "房主姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(15) << "家庭住址" << endl;
    ifstream fin("house_owner.dat");
    if (!fin) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    house_owner stu[105];
    int n = 0;
    while (fin >> stu[n].house_owner_number >> stu[n].name >> stu[n].password >> stu[n].sex >> stu[n].phone >> stu[n].address){             //eof()会多读一行导致数据出错
        n++;
    } 
    fin.close();
    house_owner temp1;
    for (int j = 0; j < n-1; j++) {
        for (int k = 0; k < n - j - 1; k++) {
            if (strcmp(stu[k].house_owner_number,stu[k + 1].house_owner_number)>0) {
                temp1 = stu[k];
                stu[k] = stu[k + 1];
                stu[k + 1] = temp1;
            }
        }
    }
    for(int i=0;i<n;i++)
    cout << setw(10) << stu[i].house_owner_number << setw(10) << stu[i].name << setw(10) << stu[i].sex << setw(15) << stu[i].phone << setw(15) << stu[i].address << endl;
}

void house_owner::delete_information(){                                    //删除房主信息
    system("cls");
    house_owner stu[105];
    ifstream fin("house_owner.dat");
    if (!fin) {
        cout << "打开house_owner.dat失败!" << endl;
        abort();
    }
    int n = 0;
    cout << "请输入你要删除的房主编号:";
    char temp[20];
    cin >> temp;
    while (!fin.eof()) {
        fin >> stu[n].house_owner_number >> stu[n].name >> stu[n].password >> stu[n].sex >> stu[n].phone >> stu[n].address;
        n++;
    }
    n = n - 1;                                          //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
    fin.close();
    bool l = true;
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (strcmp(stu[i].house_owner_number, temp)==0) {
            k = i;
            l = false;
            break;
        }
    }
    if (l) cout << "此编号的房主不存在!删除失败!" << endl;
    else {
        for (int i = k; i < n - 1; i++) {
            stu[i] = stu[i + 1];
        }
        ofstream fout("house_owner.dat");
        if (!fout) {
            cout << "打开文件house_owner.dat失败!" << endl;
            abort();
        }
        for (int i = 0; i < n - 1; i++) {
            fout << stu[i] << "\n";
        }
        cout << "删除成功!" << endl;
        fout.close();
    }
    system("pause");
}
 
void house_owner::find_information() {                                       //查找房主信息
    system("cls");
    cout << "请输入你想查找房主的编号" << endl;
    char temp[20];
    cin >> temp;
    bool k = true;
    ifstream fin("house_owner.dat");
    if (!fin) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    house_owner stu[105];
    int n = 0;
    while (fin >> stu[n].house_owner_number >> stu[n].name >> stu[n].password >> stu[n].sex >> stu[n].phone >> stu[n].address) {
        n++;
    }
    fin.close();
    do {
        for (int i = 0; i < n; i++) {
            if (strcmp(stu[i].house_owner_number, temp) == 0) {
                cout << setw(10) << "房主编号" << setw(10) << "房主姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(15) << "家庭住址" << endl;
                cout << setw(10) << stu[i].house_owner_number << setw(10) << stu[i].name << setw(10) << stu[i].sex << setw(15) << stu[i].phone << setw(15) << stu[i].address << endl;
                k = false;
                break;
            }
        }
        if (k) {
            cout << "该编号房主不存在!请重新输入房主编号:";
            cin >> temp;
        }
    } while (k);
    system("pause");
}

void house_owner::amend_information() {                                           //修改房主信息
    system("cls");
    cout << "请选择你要修改的房主信息编号:";
    char temp[20];
    cin >> temp;
    ifstream fin("house_owner.dat");
    if (!fin) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    house_owner stu[105];
    int n = 0;
    while (fin >> stu[n].house_owner_number >> stu[n].name >> stu[n].password >> stu[n].sex >> stu[n].phone >> stu[n].address) {
        n++;
    }
    fin.close();
    bool k = true;
    for (int i = 0; i < n; i++) {
        if (strcmp(stu[i].house_owner_number, temp) == 0) {
            k = false;
            break;
        }
    }
    if (k) { cout << "编号错误!" << endl; return; }
    cout << "你要修改的房主信息为:" << endl;
    cout << setw(10) << "房主编号" << setw(10) << "房主姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(15) << "家庭住址" << endl;
    cout << setw(10) << stu[k].house_owner_number << setw(10) << stu[k].name << setw(10) << stu[k].sex << setw(15) << stu[k].phone << setw(15) << stu[k].address << endl;
    int ch;
    do {
        cout << "1.电话" << endl;
        cout << "2.家庭住址" << endl;
        cout << "0:返回" << endl;
        cout << "请输入你的选择:";
        cin >> ch;
        char s[20];
        string a;
        while (ch > 2 || ch < 0) {
            cout << "请重新输入你的选择:";
            cin >> ch;
        }
        switch (ch) {
        case 1:
            cout << "请输入你要修改的内容:";
            cin >> s;
            strcpy_s(stu[k].phone, s);
            break;
        case 2:
            cout << "请输入你要修改的内容:";
            cin >> a;
            stu[k].address = a;
            break;
        }
        cout << "修改成功!" << endl;
        system("pause");
    } while (ch);
    ofstream fout("house_owner.dat");
    if (!fout) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    for (int i = 0; i < n - 1; i++) {
        fout << stu[i] << "\n";
    }
    fout.close();
}

bool house_owner::findh(string a, char* b,int c) {                                           //判断密码正误以及修改密码
    ifstream fin("house_owner.dat");
    if (!fin) {
        cout << "打开文件house_owner.dat失败!" << endl;
        abort();
    }
    house_owner stu[105];
    int n = 0;
    while (fin >> stu[n].house_owner_number >> stu[n].name >> stu[n].password >> stu[n].sex >> stu[n].phone >> stu[n].address) {
        n++;
    }
    fin.close();
    if (c) {                                                                 //修改密码
        for (int i = 0; i < n; i++) {
            if (stu[i].name==a) {
                strcpy_s(stu[i].password, b);
                ofstream fout("house_owner.dat");
                if (!fout) {
                    cout << "打开文件house_owner.dat失败!" << endl;
                    abort();
                }
                for (int j = 0; j < n; j++) {
                    fout << stu[j] << "\n";
                }
                fout.close();
                return true;
            }
        }
    }
    else {                                           //判断密码正误
        for (int i = 0; i < n; i++) {
            if (stu[i].name==a && strcmp(stu[i].password, b) == 0) {
                return true;
            }
        }
    }
    return false;
}

看房信息:存储有人想去实地看房的信息,预约等

#pragma once
#include<iostream>
#include<string>
using namespace std;
class look_house {                         //看房信息类
public:
	look_house();                           //构造函数
	void get_look();                         //看房信息录入
	void dis_look();                         //看房信息输出
	void delete_look();                      //看房信息删除
	void find_look();                        //信息查询
	void amend_look();                       //修改信息
	friend ofstream& operator <<(ofstream& out, look_house stu);
private:
	int Look_house_number;           //看房信息编号 
	string Look_house_time;                //看房日期
	string  Look_house_site;               //看房地点 
	string look_name;                   //看房人姓名
	string look_phone;                  //电话
};



看房信息的实现:

#include "look_house.h"
#include<iostream>
#include<algorithm>
#include<fstream>
#include<iomanip>
#include<string>
#include<cstring>
using namespace std;
look_house::look_house() {
	Look_house_number = 0;
	Look_house_site = '0';
	Look_house_time = '0';
}
ofstream& operator <<(ofstream& out, look_house stu) {
	out << stu.Look_house_number << " ";
	out << stu.Look_house_time << " ";
	out << stu.Look_house_site << "\n";
	return out;
}

void look_house::get_look() {                           //看房信息的录入
	ofstream fout("look_house.txt", ios::app);
	if (!fout) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	ifstream fin("look_house.txt");
	if (!fin) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	int n = 0;
	int sum = 0;
	look_house stu[105];
	while (fin >> stu[n].Look_house_number >> stu[n].Look_house_time >> stu[n].Look_house_site>>stu[n].look_name>>stu[n].look_phone) {
		sum = max(sum, stu[n].Look_house_number);
		n++;
	}
	
	Look_house_number = sum+1 ;
	                      fout << Look_house_number << " ";
	cout << "请输入看房的时间:"; cin >> Look_house_time; fout << Look_house_time << " ";
	cout << "请输入看房的地点:"; cin >> Look_house_site; fout << Look_house_site << " ";
	cout << "请输入你的姓名:"; cin >> look_name; fout << look_name << " ";
	cout << "请输入你的电话号码:"; cin >> look_phone; fout << look_phone << "\n";
	fout.close();
	cout << "录入成功!" << endl;
	system("pause");
}  

void look_house::dis_look() {
	system("cls");
	ifstream fin("look_house.txt");
	if (!fin) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	cout << setw(10) << "看房的编号" << setw(15) << "看房时间" << setw(15) << "看房地点" << setw(15) << "看房者的姓名" <<setw(15)<< "电话号码" << endl;
	look_house stu[105];
	int n = 0;
	while (fin >> stu[n].Look_house_number >> stu[n].Look_house_time >> stu[n].Look_house_site>>stu[n].look_name>>stu[n].look_phone) {
		n++;
	}
	fin.close();
	for (int j = 0; j < n-1; j++) {
		for (int k = 0; k < n - j-1 ; k++) {
			if (stu[k].Look_house_number>stu[k + 1].Look_house_number) {
				look_house temp1 = stu[k];
				stu[k] = stu[k + 1];
				stu[k + 1] = temp1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << setw(10) << stu[i].Look_house_number << setw(15) << stu[i].Look_house_time << setw(15) << stu[i].Look_house_site << setw(15) << stu[i].look_name <<setw(15) << stu[i].look_phone <<  endl;
	}
	system("pause");
}

void look_house::delete_look(){
	system("cls");
	cout << "请输入你要删除看房信息编号:";
	int temp;
	cin >> temp;
	look_house stu[105];
	ifstream fin("look_house.txt");
	if (!fin) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	int n = 0;
	while (!fin.eof()) {
		fin >> stu[n].Look_house_number >> stu[n].Look_house_time >> stu[n].Look_house_site >> stu[n].look_name >> stu[n].look_phone;
		n++;
	}
	n = n - 1;                                //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
	fin.close();
	bool l = true;
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (stu[i].Look_house_number==temp) {
			k = i;
			l = false;
			break;
		}
	}
	if (l) cout << "此编号的看房信息不存在!删除失败!" << endl;
	else {
		ofstream fout("look_house.txt");
		if (!fout) {
			cout << "打开文件look_house.txt失败!" << endl;
			abort();
		}
		for (int i = k; i < n - 1; i++) {
			stu[i] = stu[i + 1];
		}
		for (int i = 0; i < n - 1; i++) {
			fout << stu[i] << "\n";
		}
		cout << "删除成功!" << endl;
		fout.close();
	}
	system("pause");
	
}

void look_house::find_look() {
	system("cls");
	cout << "请输入你想查找看房的编号" << endl;
	int temp;
	cin >> temp;
	bool k = true;
	ifstream fin("look_house.txt");
	if (!fin) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	look_house stu[105];
	int n = 0;
	while (fin >> stu[n].Look_house_number >> stu[n].Look_house_time >> stu[n].Look_house_site >> stu[n].look_name >> stu[n].look_phone) {
		n++;
	}
	fin.close();
	do {
		for (int i = 0; i < n; i++) {
			if (stu[i].Look_house_number==temp) {
				cout << setw(10) << "看房的编号" << setw(15) << "看房时间" << setw(15) << "看房地点" << setw(15) << "看房者的姓名" << setw(15) << "电话号码" << endl;
				cout << setw(10) << stu[i].Look_house_number << setw(15) << stu[i].Look_house_time << setw(15) << stu[i].Look_house_site << setw(15) << stu[i].look_name << setw(15) << stu[i].look_phone << endl;
				k = false;
				break;
			}
		}
		if (k) {
			cout << "该编号看房信息不存在!请重新输入看房信息编号:";
			cin >> temp;
		}
	} while (k);
	system("pause");
}

void look_house::amend_look() {
	system("cls");
	cout << "请输入你想修改的看房信息编号" << endl;
	int temp;
	cin >> temp;
	ifstream fin("look_house.txt");
	if (!fin) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	look_house stu[105];
	int n = 0;
	while (fin >> stu[n].Look_house_number >> stu[n].Look_house_time >> stu[n].Look_house_site) {
		n++;
	}
	fin.close();
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (stu[i].Look_house_number==temp) {
			k = i;
			break;
		}
	}
	cout << "你要修改的看房信息为:" << endl;
	cout << setw(10) << "看房的编号" << setw(15) << "看房时间" << setw(15) << "看房地点" << setw(15) << "看房者的姓名" << setw(15) << "电话号码" << endl;
	cout << setw(10) << stu[k].Look_house_number << setw(15) << stu[k].Look_house_time << setw(15) << stu[k].Look_house_site << setw(15) << stu[k].look_name << setw(15) << stu[k].look_phone << endl;
	int ch;
	do {
		system("cls");
		cout << "1.看房时间" << endl;
		cout << "2.看房地点" << endl;
		cout << "4.电话号码" << endl;
		cout << "4.电话号码" << endl;
		cout << "0:返回" << endl;
		cin >> ch;
		string s;
		switch (ch) {
		case 1:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].Look_house_time = s;
			break;
		case 2:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].Look_house_site = s;
			break;
		case 3:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].look_name = s;
			break;
		case 4:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].look_phone = s;
			break;
		case 0:
			break;
		}
		cout << "修改成功!" << endl;
		system("pause");
	} while (ch);
	ofstream fout("look_house.txt");
	if (!fout) {
		cout << "打开文件look_house.txt失败!" << endl;
		abort();
	}
	for (int i = 0; i < n - 1; i++) {
		fout << stu[i] << "\n";
	}
	fout.close();
	system("pause");
}

员工信息:存储中介公司的员工信息

#pragma once
#include<iostream>
#include<string>
using namespace std;
class staff
{
public:
    friend ofstream& operator<<(ofstream& out, staff stu);         //重载插入运算符
	void get_staff();                                             //用于员工信息录入采集
	void dis_staff();                                             //用于员工信息输出
	void delete_staff();                                                //员工信息删除
	void find_staff();                                    //员工信息查询
	void amend_staff();                                     //修改信息
private:
	char staff_number[20];                   //编号
	string staff_name;                        //姓名
	string staff_sex;                          //性别
	string staff_phone;                        //电话
	string staff_address;                    //家庭住址
};


员工信息类的实现:

#include "staff.h"
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
ofstream& operator <<(ofstream& out, staff stu) {
    out << stu.staff_number << " ";
    out << stu.staff_name << " ";
    out << stu.staff_sex << " ";
    out << stu.staff_phone << " ";
    out << stu.staff_address << "\n";
    return out;
}

void staff::get_staff() {                                       //输入房主信息类容,存储进文件
    system("cls");
    ofstream fout("staff.txt", ios::app);
    if (!fout) {
        cout << "打开文件staff.txt失败!" << endl;
        abort();
    }
    cout << "请输入员工信息:" << endl;
    cout << "请输入员工编号:"; cin >> staff_number; fout << staff_number << " ";
    cout << "请输入员工姓名:"; cin >> staff_name; fout << staff_name << " ";
    cout << "请输入员工性别:"; cin >> staff_sex; fout << staff_sex << " ";
    cout << "请输入员工电话号码:"; cin >> staff_phone; fout << staff_phone << " ";
    cout << "请输入员工家庭住址:"; cin >> staff_address; fout << staff_address << "\n";
    cout << "录入成功!" << endl;
    fout.close();
    system("pause");
}

void staff::dis_staff() {                         //输出员工信息
	system("cls");
	ifstream fin("staff.txt");
	if (!fin) {
		cout << "打开文件staff.txt失败!" << endl;
		abort();
	}
	cout << setw(10) << "员工编号" << setw(10) << "员工姓名" << setw(10) << "员工性别" << setw(15) << "员工电话" << setw(15) << "家庭地址" << endl;
	staff stu[105];
	int n = 0;
	while (fin >> stu[n].staff_number>>stu[n].staff_name>>stu[n].staff_sex>>stu[n].staff_phone>>stu[n].staff_address) {
		n++;
	}
	fin.close();
	staff temp1;
	for (int j = 0; j < n; j++) {
		for (int k = 0; k < n - j - 1; k++) {
			if (strcmp(stu[k].staff_number,stu[k + 1].staff_number)>0) {
				 temp1 = stu[k];
				stu[k] = stu[k + 1];
				stu[k + 1] = temp1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << setw(10) << stu[i].staff_number << setw(10) << stu[i].staff_name << setw(10) << stu[i].staff_sex << setw(15) << stu[i].staff_phone << setw(15) << stu[i].staff_address << endl;
	}
	system("pause");
}

void staff::amend_staff() {                    //修改信息
    system("cls");
    cout << "请选择你要修改的员工信息编号:";
    char temp[20];
    cin >> temp;
    ifstream fin("staff.txt");
    if (!fin) {
        cout << "打开文件staff.txt失败!" << endl;
        abort();
    }
    staff stu[105];
    int n = 0;
    while (fin >> stu[n].staff_number >> stu[n].staff_name >> stu[n].staff_sex >> stu[n].staff_phone >> stu[n].staff_address) {
        n++;
    }
    fin.close();
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (strcmp(stu[i].staff_number, temp) == 0) {
            k = i;
            break;
        }
    }
    cout << "你要修改的员工信息为:" << endl;
    cout << setw(10) << "员工编号" << setw(10) << "员工姓名" << setw(10) << "员工性别" << setw(15) << "员工电话" << setw(15) << "家庭地址" << endl;
    cout << setw(10) << stu[k].staff_number << setw(10) << stu[k].staff_name << setw(10) << stu[k].staff_sex << setw(15) << stu[k].staff_phone << setw(15) << stu[k].staff_address << endl;
    int ch;
    do {
        system("cls");
        cout << setw(10) << "1.电话" << endl;
        cout << setw(10) << "2.家庭住址" << endl;
        cout << setw(10) << "0:返回" << endl;
        cout << setw(10) << "请输入你的选择:";
        cin >> ch;
        string a;
        switch (ch) {
        case 1:
            cout << "请输入你要修改的内容:";
            cin >> a;
            stu[k].staff_phone = a;
            break;
        case 2:
            cout << "请输入你要修改的内容:";
            cin >> a;
            stu[k].staff_address = a;
            break;
        case 0:
            break;
        }
        cout << "修改成功!" << endl;
        system("pause");
    } while (ch);
    ofstream fout("staff.txt");
    if (!fout) {
        cout << "打开文件staff.txt失败!" << endl;
        abort();
    }
    for (int i = 0; i < n - 1; i++) {
        fout << stu[i] << "\n";
    }
    fout.close();
    system("pause");
}

void staff::delete_staff() {                                     //删除员工信息
    system("cls");
    staff stu[105];
    ifstream fin("staff.txt");
    if (!fin) {
        cout << "打开staff.txt失败!" << endl;
        abort();
    }
    int n = 0;
    cout << "请输入你要删除的员工编号:";
    char temp[20];
    cin >> temp;
    while (!fin.eof()) {
        fin >> stu[n].staff_number >> stu[n].staff_name >> stu[n].staff_sex >> stu[n].staff_phone >> stu[n].staff_address;
        n++;
    }
    n = n - 1;                                          //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
    fin.close();
    bool l = true;
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (strcmp(stu[i].staff_number, temp) == 0) {
            k = i;
            l = false;
            break;
        }
    }
    if (l) cout << "此编号的员工不存在!删除失败!" << endl;
    else {
        for (int i = k; i < n - 1; i++) {
            stu[i] = stu[i + 1];
        }
        ofstream fout("staff.txt");
        if (!fout) {
            cout << "打开文件staff.txt失败!" << endl;
            abort();
        }
        for (int i = 0; i < n - 1; i++) {
            fout << stu[i] << "\n";
        }
        cout << "删除成功!" << endl;
        fout.close();
    }
    system("pause");
}

void staff::find_staff() {                 //查找员工信息
    system("cls");
    cout << "请输入你想查找员工的编号" << endl;
    char temp[20];
    cin >> temp;
    bool k = true;
    ifstream fin("staff.txt");
    if (!fin) {
        cout << "打开文件staff.txt失败!" << endl;
        abort();
    }
    staff stu[105];
    int n = 0;
    while (fin >> stu[n].staff_number >> stu[n].staff_name>> stu[n].staff_sex >> stu[n].staff_phone >> stu[n].staff_address) {
        n++;
    }
    fin.close();
    do {
        for (int i = 0; i < n; i++) {
            if (strcmp(stu[i].staff_number, temp) == 0) {
                cout << setw(10) << "员工编号" << setw(10) << "员工姓名" << setw(10) << "员工性别" << setw(15) << "员工电话" << setw(15) << "家庭地址" << endl;
                cout << setw(10) << stu[i].staff_number << setw(10) << stu[i].staff_name << setw(10) << stu[i].staff_sex << setw(15) << stu[i].staff_phone << setw(15) << stu[i].staff_address << endl;
                k = false;
                break;
            }
        }
        if (k) {
            cout << "该编号员工不存在!请重新输入房主编号:";
            cin >> temp;
        }
    } while (k);
    system("pause");
}

租房者的信息类:租房者想要租房等功能的实现

#pragma once
#include<iostream>
#include<string>
using namespace std;                          //租房者类
class tenant {
public:
	tenant();
	void get_tenant();                         //租房者的信息录入
	void dis_tenant();                         //租房者的信息输出
	void delete_tenant();                      //租房者的信息删除
	void find_tenant();                        //信息查询
	void amend_tenant();                       //修改信息
	friend ofstream& operator <<(ofstream& out, tenant stu);
	bool findt(string a, char* b,int c);             //用户登录查找
		
private:
	char tenant_number[20];            //租房者编号 
	string tenant_name;                //租房者姓名 
	char tenant_password[20];          //租房者密码 
	string tenant_sex;                 //租房者性别 
	char tenant_phone[20];             //租房者电话号码 
	string profession;                 //租房者职业 
};

租房者的实现

#include "tenant.h"
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cstring>
using namespace std;
tenant::tenant() {
	strcpy_s(tenant_number, "0");
	tenant_name = '0';
	strcpy_s(tenant_password, "0");
	tenant_sex = '0';
	strcpy_s(tenant_phone, "0");
	profession = '0';
}

ofstream& operator <<(ofstream& out, tenant stu) {
	out << stu.tenant_number << " ";
	out << stu.tenant_name << " ";
	out << stu.tenant_password << " ";
	out << stu.tenant_sex << " ";
	out << stu.tenant_phone << " ";
	out << stu.profession << "\n";
	return out;
}

void tenant::get_tenant() {                                             //录入信息
	
	ofstream fout("tenant.txt", ios::app);
	if (!fout) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	cout << "请输入租房者编号:"; cin >> tenant_number; fout << tenant_number << " ";
	cout << "请输入租房者姓名:"; cin >> tenant_name; fout << tenant_name << " ";
	cout << "请输入密码:"; cin >> tenant_password; fout << tenant_password << " ";
	cout << "请输入性别:"; cin >> tenant_sex; fout << tenant_sex << " ";
	cout << "请输入电话:"; cin >> tenant_phone; fout << tenant_phone << " ";
	cout << "请输入工作职业:"; cin >> profession; fout << profession << "\n";
	fout.close();
	cout << "录入成功!" << endl;
	system("pause");
}

void tenant::dis_tenant() {                                                   //输出信息
	ifstream fin("tenant.txt");
	if (!fin) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	cout << setw(10) << "租房者编号" << setw(10) << "姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(10) << "工作职业" << endl;
	tenant stu[205];
	int n = 0;
	while (fin >> stu[n].tenant_number >> stu[n].tenant_name >> stu[n].tenant_password >> stu[n].tenant_sex >> stu[n].tenant_phone >> stu[n].profession) {
		n++;
	}
	fin.close();
	for (int j = 0; j < n; j++) {
		for (int k = 0; k < n - j - 1; k++) {
			if (strcmp(stu[k].tenant_number,stu[k + 1].tenant_number)>0) {
				tenant temp1 = stu[k];
				stu[k] = stu[k + 1];
				stu[k + 1] = temp1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << setw(10) << stu[i].tenant_number << setw(10) << stu[i].tenant_name << setw(10) << stu[i].tenant_sex << setw(15) << stu[i].tenant_phone << setw(10) << stu[i].profession << endl;
	}
	system("pause");
}

void tenant::delete_tenant() {                                          //删除信息

	cout << "请输入你要删除的租房者编号:";
	char temp[20];
	cin >> temp;
	tenant str[205];
	ifstream fin("tenant.txt");
	if (!fin) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	int n = 0;
	while (!fin.eof()) {
		fin >> str[n].tenant_number >> str[n].tenant_name >> str[n].tenant_password >> str[n].tenant_sex >> str[n].tenant_phone >> str[n].profession;
		n++;
	}
	n = n - 1;                                //eof()到文件末尾会多循环一次来判断文件末尾,所以n多加了一次,这里减去
	fin.close();
	bool l = true;
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (strcmp(str[i].tenant_number, temp) == 0) {
			k = i;
			l = false;
			break;
		}
	}
	if (l) cout << "此编号的租房者不存在!删除失败!" << endl;
	else {
		ofstream fout("tenant.txt");
		if (!fout) {
			cout << "打开文件tenant.txt失败!" << endl;
			abort();
		}
		for (int i = k; i < n - 1; i++) {
			str[i] = str[i + 1];
		}
		for (int i = 0; i < n - 1; i++) {
			fout << str[i] << "\n";
		}
		cout << "删除成功!" << endl;
		fout.close();
	}
	system("pause");
	
}

void tenant::find_tenant() {                                              //查找信息
	system("cls"); 
	cout << "请输入你想查找租房者的编号" << endl;
	char temp[20];
	cin >> temp;
	bool k = true;
	ifstream fin("tenant.txt");
	if (!fin) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	tenant stu[205];
	int n = 0;
	while (fin >> stu[n].tenant_number >> stu[n].tenant_name >> stu[n].tenant_password >> stu[n].tenant_sex >> stu[n].tenant_phone >> stu[n].profession) {
		n++;
	}
	fin.close();
	do {
		for (int i = 0; i < n; i++) {
			if (strcmp(stu[i].tenant_number, temp) == 0) {
				cout << setw(10) << "租房者编号" << setw(10) << "姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(10) << "工作职业" << endl;
				cout << setw(10) << stu[i].tenant_number << setw(10) << stu[i].tenant_name << setw(10) << stu[i].tenant_sex << setw(15) << stu[i].tenant_phone << setw(10) << stu[i].profession << endl;
				k = false;
				break;
			}
		}
		if (k) {
			cout << "该编号租房者不存在!请重新输入租房者编号:";
			cin >> temp;
		}
	} while (k);
	system("pause");
}

void tenant::amend_tenant() {                                            //修改信息
	cout << "请输入你想修改的租房者编号" << endl;
	char temp[20];
	cin >> temp;
	ifstream fin("tenant.txt");
	if (!fin) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	tenant stu[205];
	int n = 0;
	while (fin >> stu[n].tenant_number >> stu[n].tenant_name >> stu[n].tenant_password >> stu[n].tenant_sex >> stu[n].tenant_phone >> stu[n].profession) {
		n++;
	}
	fin.close();
	bool k = true;
	for (int i = 0; i < n; i++) {
		if (strcmp(stu[i].tenant_number, temp) == 0) {
			k = false;
			break;
		}
	}
	if (k) { cout << "编号错误!" << endl; return; }
	cout << "你要修改的租房者信息为:" << endl;
	cout << setw(10) << "租房者编号" << setw(10) << "姓名" << setw(10) << "性别" << setw(15) << "电话号码" << setw(10) << "工作职业" << endl;
	cout << setw(10) << stu[k].tenant_number << setw(10) << stu[k].tenant_name << setw(10) << stu[k].tenant_sex << setw(15) << stu[k].tenant_phone << setw(10) << stu[k].profession << endl;
	int ch;
	do {
		cout << "1.电话号码" << endl;
		cout << "2.工作职业" << endl;
		cout << "0:返回" << endl;
		cout << "请输入你的选择:";
		cin >> ch;
		string s;
		while (ch > 2 || ch < 0) {
			cout << "请重新输入您的选择:";
			cin >> ch;
		}
		char a[20];
		switch (ch) {
		case 1:
			cout << "请输入你要修改的内容:";
			cin >> a;
			strcpy_s(stu[k].tenant_phone,a);
			break;
		case 2:
			cout << "请输入你要修改的内容:";
			cin >> s;
			stu[k].profession = s;
			break;
		}
		cout << "修改成功!" << endl;
	} while (ch);
	ofstream fout("tenant.txt");
	if (!fout) {
		cout << "文件tenant.txt打开失败!" << endl;
		abort();
	}
	for (int i = 0; i < n - 1; i++) {
		fout << stu[i] << "\n";
	}
	fout.close();
}

bool tenant::findt(string a, char* b,int c) {                              //判读学号,密码正误以及修改密码
	ifstream fin("tenant.txt");
	if (!fin) {
		cout << "打开文件tenant.txt失败!" << endl;
		abort();
	}
	tenant stu[105];
	int n = 0;
	while (fin >> stu[n].tenant_number >> stu[n].tenant_name >> stu[n].tenant_password >> stu[n].tenant_sex >> stu[n].tenant_phone >> stu[n].profession) {
		n++;
	}
	fin.close();
	int k = 0;
	
	if (c) {                                                           //修改密码
		for (int i = 0; i < n; i++) {
			if (stu[i].tenant_name == a ){
				strcpy_s(stu[i].tenant_password, b);
				ofstream fout("tenant.txt");
				if (!fout) {
					cout << "打开文件tenant.txt失败!" << endl;
					abort();
				}
				for (int j = 0; j < n; j++) {
					fout << stu[j] << "\n";
				}
				fout.close();
				return true;
			}
		}
	}
	else {                                                                  //判读密码正误
		for (int i = 0; i < n; i++) {
			if (stu[i].tenant_name==a && strcmp(stu[i].tenant_password, b) == 0) {
				return true;
			}
		}
	}
	return false;
}

至此全部功能完成

在这里插入图片描述

总结

因为完成了就放在一旁了,结果后面想起了想改的时候,忘了咋写的了,那个信息序号的排序可能有点问题,各位哥哥们可以自己写一下

  • 10
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值