婚恋交友系统框架,实现的功能,男嘉宾,女嘉宾单个写入文件,成批写入文件。读文件方式(这里用的是C语言的sscanf_s(line.c_str(),""性别:男 姓名:%s
薪资:%d 年龄:%d",name,sizeof(name),&salary,&age))实现自动配对功能。所用到的知识有,类的继承与派生,类的继承方式。以及数据库的使用。
main.cpp
#include<vector>
#include<iostream>
#include"Boy.h"
#include"Girl.h"
#include"Database.h"
int main()
{
Database data;
data.init();
Boy boy;
Boy::inputBoy(boy);//输入boy信息
data.addOne(boy);
Girl girl;
Girl::inputGirl(girl);//输入girl信息
data.addOne(girl);
system("pause");
return 0;
}
Boy.h
#pragma once
#include<string>
#include<vector>
#include"Single.h"
using namespace std;
class Girl;
class Boy : public Single
{
public:
Boy();
Boy(string name, int age, int salary);
//int getAge() const;
//string getName() const;
int getSalary() const;
string description() const;
bool statisfied(const Girl&girl) const;
static void inputBoys(vector<Boy>&boys);
static void inputBoy(Boy& boy);
protected:
//int age;
//string name;
int salary; //薪资
};
Boy.cpp
#include "Boy.h"
#define SALARY_FACTOR 0.006
#include "Girl.h"
#include<sstream>
#include<iostream>
Boy::Boy()
{
//age = 0;
//name = "";
salary = 0;
}
Boy::Boy(string name, int age, int salary) : Single(name, age)
{
//this->age = age;
//this->name = name;
this->salary = salary;
}
/*int Boy::getAge() const
{
return age;
}
string Boy::getName() const
{
return name;
}*/
int Boy::getSalary() const
{
return salary;
}
string Boy::description() const
{
//规范一下字符串格式;
//性别:男\t\t\t姓名:zhs\t\t\t薪资:35000\t\t\t年龄:24
stringstream ret;
ret << "性别:男 姓名:"<<name<<" 薪资:"<<salary<<" 年龄:" << age;
return ret.str();
}
bool Boy::statisfied(const Girl & girl) const
{
int yanZhi = salary * SALARY_FACTOR;
if (yanZhi>=100)
{
yanZhi = 100;
}
if (girl.getYanZhi()>=yanZhi)
{
return true;
}
else
{
return false;
}
}
void Boy::inputBoys(vector<Boy>& boys)
{
int age;
string name;
int salar