首页 > 编程语言 >C++ 很有意思的自动相亲交往系统基础版

C++ 很有意思的自动相亲交往系统基础版

时间:2022-11-13 20:24:37浏览次数:46  
标签:Boy 有意思 const name int age C++ 相亲 Girl

Boy.h:

#pragma once
#include <string>
#include <vector>
using namespace std;
class Girl;
class Boy
{
public:
    Boy();
    Boy(int age,string name,int salary);
    int getAge()const;
    string getName()const;
    int getSalary()const;
    bool isSatisfied(const Girl& girl)const;
    string description()const;
    static void inputBoys(vector<Boy>& boys);
    ~Boy();
private:
    int age;
    string name;
    int salary;

};

Girl.h:

#pragma once
#include <iostream>
#include <vector>
using namespace std;
class Boy;
class Girl
{
public:
    Girl();
    Girl(int age, string name, int faceScore);
    int getAge()const;
    string getName()const;
    int getFaceScore()const;
    bool isSatisfied(const Boy& boy)const;
    string description()const;
    static void inputGirls(vector<Girl> &girls);
    ~Girl();
private:
    int age;
    string name;
    int faceScore; //颜值
};

Boy.cpp:

#include <sstream>
#include "Boy.h"
#include "Girl.h"
#define SALARY_FACTORY 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;
}
int Boy::getAge()const {
    return age;
}
string Boy::getName() const {
    return name;
}
int Boy::getSalary()const {
    return salary;
}
bool Boy::isSatisfied(const Girl& girl)const {
    int faceScore = salary * SALARY_FACTORY;
    if (faceScore > 100) {
        faceScore = 100;
    }
    if (girl.getFaceScore() >= faceScore) {
        return true;
    }
    else
    {
        return false;
    }
}
void Boy::inputBoys(vector<Boy>& boys) {
    int age;
    string name;
    int salary;
    int n = 1;
    while (1)
    {
        cout << "请输入第" << n << "位小哥哥的年龄【输入0结束】:";
        cin >> age;
        if (age == 0) {
            break;
        }
        cout << "请输入第" << n << "位小哥哥的姓名:";
        cin >> name;

        cout << "请输入第" << n << "位小哥哥的薪资:";
        cin >> salary;
        n++;
        boys.push_back(Boy(age, name, salary));
    }
}
string Boy::description()const {
    stringstream ret;
    ret << name << "-男-薪资(" << salary << ")-年龄(" << age << ")";
    return ret.str();
}
Boy::~Boy() {

}

Girl.cpp:

#include "Girl.h"
#include "Boy.h"
#include <sstream>
#define FACESCORE_FACTORY 100

Girl::Girl() {
    name = "";
    age = 0;
    faceScore = 0;
}
Girl::Girl(int age, string name,int faceScore){
    this->name = name;
    this->age = age;
    this->faceScore = faceScore;
}
int Girl::getAge()const {
    return age;
}
string Girl::getName()const {
    return name;
}
int Girl::getFaceScore()const {
    return faceScore;
}
bool Girl::isSatisfied(const Boy& boy)const {
    if (boy.getSalary() >= faceScore * FACESCORE_FACTORY) {
        return true;
    }
    else
    {
        return false;
    }
}
void Girl::inputGirls(vector<Girl> &girls) {
    int age;
    string name;
    int faceScore;
    int n = 1;
    while (1)
    {
        cout << "请输入第" << n << "位小姐姐的年龄【输入0结束】:";
        cin >> age;
        if (age == 0) {
            break;
        }
        cout << "请输入第" << n << "位小姐姐的姓名:";
        cin >> name;

        cout << "请输入第" << n << "位小姐姐的颜值:";
        cin >> faceScore;
        n++;
        girls.push_back(Girl(age, name, faceScore));
    }
}
string Girl::description()const {
    stringstream ret;
    ret << name << "-女-颜值(" << faceScore << ")-年龄(" << age << ")";
    return ret.str();
}
Girl::~Girl() {
    
}

主函数main.cpp:

#include <iostream>
#include <vector>
#include "Girl.h"
#include "Boy.h"

using namespace std;
void autoPair(const vector<Boy>& boys, const vector<Girl>& girls) {
    for (int i = 0; i < boys.size(); i++) {
        for (int j = 0; j < girls.size(); j++) {
            if (boys[i].isSatisfied(girls[j]) &&
                girls[j].isSatisfied(boys[i])) {
                cout << boys[i].description() << "<==>" <<
                    girls[j].description() << endl;
            }
        }
    }
}
int main() {
    
    vector<Boy> boys;
    vector<Girl> girls;

    Boy::inputBoys(boys);
    Girl::inputGirls(girls);
    cout << "\n--------------------------结果------------------------\n";
    autoPair(boys,girls);
    
    system("pause");
    return 0;
}

运行结果:

标签:Boy,有意思,const,name,int,age,C++,相亲,Girl
From: https://www.cnblogs.com/smartlearn/p/16886788.html

相关文章

  • c++ 基础语法
    一眼mophie,鉴定为:普及组。#include<bits/stdc++.h>#defineintlonglong#definepbpush_back#definempmake_pair#definepiipair<int,int>#definexfirst#de......
  • C/C++班主任管家系统
    C/C++班主任管家系统设计与开发班主任管家系统,巩固所学c语言基础知识,通过实际项目的开发过程培养综合解决问题的能力及编程能力等。班主任管家软件以学生信息﹑课程信息为......
  • C/C++中声明指针变量时星号是靠近变量名还是靠近数据类型?
    摘自<<C和指针>>3.23  int*a;int*a;两者意思相同且后者看上去更为清楚:a被声明为类型为int*的指针.但是,这并不是一个好技巧,原因如下:int*b,c,d;人们很......
  • C++中 vector容器的神奇用法
    1.可以用简单的数据类型作为参数:#include<iostream>#include<vector>usingnamespacestd;intmain(){vector<int>data;data.push_back(1);data......
  • C++设计模式-(创建模式)原型模式
     原型模式主要用于复制当前对象的副本 #include<iostream>classanimal{public:virtual~animal(){}virtualvoideat(){std::cout......
  • 按照C++语言程序结构组成数字电路进行计算的计算机
    按照C++语言程序结构组成数字电路进行计算的计算机按照C++语言程序结构组成数字电路进行计算的计算机是一种可以按照C++语言程序结构来安排加法器,输出显示电路,输入电路,的数......
  • 类和对象——C++运算符重载
    概念:对已有的运算符重新定义,赋予其另一种功能,以适应不同数据类型。。重载的两类方法:1.类成员函数重载2.全局函数重载注意:运算符重载也可以实现函数重载引入:我们希望......
  • C++ template using for what?
    //Forclassusing,youcansetaseriousofmacrotopredictsomething////whenyoucallthismacro,thetemplatecouldmakeanewfunctionbyyourinput//templ......
  • C++运算符重载相关知识点
    1.运算符重载限制重载后的运算符必须至少有一个操作数是用户自定义的类型使用运算符时不能违反运算符原来的句法规则,也不能修改运算符的优先级。2.不能进行重载的运......
  • C++之string的底层简单实现!(七千字长文详解)
    C++之string的底层简单实现!string之私有成员变量namespaceMySTL{classstring {private: char*_str; size_t_size; size_t_capacity; //这里capa......