美文网首页
(二)Team

(二)Team

作者: GoodTekken | 来源:发表于2023-03-23 14:20 被阅读0次
#include<iostream>
#include<string>

using namespace std;

class Team
{
    private:
        string name;
        int goals;  //(1) 

    public:
        Team(string name)
        {
            this->name = name; //(2) 
            goals = 0;
        }
        void increamentGoal()
        {
            goals++; //(3) 
        }

        int getGoals()
        {
            return goals;
        }

        string getName()
        {
            return name;
        }
};

class Game
{
    private:
        Team *a,*b;   //两支比赛球队

    public:
        Game(Team *t1, Team *t2)
        {
            a = t1;
            b = t2;
        }

        void getResults()  //输出比分
        {
            cout << a->getName() << " : " << b->getName() << " = ";
            cout << a->getGoals() << " : " << b->getGoals() << endl;
        }

        void increamentGoal(Team* t) //球队t 进1球  //(4) 
        {
            t->increamentGoal();
        }
};

int main()
{
    Team *t1 = new Team("TA");
    Team *t2 = new Team("TB");
    Game *football = new Game(t1,t2); //(5) 

    football->increamentGoal(t1);
    football->increamentGoal(t2);
    football->getResults();       //输出为:TA:TB = 1:1
    football->increamentGoal(t2);
    football->getResults();       //输出为:TA:TB = 1:2

    return 0;
}

答案:
(1) int goals

(2) this->name

(3) goals++

(4) Team*

(5) new Game(t1,t2)

相关文章

  • kali上安装team viewer 12

    今天试了一下在kali上安装team viewer 12 下载team viewer 12 二、根据安装说明进行安...

  • 上班第二天

    上班第二天,加班第二天。 今天原PM离职了,我就成为了唯一的PM。 三个scrum team,有个team本来需要...

  • 20180119——团队

    Team is a team,King is a king。 We are together。

  • 工作——团队

    team player 有团队合作精神的人 build a team 组建团队 work in a team 在团...

  • TEAM COACHING课堂笔记二

    复盘DAY 2. 第二天练习明显增多, 体验式的反思也变得多了起来。 1. CONFUSION IS A DOOR...

  • Wonderful football match

    In the evening, the Beijing team and the Guangzhou team g...

  • TEAM

    试想一下, 场景一:小A是一个业务能力突出的员工。一天,他和新来的部门领导C因为一个决议产生了不同看法,以往经验告...

  • Team

    别人①个人组织一个微信群活成一个队伍 你一个人几个微信号活成队伍

  • TEAM

    “万夫一力,天下无敌”。 这是明朝开国元勋刘伯温说的,强调的是团队的力量。 是的,这世界上的每一个人,他的力量都是...

  • team

    游戏工作室,感觉是一个奋斗在前线的战斗团队,我们要随 时掌握最新时事内容,保证整个团队不被拉下,因为类似这...

网友评论

      本文标题:(二)Team

      本文链接:https://www.haomeiwen.com/subject/qiyirdtx.html