【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;
	}
	
相关推荐
黄雪超1 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice1 小时前
对象的finalization机制Test
java·开发语言·jvm
水木兰亭1 小时前
数据结构之——树及树的存储
数据结构·c++·学习·算法
思则变1 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
lijingguang1 小时前
在C#中根据URL下载文件并保存到本地,可以使用以下方法(推荐使用现代异步方式)
开发语言·c#
¥-oriented2 小时前
【C#中路径相关的概念】
开发语言·c#
CoderCodingNo2 小时前
【GESP】C++四级考试大纲知识点梳理, (7) 排序算法基本概念
开发语言·c++·排序算法
恋猫de小郭2 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
JosieBook3 小时前
【Java编程动手学】使用IDEA创建第一个HelloJava程序
java·开发语言·intellij-idea
Thomas_YXQ3 小时前
Unity3D DOTS场景流式加载技术
java·开发语言·unity