c++面对对象编程,婚恋交友系统

婚恋交友系统框架,实现的功能,男嘉宾,女嘉宾单个写入文件,成批写入文件。读文件方式(这里用的是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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值