Answer to Question #344579 in C++ for Ali Mustafa

Question #344579

Create a “Boss” class that inherits from the “Armed Enemy” class. Implement an additional

armor level field for the “Boss” class and provide suitable getter and setter methods. Create a

“Boss” Object in the main function to test the functionality of your “Boss” class.



1
Expert's answer
2022-05-25T10:22:57-0400
#include <iostream>

class ArmedEnemy{
    protected:
        float health;
        int armor;
    public:
        ArmedEnemy(float hp = 100, int def = 10){
            health = hp;
            armor = def;
        }
    float getHP(){
        return health;
    }
    void setHP(int hp){
        health = hp;
    }
    void setHP(float hp){
        health = hp;
    }
    // add any other methohds you would like to have
};


class Boss:public ArmedEnemy{
    private:
        float armorShield;
    public:
    Boss(float hp = 1000, int def = 0, float shield = 100){
        health = hp;
        armor = def;
        armorShield = shield;
    }
};


using namespace std;
int main()
{
    Boss demon(1000);
    demon.setHP(500);
    cout<<demon.getHP();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS