# cpp03
###### tags: cpp
## ex00
Here you have to make a class!
<font color="ForestGreen">ここでクラスを作る必要があります!</font>
How original!
<font color="ForestGreen">なんて独創的!</font>
The class will be called ClapTrap, and will have the following private attributes,initialized to the specified values:
<font color="ForestGreen">このクラスはClapTrapと呼ばれ、指定された値に初期化された次のプライベート属性を持ちます。</font>
- Name (Parameter of constructor)
<font color="ForestGreen">-名前(コンストラクターのパラメーター)</font>
- Hitpoints (10)
<font color="ForestGreen">-ヒットポイント(10)</font>
- Energy points (10)
<font color="ForestGreen">-エネルギーポイント(10)</font>
- Attack damage (0)You will also give it a few public functions to make it more life
<font color="ForestGreen">-攻撃ダメージ(0)あなたはそれをより多くの生命にするためにそれにいくつかの公共の機能も与えます</font>
-like:
<font color="ForestGreen">-お気に入り:</font>
- void attack(std::string const & target)
<font color="ForestGreen">-voidattack(std :: string const&target)</font>
- void takeDamage(unsigned int amount)
<font color="ForestGreen">--void takeDamage(unsigned int amount)</font>
- void beRepaired(unsigned int amount)In all of these functions, you have to display something to describe what happens.
<font color="ForestGreen">--void beRepaired(unsigned int amount)これらすべての関数では、何が起こるかを説明するために何かを表示する必要があります。</font>
For example, the attack function may display something along the lines of:ClapTrap <name> attacks <target>, causing <damage> points of damage!
<font color="ForestGreen">たとえば、攻撃関数は次の行に沿って何かを表示する場合があります:ClapTrap<name>攻撃<target>、原因<damage>ダメージポイント!</font>
The constructor and destructor must also display something, so people can see theyhave been called.
<font color="ForestGreen">コンストラクタとデストラクタも何かを表示する必要があるため、人々は自分が呼び出されたことを確認できます。</font>
You will provide a main function, with enough tests to demonstrate that your code isfunctional.
<font color="ForestGreen">コードが機能していることを示すのに十分なテストを含むmain関数を提供します。</font>
## ex01
Because we can’t ever have enough Claptraps, now you will make another one.
<font color="ForestGreen">十分な数のクラップトラップを入手できないため、別のクラップトラップを作成します。</font>
The class will be named ScavTrap, and will inherit from ClapTrap, the constructor,destructor, and attacks have to use different outputs.
<font color="ForestGreen">クラスにはScavTrapという名前が付けられ、コンストラクタ、デストラクタであるClapTrapから継承され、攻撃は異なる出力を使用する必要があります。</font>
After all, a Claptrap has to havesome measure of individuality.
<font color="ForestGreen">結局のところ、クラップトラップにはある程度の個性が必要です。</font>
The ScavTrap class will have its construction and destruction messages.
<font color="ForestGreen">ScavTrapクラスには、構築メッセージと破棄メッセージがあります。</font>
Also, properconstruction/destruction chaining must be present (When you build a ScavTrap, youmust start by building a ClapTrap... Destruction is in reverse order), and the tests haveto show it.
<font color="ForestGreen">また、適切な構築/破壊チェーンが存在する必要があり(ScavTrapを構築するときは、ClapTrapを構築することから始める必要があります...破壊は逆の順序です)、テストはそれを示さなければなりません。</font>
ScavTrap will use the attributes of Claptrap (You need to change Claptrap accordingly)!
<font color="ForestGreen">ScavTrapはクラップトラップの属性を使用します(それに応じてクラップトラップを変更する必要があります)!</font>
And must initialize them to:
<font color="ForestGreen">そして、それらを次のように初期化する必要があります。</font>
- Name (Parameter of constructor)
<font color="ForestGreen">-名前(コンストラクターのパラメーター)</font>
- Hitpoints (100)
<font color="ForestGreen">-ヒットポイント(100)</font>
- Energy points (50)
<font color="ForestGreen">-エネルギーポイント(50)</font>
- attack damage (20)ScavTrap will also have a new specific function: void guardGate(); this functionwill display a message on the standard outputs to anounce that ScavTrap have enterredin Gate keeper mode.
<font color="ForestGreen">-攻撃ダメージ(20)ScavTrapには、新しい特定の関数もあります:void guardGate();この関数は、ScavTrapがゲートキーパーモードに入ったことを通知するメッセージを標準出力に表示します。</font>
Extend your main function to test everything.
<font color="ForestGreen">main関数を拡張して、すべてをテストします。</font>
## ex02
Making Claptraps is probably starting to get on your nerves.
<font color="ForestGreen">クラップトラップを作ることはおそらくあなたの神経質になり始めています。</font>
Now, you will make a FragTrap class that inherits from ClapTrap.
<font color="ForestGreen">ここで、ClapTrapから継承するFragTrapクラスを作成します。</font>
- Name (Parameter of constructor)
<font color="ForestGreen">-名前(コンストラクターのパラメーター)</font>
- Hitpoints (100)
<font color="ForestGreen">-ヒットポイント(100)</font>
- Energy points (100)
<font color="ForestGreen">-エネルギーポイント(100)</font>
- attack damage (30)The FragTrap class will have its construction and destruction messages.
<font color="ForestGreen">-攻撃ダメージ(30)FragTrapクラスには構築と破壊のメッセージがあります。</font>
Also, properconstruction/destruction chaining must be present (When you build a FragTrap, youmust start by building a ClapTrap... Destruction is in reverse order), and the tests haveto show it.
<font color="ForestGreen">また、適切な構築/破壊チェーンが存在する必要があり(FragTrapを構築するときは、ClapTrapを構築することから始める必要があります...破壊は逆の順序です)、テストはそれを示さなければなりません。</font>
The specific function for FragTrap will be void highFivesGuys(void) and will display a positive high fives request on the standard output.
<font color="ForestGreen">FragTrapの特定の関数はvoidhighFivesGuys(void)であり、標準出力に正のハイタッチ要求を表示します。</font>
Extend your main function to test everything.
<font color="ForestGreen">main関数を拡張して、すべてをテストします。</font>
## ex03
Now, you will create a monster by making a Claptrap that’s half Fragtrap, half Fragtrap.
<font color="ForestGreen">次に、半分がフラグトラップ、半分がフラグトラップであるクラップトラップを作成して、モンスターを作成します。</font>
It will be named DiamondTrap, and it will inherit from both the FragTrap AND theScavTrap.
<font color="ForestGreen">これはDiamondTrapという名前になり、FragTrapとtheScavTrapの両方から継承されます。</font>
Very risky and horrible act the DiamondTrap class will declare a private attributecalled name like the one inside ClapTrap.
<font color="ForestGreen">非常に危険で恐ろしい行為であるDiamondTrapクラスは、ClapTrap内のような名前と呼ばれるプライベート属性を宣言します。</font>
Its attributes and functions will be chosen from either of its parent classes:
<font color="ForestGreen">その属性と関数は、その親クラスのいずれかから選択されます。</font>
- Name (Parameter of constructor)
<font color="ForestGreen">-名前(コンストラクターのパラメーター)</font>
- Claptrap::Name (Parameter of constructor + "_clap_name")
<font color="ForestGreen">--Claptrap :: Name(コンストラクターのパラメーター+ "_clap_name")</font>
- Hitpoints (Fragtrap)
<font color="ForestGreen">- ヒットポイント</font>
- Energy points (Scavtrap)
<font color="ForestGreen">-エネルギーポイント(Scavtrap)</font>
- Attack damage (Fragtrap)
<font color="ForestGreen">-攻撃ダメージ(フラグトラップ)</font>
- attack (Scavtrap)It will have the special functions of both.
<font color="ForestGreen">-攻撃(スカトラップ)両方の特殊機能があります。</font>
As usual, your main will be extended to test the new class.
<font color="ForestGreen">いつものように、メインは新しいクラスをテストするために拡張されます。</font>
Of course, the Claptrap part of the Diamondtrap will be created once, and only once...Yes, there’s a trick.
<font color="ForestGreen">もちろん、DiamondtrapのClaptrap部分は一度だけ作成されます...はい、トリックがあります。</font>
DiamondTrap will have a new function void whoAmI(); that will display its nameand its clapTrap name.
<font color="ForestGreen">DiamondTrapには新しい関数voidwhoAmI();があります。名前とクラップトラップ名が表示されます。</font>
Compilation flags like -Wshadow and -Wno-shadow!