简易看房加权评估案例C++

  • Post author:
  • Post category:其他


最近偶尔关注房子的事情,为了方便对大量房产信息制定最符合个人需求的评估,所以本人决定写个小东西出来,于是今天就着手了。本人看房经验有限,加权系数仅根据个人感官给定,总和为100。一共综合考虑了10个影响因素,最后对其加权求均值计算出结果。采用类的方法进行编写,当然完全可以使用数组,但是为了定义一个对象更加方便,且易于修改,本人采用类进行编写。由于涉及权益,文中不给出详细的盘或开发商的名字,也不给予城市地名等信息。

1.距离 2.首付月供 3.生活配置 4.教育医疗 5.装修程度 6.建造程度交付时间 7.物业 8.布局朝向大小 9.绿化 10.楼层

加权系数分别为:14,15,12,13,10,15,5,8,5,3

/*
对多个房进行一次性综合评分
author:@Babysen
 */

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <map>
using namespace std;

class home
{ //考虑十个因素,并对其进行加权,总分100分
private:
    int m_distance;      //距离(通勤)14
    int m_down_payments; //首付与月供15
    int m_living;        //生活配置12
    int m_edu_medical;   //教育医疗13
    int m_renovation;    //装修程度10
    int m_time;          //目前所售盘盖的建造程度,交房时间15
    int m_property;      //物业质量5
    int m_house_type;    //房间布局朝向面积8
    int m_environment;   //绿化5
    int m_floor;         //楼层3
public:
    home();
    home(int distance, int down_payments, int living, int edu_medical, int renovation, int time, int property, int house_type, int environment, int floor)
    {
        m_distance = distance;
        m_down_payments = down_payments;
        m_living = living;
        m_edu_medical = edu_medical;
        m_renovation = renovation;
        m_time = time;
        m_property = property;
        m_house_type = house_type;
        m_environment = environment;
        m_floor = floor;
    };

    int getdis() { return m_distance; }
    int getdown() { return m_down_payments; }
    int getapp() { return m_living; }
    int getedu() { return m_edu_medical; }
    int getmed() { return m_renovation; }
    int gettime() { return m_time; }
    int getpro() { return m_property; }
    int gethty() { return m_house_type; }
    int getenvi() { return m_environment; }
    int getfloor() { return m_floor; }

    double sum(home &h);   //求和函数
    double Mean(home &hm); //求均值
    void showmenu();       //菜单函数
    void test(home &ht);   //测试
    // map<string, house> m_house; //这是一个队组,

    //运算符重载,友元函数
    friend ostream &operator<<(ostream &cout, home hh);
};

//设施一个静态全局变量
static int i = 0;

//求和函数
double home::sum(home &h)
{
    return 14 * h.getdis() + 15 * h.getdown() + 12 * h.getapp() + 13 * h.getedu() + 10 * h.getmed() + 15 * h.gettime() +
           5 * h.getpro() + 8 * h.gethty() + 5 * h.getenvi() + 3 * h.getfloor();
}

//求均值函数
double home::Mean(home &hm)
{
    return sum(hm) / (sizeof(hm) / sizeof(int));
}

//菜单函数
void home::showmenu()
{
    cout << "|---------------------------------------------------------|" << endl;
    cout << "|   1.距离 2.首付月供 3.生活配置 4.教育医疗 5.装修程度    |" << endl;
    cout << "| 6.建造程度交付时间 7.物业 8.布局朝向大小 9.绿化 10.楼层 |" << endl;
    cout << "|---------------------------------------------------------|" << endl;
}

//<<运算符重载
ostream &operator<<(ostream &cout, home hh)
{
    string nameseed[13] = {"枫",
                           "高区",
                           "府",
                           "华",
                           "金府",
                           "隆",
                           "清晖",
                           "万星",
                           "香",
                           "雨华",
                           "景清",
                           "山",
                           "金湾"};
    cout << nameseed[i];
    i++;
    return cout;
}

//测试打包函数
void home::test(home &ht)
{
    pair<home, double> pair1 = make_pair(ht, ht.Mean(ht));
    ht.sum(ht);
    ht.Mean(ht);
    cout << pair1.first << "的得分为:" << pair1.second << endl;
}

//主函数
int main()
{
    //数据写入文件
    ofstream ofs("houseview.csv", ios::trunc); //输出结果存储在statis文件中
    if (!ofs)
    {
        cerr << "open err!" << endl;
        exit(1);
    }
    // 1.距离 2.首付月供 3.生活配置 4.教育医疗 5.装修程度 6.建造程度交付时间 7.物业 8.布局朝向大小 9.绿化 10.楼层

    //创建一个gx对象,分别赋予它们各参数的值
    home gx(8, 8, 10, 9, 8, 7, 8, 7, 7, 6);
    gx.showmenu();
    gx.test(gx);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << gx.Mean(gx) << endl;

    home yt(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt.test(yt);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt.Mean(yt) << endl;

    home yt1(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt1.test(yt);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt1.Mean(yt1) << endl;

    home yt2(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt2.test(yt2);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt2.Mean(yt2) << endl;

    home yt3(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt3.test(yt3);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt3.Mean(yt3) << endl;

    home yt4(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt4.test(yt4);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt4.Mean(yt4) << endl;

    home yt5(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt5.test(yt5);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt5.Mean(yt5) << endl;

    home yt6(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt6.test(yt6);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt6.Mean(yt6) << endl;

    home yt7(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt7.test(yt7);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt7.Mean(yt7) << endl;

    home yt8(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt8.test(yt8);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt8.Mean(yt8) << endl;

    home yt9(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt9.test(yt9);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt9.Mean(yt9) << endl;

    home yt10(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt10.test(yt10);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt10.Mean(yt10) << endl;

    home yt11(8, 3, 10, 9, 8, 7, 8, 9, 7, 2);
    yt11.test(yt11);
    // ofs << "scores model" << endl;
    ofs << setprecision(3) << yt11.Mean(yt11) << endl;

    ofs.close();
    cout << "end!" << endl;
    system("pause");
    return 0;
}



版权声明:本文为m0_56574701原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。