【25.3】C++智能交友系统

仿照上篇文章,编写boy类,代码如下

头文件

cpp 复制代码
#pragma once
#include <string>

using namespace std;

class Girl;
class Boy
{
public:
	Boy();
	Boy(int age, string name, int salary);
	~Boy();

	int getAge() const;
	string getName() const;
	int getSalary() const;

	bool satisfied(const Girl& girl) const;
	string description() const;
private:
	int age;
	string name;
	int salary;//薪资
};

cpp文件

cpp 复制代码
#include "boy.h"
#include "Girl.h"

#define SALARY_FACTOR 0.006

Boy::Boy()
{
	age = 0;
	name = "";
	salary = 0;
}

Boy::Boy(int age, string name, int salary)
{
	this->age = age;
	this->name = name;
	this->salary = salary;
}

Boy::~Boy()
{
}

int Boy::getAge() const
{
	return age;
}

string Boy::getName() const
{
	return name;
}

int Boy::getSalary() const
{
	return salary;
}

string Boy::description() const
{
	stringstream ret;
	ret << name << "-男-年龄-" << age << "-薪资-" << salary;
	return string();
}

bool Boy::satisfied(const Girl& girl) const
{
	if(girl.getStyle()>=salary*SALARY_FACTOR){
		return true;
	}
	else {
		return false;
	}
	
相关推荐
hakesashou4 分钟前
ruby和python哪个好学
开发语言·python·ruby
林一怂儿9 分钟前
H5 three.js 实现六年级观察物体
开发语言·javascript
ZH_qaq16 分钟前
【洛谷】P11062 【MX-X4-T2】「Jason-1」加法 的题解
c++·算法
NiNg_1_23418 分钟前
Python协程详解
开发语言·python
黑白子200023 分钟前
python定时任务,定时爬取水质和天气
开发语言·python
9ilk24 分钟前
【与C++的邂逅】--- C++的IO流
开发语言·c++
是小满满满满吗25 分钟前
C++中的继承
开发语言·c++·python
程序猿练习生25 分钟前
C++速通LeetCode简单第16题-买卖股票的最佳时机
开发语言·c++·leetcode
OEC小胖胖25 分钟前
js进阶-作用域是什么
开发语言·前端·javascript·ecmascript·web
只对您心动36 分钟前
【QT】实现TCP服务器,客户端之间的通信
linux·服务器·c语言·开发语言·c++·qt·tcp/ip