Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MAIN SOURCE FILE: . Create a struct named Monster . Inside the header file, crea

ID: 3860972 • Letter: M

Question

MAIN SOURCE FILE: . Create a struct named Monster . Inside the header file, create a struct called Monster . Monster should have the following attributes: o Name o Combat Power/of type int //of type string Write the following functions: captureAttempt0 o chance of type int This function takes a Monster data type as an argument and returns a boolean true or false. The monster argument is to use the combatPower value to determine the chance of catching the pokemon. The chances of catching a pokemon depends upon how high the combatPower is. Use the following scale: · if combatPower is less than 100, there is a 1 in 2 chance to capture if combatPower is greater than 99 there is a 1 in 4 chance to capture if combatPower is greater than 200 there is a 1 in 8 chance to capture Check the variable "chance" to see if it is equal to zero·If it is, you caught the pokemon so return true. If it is any other number you did not catch the pokemon. The greater the combat power, the slimmer chance that zero appears. main Variables: monster of type Monster input of type char didCatch of type bool initialized and assigned to false pokeballs of type int initialized and assigned to

Explanation / Answer

//============================================================================

// Name : monster.cpp

// Author : Ramachandra jr

// Version :

// Copyright : Your copyright notice

// Description : Hello World in C++, Ansi-style

//============================================================================

#include <iostream>

#include <string>

#include <vector>

#include <ctime>

#include <cstdlib>

using namespace std;

struct Monster {

string _name;

int _cp;

};

bool captureAttempt(Monster m1)

{

// The question is not clear with this part of the function

// so there will be some additional code here.

int chance{ 0 };

if (chance == 0) return true;

return false;

}

/**

* Random name generator function.

*/

string randomNameGenerator() {

int index{};

vector<string> pokes = {

"Charmander", "Bulbasaur", "Squirtle",

"Pikachu", "Sandshrew", "Pidgey",

"Evee", "Ratatta"

};

srand (time(NULL));

index = rand() % (pokes.size());

return pokes.at(index);

}

/**

* Creates a random monster and returns the same monster

* as a pointer.

*/

Monster * setMonster(Monster &m1)

{

int cp;

// Generate name.

m1._name = randomNameGenerator();

// Generate cp.

srand (time(NULL));

cp = rand() % 450 + 1;

m1._cp = cp;

return &m1;

}

int main() {

Monster m0;

setMonster(m0);

char inp{};

bool didCatch{ false };

int pokeBalls{ 5 };

while (pokeBalls > 0 && didCatch == false)

{

didCatch = captureAttempt(m0);

}

if (pokeBalls == 0 && didCatch == false)

{

cout << "Sorry, couldn't catch!" << endl;

}

else

{

cout << "Caught a monster!" << endl;

}

return 0;

}