【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;
	}
	
相关推荐
Antonio9157 分钟前
【Swift】Swift基础语法:函数、闭包、枚举、结构体、类与属性
开发语言·swift
csbysj202010 分钟前
Vue3 事件处理
开发语言
Q***f63525 分钟前
Kotlin在Android性能优化中的工具
android·开发语言·kotlin
是小胡嘛41 分钟前
华为云CentOS系统中运行http服务器无响应
linux·服务器·c++·http·centos·华为云
菠菠萝宝1 小时前
【Java手搓RAGFlow】-9- RAG对话实现
java·开发语言·人工智能·llm·jenkins·openai
leon_zeng01 小时前
Qt OpenGL 3D 彩色立方体开发指南
开发语言·qt
科威舟的代码笔记1 小时前
第10讲:Stream实战与陷阱——综合案例与最佳实践
java·开发语言
MM_MS1 小时前
WinForm+C#小案例--->爱心跑马灯演示
开发语言·c#·visual studio
福尔摩斯张1 小时前
C语言核心:string函数族处理与递归实战
c语言·开发语言·数据结构·c++·算法·c#
程序定小飞2 小时前
基于springboot的体育馆使用预约平台的设计与实现
java·开发语言·spring boot·后端·spring