Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Advanced C++: Gorg vs Boov Battle Part 2 Bring on the Gorg! NOTE: Remember that you are adding on to your previous Boov project.See the

Advanced C++:

Gorg vs Boov Battle Part 2 Bring on the Gorg! NOTE: Remember that you are adding on to your previous Boov project.See the previous documentation for Boov specific information. The Gorg can no longer be reasoned with!Negotiations cannot go well if you have no idea what the other side wants!They are so strong and vicious that ignoring them only means Earth is indirectly conquered somehow ? Its not my movie plot, but my retelling is totally butchering it for sure. The Boov are friends of all peoples across the galaxy.Or so we are told.These beloved creatures want nothing more than peace and harmony, as long as it is their version of peace and harmony.It turns out okay for everyone in the end I suppose. Maybe you can tell from the descriptions, but the Boov are quite the underdogs here!Captain Smek will need to simulate a Gorg battle many times over to see what their odds of victory would be. For the next part of this simulation, lets create the Gorg class.Here are their specifications. Gorg Every one of them is named George Every one of them has 10 health points When a Gorg gets attacked : o 1 / 4 of the time randomly, the attack will miss and do no damage o 1 / 4 of the time the Gorg will actually regain 1 health point!Just make sure the new health value doesnt get above the starting value of 10 o 1 / 2 of the time randomly, the attack will hit them and do[2 - 4] random damage Requirements 1) Create a Gorg class type Private string member variable for name Private int member variable for health Public constructor which initializes both member variables Public get function for the name Public get function for the health value Public boolean function called IsDefeated() o A Gorg is defeated when health <= 0 Public void function called Print() to print out the valuable object details Public void function called GetsAttacked() o The above section describes the results of when a Gorg gets attacked 2) Create a main() function which creates a Boov versus Gorg battle using these classes Create a Boov object(We will be sending one named Oh off to do all the battling) Create a Gorg object(Hes always named George, remember ? ) What percentage of the time will the Boov win the battle ? o Boov always attack first, and then the attacks go back and forth o Create a loop that uses the GetsAttacked() functions until either the Boov or Gorg is defeated o Keep track of each kind of victory o Test every one of your functions thoroughly o After 100000 simulations, how bad are the Boovs chances ? Submit your solution folder in ZIP format. */ So far I have this code. Please someone help me out! //GorgvsBoov.h:

#pragma once

#include

class GorgvsBoov { public: GorgvsBoov(const std::string & NAME); GorgvsBoov(const GorgvsBoov & rhs);

~GorgvsBoov();

std::string GetName(); int GetHealth(); static int GetCount();

bool IsDefeated(); void Print(); void GetAttacked();

GorgvsBoov & operator =(const GorgvsBoov &rhs);

private:

std::string name; int health; static int count; }; //GorgvsBoov.cpp:

#include "GorgvsBoov.h"

#include

int GorgvsBoov::count = 0;

GorgvsBoov::GorgvsBoov(const std::string & NAME) :name(NAME), health(10 + (rand() % 6)) { ++count; }

GorgvsBoov::GorgvsBoov(const GorgvsBoov & rhs) : name(rhs.name), health(rhs.health) { count++; }

GorgvsBoov::~GorgvsBoov() { --count; }

std::string GorgvsBoov::GetName() { return name;

}

int GorgvsBoov::GetHealth() { return health; }

int GorgvsBoov::GetCount() { return count; }

bool GorgvsBoov::IsDefeated() { return health <= 0; }

void GorgvsBoov::Print() { std::cout << name << ": " << health; }

void GorgvsBoov::GetAttacked() { int result = rand() % 4;

if (result == 1) { health -= 1; }

else if (result >= 2) { health -= (2 + rand() % 4); }

}

GorgvsBoov & GorgvsBoov::operator=(const GorgvsBoov & rhs) { health = rhs.health; name = rhs.name; return *this; } //Main.cpp

#include "GorgvsBoov.h" #include #include

int main() {

srand(static_cast(time(NULL)));

int rounds = 0; int battles = 1000000;

for (int i = 1; i <= battles; i++) { GorgvsBoov b("OhNo!");

while (b.IsDefeated() == false) { rounds++; b.GetAttacked(); } }

double average = rounds / static_cast(battles);

std::cout << "Average: " << average << std::endl;

system("pause"); return 0; } // This is a previous part of this question, but I already did part 1 and need to do part 2. *************************************************************************************** Gorg vs Boov Battle Part 1 Meet the Boov

The Gorg can no longer be reasoned with! Negotiations cannot go well if you have no idea what the other side wants! They are so strong and vicious that ignoring them only means Earth is indirectly conquered somehow? Its not my movie plot, but my retelling is totally butchering it for sure.

The Boov are friends of all peoples across the galaxy. Or so we are told. These beloved creatures want nothing more than peace and harmony, as long as it is their version of peace and harmony. It turns out okay for everyone in the end I suppose.

Maybe you can tell from the descriptions, but the Boov are quite the underdogs here! Captain Smek will need to simulate a Gorg battle many times over to see what their odds of victory would be.

For the first part of this simulation, lets create the Boov class. Here are their specifications.

Boov

  • Every one of them can have a different name. There is no default name for a Boov.
  • Every individual Boov starts with a health point value in the range [10-15] randomly selected
  • When a Boov gets attacked:
    • 1/4 of the time randomly, the attack does no damage
    • 1/4 of the time randomly, the attack does 1 damage
    • 1/2 of the time randomly, the attack will hit them and do [2-5] random damage

Requirements

1) Create a Boov class type

  • Private string member variable for name
  • Private int member variable for health
  • Public constructor which initializes both member variables
  • Public get function for the name
  • Public get function for the health value
  • Public boolean function called IsDefeated()
    • A Boov is defeated when health <= 0
  • Public void function called Print() to print out the valuable object details
  • Public void function called GetsAttacked()
    • The above section describes the results of when a Boov gets attacked
  • Anything missing? Let me know if there is

2) Create a main() function which creates a Boov object using this class

  • Create a Boov object (We will be sending one named OhNo off to do all the battling)
  • Test every one of your functions thoroughly
  • Create a loop that uses the GetsAttacked() function until the Boov is defeated
  • How many times on average can the Boov take damage before it is defeated?
    • Create a loop (say 100000 simulations) and find out!
    • Poor OhNo!

Submit your solution folder in ZIP format.

***************************************************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

3. Define the roles individuals play in a group

Answered: 1 week ago