Question
The Monster class will have the following attributes: Private String name tba Private int health tba Private int strength tba Private int defense tba Private
The Monster class will have the following attributes:
Private | String | name | tba |
Private | int | health | tba |
Private | int | strength | tba |
Private | int | defense | tba |
Private | int | speed | tba |
Private | static const int | MAX_HEALTH | 100 |
Private | static const int | MAX_STRENGTH | 50 |
Private | static const int | MAX_DEFENSE | 100 |
Private | static const int | MAX_SPEED | 20 |
The Monster class will have the following methods/functions:
Access | Return type | Name | Inputs | Purpose |
Public | none | Monster | none | Default constructor |
Public | none | Monster | Five Monster attributes | Non-default constructor |
Public | none | Monster | one monster | Copy constructor |
Public | none | ~Monster | none | Destructor |
Public | string | getName | none | Accessor |
Public | int | getHealth | none | Accessor |
Public | int | getStrength | none | Accessor |
Public | int | getDefense | none | Accessor |
Public | int | getSpeed | none | Accessor |
Public | void | setName | string | Mutator |
Public | void | setHealth | int | Mutator |
Public | void | setStrength | int | Mutator |
Public | void | setDefense | int | Mutator |
Public | void | setSpeed | int | Mutator |
Public | void | attack | One monster | Simulate one Monster attacking another Monster |
Public | void | none | Print all five Monster attributes |
The attack speed of monster1 is a random value between 1 and monster1.speed. The dodge speed of monster2 is a random value between 1 and monster2.speed. The attack power of monster 1 is a random value between 1 and monster1.strength When monster2 dodge speed > monster1 attack speed, then monster2 successfully dodges the monster1 attack and no damage occurs. If monster2 does not dodge monster1, then monster2.defense tells us the percentage of the monster1 attack power that is deflected from monster2. If monster2.defense = 0 then monster2 has no protection, and monster2.health is reduced by the monster1 attack power. If monster2.defense = 100 then monster2 is invincible to the attack, and monster2.health is not reduced. If the health of monster2 goes to zero, the monster dies.
Your first task is to implement the Monster class interface in monster.h. Then, you should create skeleton implementations of all Monster class methods in monster.cpp that simply print out the names of each method. Next, you should create main.cpp that simply calls each of the monster methods to verify they are working as expected. Once this is working, you can add implementations of monster methods one at a time and run your main program to verify their correctness. Your second task is to extend your program in main.cpp to declare an array of N Monster objects and read monster information from an input file monster.txt to initialize this array objects. The format of this file is very simple. The first line contains an integer N that specifies how many monsters are in the file. After this, there are N*5 lines in the file that contain the attributes of each monster. The order of these attributes matches the order of attributes in the class specifications above. To verify that you have successfully created your array of monsters, you should loop over the array to print out the attributes of each monster. Your final task is to test the attack method by asking the user to select two numbers A and B between 0 and N-1 and then write a loop that has monster[A] and monster[B] take turns attacking each other until one of the monsters die. Your program should print the results of each attack move, showing the damage done to the defense and health of each monster at each step.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started