【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;
	}
	
相关推荐
li星野2 小时前
Qt 单例配置管理器学习记录:JsonConfigManager 的设计原理与使用示例
开发语言·qt·学习
闻缺陷则喜何志丹2 小时前
【C++20特性】std::format
c++·字符串·c++20·格式化
默 语9 小时前
HarmonyOS7 事件分发控制(二):onTouchIntercept 镂空玻璃卡——圆内自己接,圆外放行
android·java·开发语言
Amumu1213810 小时前
TypeScript学习: 基础知识(二)
开发语言·typescript·ecmascript
derek199710 小时前
软考软件设计师:B-树和 B+树的区别、线性探查法查找时到底比较了谁
c语言·c++·计算机网络·软件工程·学习方法
sharemylove10 小时前
Java 异常与常用类 学习笔记
java·开发语言·经验分享·笔记·学习
小灰灰搞电子11 小时前
C 语言基础:动态内存管理详解
c语言·开发语言
打工仔折腾 AI11 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
fqbqrr11 小时前
2612C++,C++量钢问题
c++
Amumu1213811 小时前
TypeScript学习: 进阶知识
开发语言·学习·typescript