1.02

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
static int num = 0, boy = 0, girl = 0, dangyuan = 0;
static int adultnum = 0, childnum = 0, studentnum = 0;
/*人员类*/
class People
{
public:
    string name;    //姓名
    string gender;  //性别
    int birthday;   //出生日期 格式:20010822
    string nativePlace; //籍贯
    string national; //民族
    string IDnumber; //身份证号
    int roomNum;    //门牌号 格式:4305 (代表4号楼305室)
	string political; //政治面貌

public:
    People()
    {
        name = "NULL";
        gender = "NULL";
        birthday = 0;
        nativePlace = "NULL";
        national = "NULL";
        IDnumber = "NULL";
        roomNum = 0;
		political = "NULL";
    }
    People(string _name, string _gender, int _birthday, string _nativePlace, string _national, string _IDnumber, int _roomNum, string _political)
    {
        name = _name;
        gender = _gender;
        birthday = _birthday;
        nativePlace = _nativePlace;
        national = _national;
        IDnumber = _IDnumber;
        roomNum = _roomNum;
		political = _political;
    }
    People(const People &t)
    {
        name = t.name;
        gender = t.gender;
        birthday = t.birthday;
        nativePlace = t.nativePlace;
        national = t.national;
        IDnumber = t.IDnumber;
        roomNum = t.roomNum;
		political = t.political;
    }
    ~People(){}

    virtual void showInfo()  //虚函数 - 打印信息
    {
        cout << "姓名:    " << name << endl;
        cout << "性别:    " << gender << endl;
        cout << "出生日期:" << birthday/10000 << "年" << birthday/100%100 << "月" << birthday%100 << "日" << endl;
        cout << "籍贯:    " << nativePlace << endl;
        cout << "民族:    " << national << endl;
        cout << "身份证号:" << IDnumber << endl;
        cout << "门牌号:  " << roomNum/1000 << "号楼" << roomNum%1000 << "室" << endl;
		cout << "政治面貌:" << political << endl;
        cout << endl;
    }

    //修改信息
    virtual void reset_name() 
    {
        string temp;
        cout << "请输入修改后姓名:" << endl;
        cin >> temp;
        this->name = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_gender()
    {
        string temp;
        cout << "请输入修改后性别:" << endl;
        cin >> temp;
        this->gender = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_birthday()
    {
        int temp;
        cout << "请输入修改后出生日期:" << endl;
        cin >> temp;
        this->birthday = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_nativePlace()
    {
        int temp;
        cout << "请输入修改后籍贯:" << endl;
        cin >> temp;
        this->nativePlace = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_national()
    {
        string temp;
        cout << "请输入修改后民族:" << endl;
        cin >> temp;
        this->national = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_IDnumber()
    {
        string temp;
        cout << "请输入修改后身份证号:" << endl;
        cin >> temp;
        this->IDnumber = temp;
        cout << "[修改成功]" << endl << endl;
    }
    virtual void reset_roomNum()
    {
        int temp;
        cout << "请输入修改后门牌号:" << endl;
        cin >> temp;
        this->roomNum = temp;
        cout << "[修改成功]" << endl << endl;
    }
	virtual void reset_political()
	{
		int temp;
        cout << "请输入修改后政治面貌:" << endl;
        cin >> temp;
        this->political = temp;
        cout << "[修改成功]" << endl << endl;
	}

    
};

/*---------------------------------------------------*/

//成人类
class Adult : public People  //继承
{
public:
    string edu;      //学历
    string work;     //工作
    string companyAddress; //公司地址
    int salary;      //年收入
    string phonenum; //电话
    string marriage; //婚姻情况 格式:<未婚.已婚.离异.再婚>

public:
    Adult() : People()
    {
        edu = "NULL";
        work = "NULL";
        companyAddress = "NULL";
        salary = 0;
        phonenum = "0";
        marriage = "NULL";
    }

    Adult(string _name, string _gender, int _birthday, string _nativePlace, string _national, string _IDnumber, int _roomNum, string _political, string _edu, string _work, string _companyAddress, int _salary, string _phonenum, string _marriage)
     : People(_name, _gender, _birthday, _nativePlace, _national, _IDnumber, _roomNum, _political)
    {
        edu = _edu;
        work = _work;
        companyAddress = _companyAddress;
        salary = _salary;
        phonenum = _phonenum;
        marriage = _marriage;
    }

    Adult(const Adult &t) : People(t)
    {
        this->edu = t.edu;
        this->work = t.work;
        this->companyAddress = t.companyAddress;
        this->salary = t.salary;
        this->phonenum = t.phonenum;
        this->marriage = t.marriage;
    }
    ~Adult(){}
	int getsalary(){
		return salary;
	}
    void showInfo() //打印"成人类"信息
    {
        cout << "姓名:    " << name << endl;
        cout << "性别:    " << gender << endl;
        cout << "出生日期:" << birthday/10000 << "年" << birthday/100%100 << "月" << birthday%100 << "日" << endl;
        cout << "籍贯:    " << nativePlace << endl;
        cout << "民族:    " << national << endl;
        cout << "身份证号:" << IDnumber << endl;
        cout << "门牌号:  " << roomNum/1000 << "号楼" << roomNum%1000 << "室" << endl;
		cout << "政治面貌:" << political << endl;

        cout << "学历:    " << edu << endl;
        cout << "工作:    " << work << endl;
        cout << "公司地址:" << companyAddress << endl;
        cout << "年收入:  " << salary << "元" << endl;
        cout << "电话:    " << phonenum << endl;
        cout << "婚姻情况:" << marriage << endl;
        cout << endl;
    }

    //修改信息
    void reset_name() 
    {
        string temp;
        cout << "请输入修改后姓名:" << endl;
        cin >> temp;
        this->name = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_gender()
    {
        string temp;
        cout << "请输入修改后性别:" << endl;
        cin >> temp;
        this->gender = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_birthday()
    {
        int temp;
        cout << "请输入修改后出生日期:" << endl;
        cin >> temp;
        this->birthday = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_nativePlace()
    {
        int temp;
        cout << "请输入修改后籍贯:" << endl;
        cin >> temp;
        this->nativePlace = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_national()
    {
        string temp;
        cout << "请输入修改后民族:" << endl;
        cin >> temp;
        this->national = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_IDnumber()
    {
        string temp;
        cout << "请输入修改后身份证号:" << endl;
        cin >> temp;
        this->IDnumber = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_roomNum()
    {
        int temp;
        cout << "请输入修改后门牌号:" << endl;
        cin >> temp;
        this->roomNum = temp;
        cout << "[修改成功]" << endl << endl;
    }
	void reset_political()
	{
		int temp;
        cout << "请输入修改后政治面貌:" << endl;
        cin >> temp;
        this->political = temp;
        cout << "[修改成功]" << endl << endl;
	}
    void reset_edu() //修改成人类信息
    {
        string temp;
        cout << "请输入修改后学历:" << endl;
        cin >> temp;
        this->edu = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_work()
    {
        string temp;
        cout << "请输入修改后工作:" << endl;
        cin >> temp;
        this->work = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_companyAddress()
    {
        string temp;
        cout << "请输入修改后公司地址:" << endl;
        cin >> temp;
        this->companyAddress = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_salary()
    {
        int temp;
        cout << "请输入修改后年收入:" << endl;
        cin >> temp;
        this->salary = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_phonenum()
    {
        string temp;
        cout << "请输入修改后电话:" << endl;
        cin >> temp;
        this->phonenum = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_marriage()
    {
        string temp;
        cout << "请输入修改后婚姻情况:" << endl;
        cin >> temp;
        this->marriage = temp;
        cout << "[修改成功]" << endl << endl;
    }

};
//----------------------------------- 
//幼儿类 
class Child:public People{
public:
    Child() : People(){}
    Child(string _name, string _gender, int _birthday, string _nativePlace, string _national, string _IDnumber, int _roomNum,string _political)
     : People(_name, _gender, _birthday, _nativePlace, _national, _IDnumber, _roomNum, _political)
    {

    }
    Child(const Child &t) : People(t)
    {

    }
    ~Child(){}

    void showInfo() //打印"幼儿类"信息
    {
        cout << "姓名:    " << name << endl;
        cout << "性别:    " << gender << endl;
        cout << "出生日期:" << birthday/10000 << "年" << birthday/100%100 << "月" << birthday%100 << "日" << endl;
        cout << "籍贯:    " << nativePlace << endl;
        cout << "民族:    " << national << endl;
        cout << "身份证号:" << IDnumber << endl;
        cout << "门牌号:  " << roomNum/1000 << "号楼" << roomNum%1000 << "室" << endl;
        cout << "政治面貌:" << political <<endl;
        cout << endl;
    }
    //修改信息
    void reset_name() 
    {
        string temp;
        cout << "请输入修改后姓名:" << endl;
        cin >> temp;
        this->name = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_gender()
    {
        string temp;
        cout << "请输入修改后性别:" << endl;
        cin >> temp;
        this->gender = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_birthday()
    {
        int temp;
        cout << "请输入修改后出生日期:" << endl;
        cin >> temp;
        this->birthday = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_nativePlace()
    {
        int temp;
        cout << "请输入修改后籍贯:" << endl;
        cin >> temp;
        this->nativePlace = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_national()
    {
        string temp;
        cout << "请输入修改后民族:" << endl;
        cin >> temp;
        this->national = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_IDnumber()
    {
        string temp;
        cout << "请输入修改后身份证号:" << endl;
        cin >> temp;
        this->IDnumber = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_roomNum()
    {
        int temp;
        cout << "请输入修改后门牌号:" << endl;
        cin >> temp;
        this->roomNum = temp;
        cout << "[修改成功]" << endl << endl;
    }  
};

/*---------------------------------------------------*/

 //学生类
class Student : public People //继承
{
public:
    string school;  //学校
    string grade;   //年级

public:
    Student() : People()
    {
        school = "NULL";
        grade = "NULL";
    }
    Student(string _name, string _gender, int _birthday, string _nativePlace, string _national, string _IDnumber, int _roomNum, string _political, string _school, string _grade)
     : People(_name, _gender, _birthday, _nativePlace, _national, _IDnumber, _roomNum, _political)
    {
        school = _school;
        grade = _grade;
    }
    Student(const Student &t) : People(t)
    {
        school = t.school;
        grade = t.grade;
    }
    ~Student(){}

    void showInfo() //打印"学生类"信息
    {
        cout << "姓名:    " << name << endl;
        cout << "性别:    " << gender << endl;
        cout << "出生日期:" << birthday/10000 << "年" << birthday/100%100 << "月" << birthday%100 << "日" << endl;
        cout << "籍贯:    " << nativePlace << endl;
        cout << "民族:    " << national << endl;
        cout << "身份证号:" << IDnumber << endl;
        cout << "门牌号:  " << roomNum/1000 << "号楼" << roomNum%1000 << "室" << endl;
		cout << "政治面貌:" << political << endl;

        cout << "学校:    " << school << endl;
        cout << "年级:    " << grade << endl;
        cout << endl;
    }


    //修改信息
    void reset_name() 
    {
        string temp;
        cout << "请输入修改后姓名:" << endl;
        cin >> temp;
        this->name = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_gender()
    {
        string temp;
        cout << "请输入修改后性别:" << endl;
        cin >> temp;
        this->gender = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_birthday()
    {
        int temp;
        cout << "请输入修改后出生日期:" << endl;
        cin >> temp;
        this->birthday = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_nativePlace()
    {
        int temp;
        cout << "请输入修改后籍贯:" << endl;
        cin >> temp;
        this->nativePlace = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_national()
    {
        string temp;
        cout << "请输入修改后民族:" << endl;
        cin >> temp;
        this->national = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_IDnumber()
    {
        string temp;
        cout << "请输入修改后身份证号:" << endl;
        cin >> temp;
        this->IDnumber = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_roomNum()
    {
        int temp;
        cout << "请输入修改后门牌号:" << endl;
        cin >> temp;
        this->roomNum = temp;
        cout << "[修改成功]" << endl << endl;
    } 
	void reset_political()
	{
		string temp;
        cout << "请输入修改后政治面貌:" << endl;
        cin >> temp;
        this->political = temp;
        cout << "[修改成功]" << endl << endl;
	}
    void reset_school()    //修改"学生类"信息
    {
        string temp;
        cout << "请输入修改后学校:" << endl;
        cin >> temp;
        this->school = temp;
        cout << "[修改成功]" << endl << endl;
    }
    void reset_grade()
    {
        string temp;
        cout << "请输入修改后年级:" << endl;
        cin >> temp;
        this->grade = temp;
        cout << "[修改成功]" << endl << endl;
    }
    
};
//----------------------\
//家庭类 
class Family{
	public:
		vector<Adult> ad;//成人数组 
    	vector<Student> st;//学生数组 
    	vector<Child>ch;
		int ppnum=0,fincome=0;//人口数和家庭年收入 	
		//定义三个构造函数 先开户 再入户 
        Family(){}
		Family( Child& cc):ch(1,cc){
			ppnum += 1;
		}
		Family( Adult& aa):ad(1,aa){
			ppnum += 1;
			fincome += aa.getsalary();//成人时加上他的收入到这个的家庭总收入中 
		}
		Family(Student& ss):st(1,ss){
			ppnum += 1;
		}
		Family(const Family& f){//拷贝构造函数 
			ad = f.ad;
			st = f.st;
			ppnum = f.ppnum ;
			fincome = f.fincome ; 
		}				
		void showinfo(){
			cout<<"家庭人数"<<ppnum<<endl;
			cout<<"成人数"<<ad.size()<<endl;
			cout<<"未成年人数"<<st.size()+ch.size()<<endl;
			cout<<"家庭年收入"<<fincome<<endl;
			 
		}
}; 

void Input_Population_Info(); //函数申明
void Put_Population_number();
void Get_sex_Rate();
void Init();
void Input_Stu_Info() //录入学生信息
{
    system("cls");
    cout << "【录入学生信息】" << endl;
    Student s1;
    cout << "请输入姓名:";
    cin >> s1.name;
    cout << "请输入性别:";
    cin >> s1.gender;
    cout << "请输入出生日期:";
    cin >> s1.birthday;
    cout << "请输入籍贯:";
    cin >> s1.nativePlace;
    cout << "请输入民族:";
    cin >> s1.national;
    cout << "请输入身份证号:";
    cin >> s1.IDnumber;
    cout << "请输入门牌号:";
    cin >> s1.roomNum;
	cout << "请输入政治面貌:";
	cin >> s1.political;
    cout << "请输入学校:";
    cin >> s1.school;
    cout << "请输入年级:";
    cin >> s1.grade;
    cout << endl;

    num++; //总人口数+1
    studentnum++; //学生数+1

    if(s1.gender == "男") //统计性别数
        boy++;
    else
        girl++;

	if (s1.political == "共产党员") //统计党员人数
		dangyuan++;

    //学生信息写入文件
    ofstream ofile("Stu_Info.txt", ios_base::app);
    ofile << s1.name << " " << s1.gender << " " << s1.birthday << " " << s1.nativePlace << " ";
    ofile << s1.national << " " << s1.IDnumber << " " << s1.roomNum  << " " << s1.political << " " << s1.school << " " << s1.grade << endl;
    ofile.close();

    //"统计数"写入文件<格式>:总人口 男数 女数 党员数 成人数 学生数 幼儿数
    ofstream pfile("People.txt",ios_base::out);
    pfile << num << " " << boy << " " << girl << " " << dangyuan << " " << adultnum << " " << studentnum << " " << childnum << endl;
    pfile.close();
    cout << "[信息录入成功]" << endl;
    cout << "按1继续录入,按2返回上一级,按0返回首页" << endl;
    int x;
    cin >> x;
    if (x == 1)
    {
        Input_Stu_Info();
    }
    else if (x == 2)
    {
        Input_Population_Info();
    }
    else if (x == 0)
    {
        Init();
    }
}

void Input_Ch_Info() //录入幼儿信息
{
    system("cls");
    cout << "【录入幼儿信息】" << endl;
    Student s1;
    cout << "请输入姓名:";
    cin >> s1.name;
    cout << "请输入性别:";
    cin >> s1.gender;
    cout << "请输入出生日期:";
    cin >> s1.birthday;
    cout << "请输入籍贯:";
    cin >> s1.nativePlace;
    cout << "请输入民族:";
    cin >> s1.national;
    cout << "请输入身份证号:";
    cin >> s1.IDnumber;
    cout << "请输入门牌号:";
    cin >> s1.roomNum;
    cout << endl;
    s1.political = "群众";
    
    num++; //总人数+1

    childnum++; //幼儿数+1

    if(s1.gender == "男") //统计性别
        boy++;
    else
        girl++;

    //幼儿信息写入文件
    ofstream ofile("Ch_Info.txt", ios_base::app);
    ofile << s1.name << " " << s1.gender << " " << s1.birthday << " " << s1.nativePlace << " ";
    ofile << s1.national << " " << s1.IDnumber << " " << s1.roomNum << " " << s1.political << endl;
    ofile.close();

    //"统计数"写入文件<格式>:总人口 男数 女数 党员数 成人数 学生数 幼儿数
    ofstream pfile("People.txt",ios_base::out);
    pfile << num << " " << boy << " " << girl << " " << dangyuan << " " << adultnum << " " << studentnum << " " << childnum << endl;
    pfile.close();
    cout << "[信息录入成功]" << endl;

    cout << "按1继续录入,按2返回上一级,按0返回首页" << endl;
    int x;
    cin >> x;
    if (x == 1)
    {
        Input_Ch_Info();
    }
    else if (x == 2)
    {
        Input_Population_Info();
    }
    else if (x == 0)
    {
        Init();
    }
}
void Input_Adu_Info() //录入成人信息
{
    system("cls");
    cout << "【录入成人信息】" << endl;
    Adult s1;
    cout << "请输入姓名:";
    cin >> s1.name;
    cout << "请输入性别:";
    cin >> s1.gender;
    cout << "请输入出生日期:";
    cin >> s1.birthday;
    cout << "请输入籍贯:";
    cin >> s1.nativePlace;
    cout << "请输入民族:";
    cin >> s1.national;
    cout << "请输入身份证号:";
    cin >> s1.IDnumber;
    cout << "请输入门牌号:";
    cin >> s1.roomNum;
	cout << "请输入政治面貌:";
	cin >> s1.political;
    cout << "请输入学历:";
    cin >> s1.edu;
    cout << "请输入工作:";
    cin >> s1.work;
    cout << "请输入公司地址:";
    cin >> s1.companyAddress;
    cout << "请输入年收入:";
    cin >> s1.salary;
    cout << "请输入电话:";
    cin >> s1.phonenum;
    cout << "请输入婚姻情况:";
    cin >> s1.marriage;
    cout << endl;

	
    num++; //总人数+1

    adultnum++; //成人数+1

    if(s1.gender == "男") //统计性别
        boy++;
    else
        girl++;

	//统计党员人数
	if (s1.political == "共产党员")
		dangyuan++;

    //成人信息写入文件
    ofstream ofile("Adu_Info.txt", ios_base::app);
    ofile << s1.name << " " << s1.gender << " " << s1.birthday << " " << s1.nativePlace << " ";
    ofile << s1.national << " " << s1.IDnumber << " " << s1.roomNum << " "  << s1.political << " " << s1.edu << " " << s1.work << " ";
    ofile << s1.companyAddress << " " << s1.salary << " " << s1.phonenum << " " << s1.marriage << endl;
    ofile.close();

    //"统计数"写入文件<格式>:总人口 男数 女数 党员数 成人数 学生数 幼儿数
    ofstream pfile("People.txt",ios_base::out);
    pfile << num << " " << boy << " " << girl << " " << dangyuan << " " << adultnum << " " << studentnum << " " << childnum << endl;
    pfile.close();
    cout << "[信息录入成功]" << endl;
    
    cout << "按1继续录入,按2返回上一级,按0返回首页" << endl;
    int x;
    cin >> x;
    if (x == 1)
    {
        Input_Adu_Info();
    }
    else if (x == 2)
    {
        Input_Population_Info();
    }
    else if (x == 0)
    {
        Init();
    }
}

void Input_Population_Info()
{
    system("cls");
    cout << "【录入人口信息】" << endl;
    cout << "1.录入成年人信息" << endl;
    cout << "2.录入学生信息" << endl;
    cout << "3.录入幼儿信息" << endl;
    cout << "4.返回首页" << endl; 
    cout << "请输入:" << endl;
    int x;
    cin >> x;
    if (x == 1)
    {
        Input_Adu_Info();
    }
    else if (x == 2)
    {
        Input_Stu_Info();
    }
    else if (x == 3)
    {
        Input_Ch_Info();
    }
    else if (x == 4)
    {
    	Init(); 
	}
    else 
    {
        cout << "输入错误!请重新输入!" << endl;
        system("pause");
        Input_Population_Info();
    }
}

void Put_Population_number()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数、成年人口数 时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();

    cout<<"社区总人口数为:" << temp_1 << endl;

    cout<<"按1返回首页"<<endl;
    int x;
    cin>>x;
    if(x == 1)
    {
        Init();
    }
}

void Get_sex_Rate()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数、成年人口数 时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();

    cout<<"男女比例:" << temp_2*1.0/temp_3 << endl;
    cout<<"按1返回首页"<<endl;

    int x;
    cin>>x;
    if(x == 1)
    {
       Init();
    }
}

void Get_dangyuan_num()
{
    system("cls");
    
    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数、成年人口数 时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();
    
    cout << "党员人数:" << temp_4 << endl;

    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Get_diff_age_group()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();

    //幼儿及学生人口数、劳动力人口、老人数
    int cnt_litter = 0, cnt_labor = 0, cnt_old = 0;
    Adult tt;
    ifstream pfile("Adu_Info.txt", ios_base::in);
    while (temp_5--)
    {
        pfile >> tt.name >> tt.gender >> tt.birthday >> tt.nativePlace >> tt.national >> tt.IDnumber >> tt.roomNum >> tt.political >> tt.edu >> tt.work >> tt.companyAddress >> tt.salary >> tt.phonenum >> tt.marriage;
        if ((2021-(tt.birthday/10000)) >= 60)
        {
            cnt_old++;
        }
        else 
        {
            cnt_labor++;
        }
    }
    pfile.close();
    cnt_litter = temp_1 - cnt_labor - cnt_old; //幼儿及学生人口=总人数-劳动力人口-老年人口
    
    cout << "幼儿及学生人口占比:" << fixed << setprecision(2) << cnt_litter*1.0/temp_1 << endl;
    cout << "劳动人口占比:" << fixed << setprecision(2) << cnt_labor*1.0/temp_1 << endl;
    cout << "老年人口占比:" << fixed << setprecision(2) << cnt_old*1.0/temp_1 << endl;

    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Get_per_salary_rank()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();

    multimap<int, string, greater<int> >rank; //个人收入排名输出时只输出收入和姓名
    Adult tt;
    ifstream pfile("Adu_Info.txt", ios_base::in);
    while (temp_5--)
    {
        pfile >> tt.name >> tt.gender >> tt.birthday >> tt.nativePlace >> tt.national >> tt.IDnumber >> tt.roomNum >> tt.political >> tt.edu >> tt.work >> tt.companyAddress >> tt.salary >> tt.phonenum >> tt.marriage;
        rank.insert(make_pair(tt.salary, tt.name));
    }
    pfile.close();

    multimap<int, string>::iterator pos;
    for (pos = rank.begin(); pos != rank.end(); ++pos)
    {
        cout << pos->first << "元  " << pos->second << endl;
    }
    
    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Get_family_num()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();
    
    Family ff;
    multimap<int, int>a; //<门牌号, 个人收入>

    Adult t1;
    ifstream pfile("Adu_Info.txt", ios_base::in);
    while (temp_5--)
    {
        pfile >> t1.name >> t1.gender >> t1.birthday >> t1.nativePlace >> t1.national >> t1.IDnumber >> t1.roomNum >> t1.political >> t1.edu >> t1.work >> t1.companyAddress >> t1.salary >> t1.phonenum >> t1.marriage;
        a.insert(make_pair(t1.roomNum, t1.salary));
    }
    pfile.close();

    Student t2;
    ifstream qfile("Stu_Info.txt", ios_base::in);
    while (temp_6--)
    {
        qfile >> t2.name >> t2.gender >> t2.birthday >> t2.nativePlace >> t2.national >> t2.IDnumber >> t2.roomNum >> t2.political >> t2.school >> t2.grade;
        a.insert(make_pair(t2.roomNum, 0));
    }
    qfile.close();

    Child t3;
    ifstream rfile("Ch_Info.txt", ios_base::in);
    while (temp_7--)
    {
        rfile >> t3.name >> t3.gender >> t3.birthday >> t3.nativePlace >> t3.national >> t3.IDnumber >> t3.roomNum >> t3.political;
        a.insert(make_pair(t3.roomNum, 0));
    }
    rfile.close();

    
    multimap<int, int>::iterator it = a.begin();
    int tmp_room = it->first;
    int count_family = 1;
    multimap<int, int>fam; //<门牌号,家庭收入>
    
    for (it = a.begin(); it != a.end(); ++it)
    {
        //cout << "测试" << count_family << endl;
        if (tmp_room != it->first) //门牌号相同,默认一家人
        {
            tmp_room = it->first;
            count_family++;
        }
    }


    cout << "家庭数:" << count_family << endl;

    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Get_fam_salary_rank()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //从文件中读取总人数、男、女、党员数时用
    ifstream ifile("People.txt", ios_base::in);
    ifile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    ifile.close();
    
    Family ff;
    multimap<int, int>a; //<门牌号, 个人收入>

    Adult t1;
    ifstream pfile("Adu_Info.txt", ios_base::in);
    while (temp_5--)
    {
        pfile >> t1.name >> t1.gender >> t1.birthday >> t1.nativePlace >> t1.national >> t1.IDnumber >> t1.roomNum >> t1.political >> t1.edu >> t1.work >> t1.companyAddress >> t1.salary >> t1.phonenum >> t1.marriage;
        a.insert(make_pair(t1.roomNum, t1.salary));
    }
    pfile.close();

    Student t2;
    ifstream qfile("Stu_Info.txt", ios_base::in);
    while (temp_6--)
    {
        qfile >> t2.name >> t2.gender >> t2.birthday >> t2.nativePlace >> t2.national >> t2.IDnumber >> t2.roomNum >> t2.political >> t2.school >> t2.grade;
        a.insert(make_pair(t2.roomNum, 0));
    }
    qfile.close();

    Child t3;
    ifstream rfile("Ch_Info.txt", ios_base::in);
    while (temp_7--)
    {
        rfile >> t3.name >> t3.gender >> t3.birthday >> t3.nativePlace >> t3.national >> t3.IDnumber >> t3.roomNum >> t3.political;
        a.insert(make_pair(t3.roomNum, 0));
    }
    rfile.close();

    
    multimap<int, int>::iterator it = a.begin();
    multimap<int, int>::iterator its = a.end();
    --its;
    int count_family = 1;
    int tmp_room = it->first;
    int count_fam_salary = 0;
    multimap<int, int, greater<int> >fam; //<门牌号,家庭收入>
    
    for (it = a.begin(); it != a.end(); ++it)
    {
        if (tmp_room != it->first) //门牌号相同,默认一家人
        {
            fam.insert(make_pair(count_fam_salary, tmp_room)); //门牌号,家庭收入插入map
            
            tmp_room = it->first;
            count_fam_salary = it->second;
            count_family++;
        }
        else
        {
            count_fam_salary += it->second;
        }

        if (it == its)
        {
            fam.insert(make_pair(count_fam_salary, tmp_room));
        }
    }


    multimap<int, int, greater<int> >::iterator pos;
    for (pos = fam.begin(); pos != fam.end(); pos++)
    {
        cout << pos->second << "室  " << pos->first << "元" << endl;
    }

    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Print_all()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //总、男、女、党员、成人、学生、幼儿
    ifstream afile("People.txt", ios_base::in);
    afile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    afile.close();


    Adult t1;
    ifstream pfile("Adu_Info.txt", ios_base::in);
    while (temp_5--)
    {
        pfile >> t1.name >> t1.gender >> t1.birthday >> t1.nativePlace >> t1.national >> t1.IDnumber >> t1.roomNum >> t1.political >> t1.edu >> t1.work >> t1.companyAddress >> t1.salary >> t1.phonenum >> t1.marriage;
        t1.showInfo();
    }
    pfile.close();

    Student t2;
    ifstream qfile("Stu_Info.txt", ios_base::in);
    while (temp_6--)
    {
        qfile >> t2.name >> t2.gender >> t2.birthday >> t2.nativePlace >> t2.national >> t2.IDnumber >> t2.roomNum >> t2.political >> t2.school >> t2.grade;
        t2.showInfo();
    }
    qfile.close();

    Child t3;
    ifstream rfile("Ch_Info.txt", ios_base::in);
    while (temp_7--)
    {
        rfile >> t3.name >> t3.gender >> t3.birthday >> t3.nativePlace >> t3.national >> t3.IDnumber >> t3.roomNum >> t3.political;
        t3.showInfo();
    }
    rfile.close();

    cout << "按1返回首页" << endl;
    int x;
    cin >> x;
    if(x == 1)
    {
       Init();
    }
}

void Change_Info()
{
    system("cls");

    int temp_1, temp_2, temp_3, temp_4, temp_5, temp_6, temp_7; //总、男、女、党员、成人、学生、幼儿
    ifstream afile("People.txt", ios_base::in);
    afile >> temp_1 >> temp_2 >> temp_3 >> temp_4 >> temp_5 >> temp_6 >> temp_7;
    afile.close();

    cout << "*请选择想要修改成人、学生、或幼儿信息*" << endl;
    cout << "1.修改成人信息" << endl;
    cout << "2.修改学生信息" << endl;
    cout << "3.修改幼儿信息" << endl;
    cout << "请输入..." << endl;
    int x;
    cin >> x;

    system("cls");

    if (x == 1) //修改成人
    {
        string temp_ID;
        cout << "请输入待修改人身份证号:" << endl;
        cin >> temp_ID;

        Adult t1[temp_5];
        ifstream pfile("Adu_Info.txt", ios_base::in);
        for (int i = 0; i < temp_5; i++)
        {
            pfile >> t1[i].name >> t1[i].gender >> t1[i].birthday >> t1[i].nativePlace >> t1[i].national >> t1[i].IDnumber >> t1[i].roomNum >> t1[i].political >> t1[i].edu >> t1[i].work >> t1[i].companyAddress >> t1[i].salary >> t1[i].phonenum >> t1[i].marriage;
            if (t1[i].IDnumber == temp_ID) //找到此人
            {
                cout << "请选择需要修改的信息:" << endl;
                cout << "1.修改姓名" << endl;
                cout << "2.修改性别" << endl;
                cout << "3.修改出生日期" << endl;
                cout << "4.修改籍贯" << endl;
                cout << "5.修改民族" << endl;
                cout << "6.修改身份证号" << endl;
                cout << "7.修改门牌号" << endl;
                cout << "8.修改政治面貌" << endl;
                cout << "9.修改学历" << endl;
                cout << "10.修改工作" << endl;
                cout << "11.修改公司地址" << endl;
                cout << "12.修改年收入" << endl;
                cout << "13.修改电话" << endl;
                cout << "14.修改婚姻情况" << endl;
                cout << "请输入";
                int xx;
                cin >> xx;
                if (xx == 1)
                    t1[i].reset_name();
                else if (xx == 2)
                    t1[i].reset_gender();
                else if (xx == 3)
                    t1[i].reset_birthday();
                else if (xx == 4)
                    t1[i].reset_nativePlace();
                else if (xx == 5)
                    t1[i].reset_national();
                else if (xx == 6)
                    t1[i].reset_IDnumber();
                else if (xx == 7)
                    t1[i].reset_roomNum();
                else if (xx == 8)
                    t1[i].reset_political();
                else if (xx == 9)
                    t1[i].reset_edu();
                else if (xx == 10)
                    t1[i].reset_work();
                else if (xx == 11)
                    t1[i].reset_companyAddress();
                else if (xx == 12)
                    t1[i].reset_salary();
                else if (xx == 13)
                    t1[i].reset_phonenum();
                else if (xx == 14)
                    t1[i].reset_marriage();
            }
        }
        pfile.close();

        //修改成功后再写入文件
        ofstream ofile("Adu_Info.txt");
        for (int i = 0; i < temp_5; i++)
        {
            ofile << t1[i].name << " " << t1[i].gender << " " << t1[i].birthday << " " << t1[i].nativePlace << " ";
            ofile << t1[i].national << " " << t1[i].IDnumber << " " << t1[i].roomNum << " "  << t1[i].political << " " << t1[i].edu << " " << t1[i].work << " ";
            ofile << t1[i].companyAddress << " " << t1[i].salary << " " << t1[i].phonenum << " " << t1[i].marriage << endl;
        }
        ofile.close();
    }
    else if (x == 2) //修改学生
    {
        string temp_ID;
        cout << "请输入待修改学生身份证号:" << endl;
        cin >> temp_ID;

        Student t2[temp_6];
        ifstream ppfile("Stu_Info.txt", ios_base::in);
        for (int i = 0; i < temp_6; i++)
        {
            ppfile >> t2[i].name >> t2[i].gender >> t2[i].birthday >> t2[i].nativePlace >> t2[i].national >> t2[i].IDnumber >> t2[i].roomNum >> t2[i].political >> t2[i].school >> t2[i].grade;
            if (t2[i].IDnumber == temp_ID) //找到此人
            {
                cout << "请选择需要修改的信息:" << endl;
                cout << "1.修改姓名" << endl;
                cout << "2.修改性别" << endl;
                cout << "3.修改出生日期" << endl;
                cout << "4.修改籍贯" << endl;
                cout << "5.修改民族" << endl;
                cout << "6.修改身份证号" << endl;
                cout << "7.修改门牌号" << endl;
                cout << "8.修改政治面貌" << endl;
                cout << "9.修改学校" << endl;
                cout << "10.修改年级" << endl;
                cout << "请输入:";
                
                int xx;
                cin >> xx;
                if (xx == 1)
                    t2[i].reset_name();
                else if (xx == 2)
                    t2[i].reset_gender();
                else if (xx == 3)
                    t2[i].reset_birthday();
                else if (xx == 4)
                    t2[i].reset_nativePlace();
                else if (xx == 5)
                    t2[i].reset_national();
                else if (xx == 6)
                    t2[i].reset_IDnumber();
                else if (xx == 7)
                    t2[i].reset_roomNum();
                else if (xx == 8)
                    t2[i].reset_political();
                else if (xx == 9)
                    t2[i].reset_school();
                else if (xx == 10)
                    t2[i].reset_grade();
            }
        }
        ppfile.close();

        //修改成功后再写入文件
        ofstream oofile("Stu_Info.txt");
        for (int i = 0; i < temp_6; i++)
        {
            oofile << t2[i].name << " " << t2[i].gender << " " << t2[i].birthday << " " << t2[i].nativePlace << " ";
            oofile << t2[i].national << " " << t2[i].IDnumber << " " << t2[i].roomNum << " "  << t2[i].political << " " << t2[i].school << " " << t2[i].grade << endl;
        }
        oofile.close();
    }
    else if (x == 3) //修改幼儿
    {
        string temp_ID;
        cout << "请输入待修改幼儿的身份证号:" << endl;
        cin >> temp_ID;

        Child t3[temp_7];
        ifstream pppfile("Ch_Info.txt", ios_base::in);
        for (int i = 0; i < temp_7; i++)
        {
            pppfile >> t3[i].name >> t3[i].gender >> t3[i].birthday >> t3[i].nativePlace >> t3[i].national >> t3[i].IDnumber >> t3[i].roomNum >> t3[i].political;
            if (t3[i].IDnumber == temp_ID) //找到此人
            {
                cout << "请选择需要修改的信息:" << endl;
                cout << "1.修改姓名" << endl;
                cout << "2.修改性别" << endl;
                cout << "3.修改出生日期" << endl;
                cout << "4.修改籍贯" << endl;
                cout << "5.修改民族" << endl;
                cout << "6.修改身份证号" << endl;
                cout << "7.修改门牌号" << endl;
                cout << "请输入:";
                
                int xx;
                cin >> xx;
                if (xx == 1)
                    t3[i].reset_name();
                else if (xx == 2)
                    t3[i].reset_gender();
                else if (xx == 3)
                    t3[i].reset_birthday();
                else if (xx == 4)
                    t3[i].reset_nativePlace();
                else if (xx == 5)
                    t3[i].reset_national();
                else if (xx == 6)
                    t3[i].reset_IDnumber();
                else if (xx == 7)
                    t3[i].reset_roomNum();
            }
        }
        pppfile.close();

        //修改成功后再写入文件
        ofstream ooofile("Ch_Info.txt");
        for (int i = 0; i < temp_7; i++)
        {
            ooofile << t3[i].name << " " << t3[i].gender << " " << t3[i].birthday << " " << t3[i].nativePlace << " ";
            ooofile << t3[i].national << " " << t3[i].IDnumber << " " << t3[i].roomNum << " " << t3[i].political << endl;
        }
        ooofile.close();
    }

    cout << "等待跳转..." << endl;
    Sleep(1000);
    Init();
}

void Init()
{
    system("cls");
    cout << "***********************************" << endl;
    cout << "【社区人口普查系统】" << endl;
    cout << "***********************************" << endl;
    cout << "1.录入人口信息" << endl;
    cout << "2.显示社区总人口数" << endl;
    cout << "3.显示社区性别比" << endl;
    cout << "4.显示社区劳动力人口、老年人口比例" << endl;
    cout << "5.社区党员人数" << endl;
    cout << "6.社区个人年收入排行" << endl;
    cout << "7.社区家庭数" << endl;
    cout << "8.家庭收入排行" << endl;
    cout << "9.显示全部人员信息" << endl;
    cout << "10.修改人员信息" << endl;
    cout << "0.退出" << endl;
    cout << "***********************************" << endl << endl;

    cout << "请选择:" << endl;
    int x;
    cin >> x;
    switch (x)
    {
    case 1:
        Input_Population_Info();
        break;
    case 2:
        Put_Population_number();
        break;
    case 3:
        Get_sex_Rate();
        break;
    case 4:
        Get_diff_age_group();
        break;
    case 5:
		Get_dangyuan_num();
        break;
    case 6:
        Get_per_salary_rank();
        break;
    case 7:
        Get_family_num();
        break;
    case 8:
        Get_fam_salary_rank();
        break;
    case 9:
        Print_all();
    case 10:
        Change_Info();
    case 0:
        return;
        break;
    default:
        break;
    }

}


int main()
{
    Init();

    system("pause");
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值