- 房屋中介公司需要对日常工作中涉及到的房屋、房主和租房顾客等各类数据进行有效地管理,以实现业务的自动化,提高运行效率的同时也能够降低人力成本。本设计主要针对房屋中介公司建立一个简单应用系统。
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;
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;
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){
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;
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;
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;
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;
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;
}
至此全部功能完成

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