仿照上篇文章,编写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;
}