This code sets up a battle.cpp program that will interact with the Grog class (Grog.h and Grog.cpp). This class is currently functioning, as is the driver file (battle.cpp), so you should be able to...


This code sets up a battle.cpp program that will interact with the Grog class (Grog.h and Grog.cpp). This class is currently functioning, as is the driver file (battle.cpp), so you should be able to run this once you download it and see the output from two Grogs that are created and a test of some of the functionality.


You will take the battle.cpp file and follow the commented instructions to do the following: create a vector of 10 PRG Grogs, have them battle in a single-elimination round, and save the five winners. These five will fight in a round robin match where each Grog fights each other Grog at least twice, recording wins and losses. This will leave you with 5 ranked Grogs, and you will select the top 2 to battle for the ultimate champion. YOU WILL likely have to figure out a method to break ties - largest margin of victory, best HP remaining in a battle, etc., you pick what makes sense to you.


There are several elements that you will want to create, and some of these involve making changes to the Grog class files, so think them through before you start coding.




#include #include #include #include #include #include using namespace std; class Grog{ public: string name; Grog(); void setHP(int hpIn); //mutator int getHP(); //accessor void setStrength(int strengthIn); int getStrength(); void setArmor(int armorIn); int getArmor(); void setDamage(float damageIn); float getDamage(); void show(); friend ostream& operator<(ostream& out,="" grog&="" grogin);="" friend="" bool="" operator="">(Grog lhGrog, Grog rhGrog); // grog1 > grog2 friend bool operator<(grog lhgrog,="" grog="" rhgrog);="" private:="" int="" hp;="" int="" strength;="" int="" armor;="" float="" damage;="" };="" #include=""> #include #include #include #include #include #include "Grog.h" using namespace std; Grog::Grog(){ //generate a name //generate HP //generate strength //generate armor //calculate damage using your own formulation or mine if you wish } void Grog::setHP(int hpIn){ hp = hpIn; } //mutator int Grog::getHP(){ return hp; }//accessor void Grog::setStrength(int strengthIn){ strength = strengthIn; } int Grog::getStrength(){ return strength; } void Grog::setArmor(int armorIn){ armor = armorIn; } int Grog::getArmor(){ return armor; } void Grog::setDamage(float damageIn){ damage = damageIn; } float Grog::getDamage(){ return damage; } void Grog::show(){ cout < "monster="" :="" "="">< name="">< endl;="" cout="">< "\t\t:="" "="">< hp="">< endl;="" cout="">< "\t\t:="" "="">< strength="">< endl;="" cout="">< "\t\t:="" "="">< armor="">< endl;="" cout="">< "\t\t:="" "="">< damage="">< endl;="" }="" ostream&=""><(ostream& out,="" grog&="" grogin){="" out="">< "monster="" :="" "="">< grogin.name="">< endl;="" out="">< "\t\t:="" "="">< grogin.gethp()="">< endl;="" out="">< "\t\t:="" "="">< grogin.getstrength()="">< endl;="" out="">< "\t\t:="" "="">< grogin.getarmor()="">< endl;="" out="">< "\t\t:="" "="">< grogin.getdamage()="">< endl;="" return="" out;="" }="" bool="" operator="">(Grog lhGrog, Grog rhGrog){ if (lhGrog.getHP() > rhGrog.getHP()) return true; else if (lhGrog.getHP() < rhgrog.gethp())="" return="" false;="" else="" return="" false;="" }="" bool=""><(grog lhgrog,="" grog="" rhgrog){="" if="" (lhgrog.gethp()="">< rhgrog.gethp())="" return="" true;="" else="" if="" (lhgrog.gethp()=""> rhGrog.getHP()) return false; else return false; } // D. Michael Franklin // MTRE 2610 - Intermediate Programming // Lab 1B - Grog Battle //include files #include #include #include #include #include #include //Our custom class #include "Grog.cpp" //define the namespace as standard using namespace std; //program start int main(){ srand(time(NULL)); cout < "welcome="" to="" battle!"="">< endl;="" test="" the="" class="" grog="" grog="" test;="" test.name="KONTROL" ;="" test.sethp(100);="" test.setstrength(10);="" test.setarmor(60);="" test.setdamage(test.gethp()="" *="" test.getstrength()="" (float)="" test.getarmor());="" grog="" test2;="" test2.name="KILLER" ;="" test2.sethp(90);="" test2.setstrength(12);="" test2.setarmor(70);="" test2.setdamage(test2.gethp()="" *="" test2.getstrength()="" (float)="" test2.getarmor());="" test="" the="" basic="" show="" function="" (later="" replaced="" with=""><) test.show();="" test="" output="" using="">< cout="">< test="">< endl;="" cout="">< test2="">< endl;="" test="" operator=""> and operator< if="" (test=""> test2) { cout < test.name="">< "="" is="" the="" best!"="">< endl;="" }="" else="" {="" cout="">< test2.name="">< "="" is="" the="" best!"="">< endl; } //======================================================== //start coding here // //instantiate a vector of 10 grogs, initialize each with prg data using a default constructor //output the grog with: //1. highest hp //2. highest strength //3. lowest armor //find the strongest grog! //choose two grogs at a time, without repitition, to battle. save the victors in a new vector //to battle, implement a hit function within the grog class and a takehit function as follows: //1. hit - generate prg amount of damage based on strength and hp and some randomness //2. takehit - receives a hit amount into the function, reduces that by the armor amount with some // proportion that you figure out (your call on how that works), and subtracts that // from the grog's hp until zero or less. winner is last one with hp, or the least // negative hp if both are below 0. use a checkwinner function for this that you write. //once you have a vector of 5 winners, figure out an algorithm to have them fight round robin // (each fights each other at least twice) - you may want to modify your class to include wins // and losses to keep count of the wins and losses during this round. the top two from this // round move to the final and battle each other directly for a winner. figure out a method // to deal with ties if needed, including a tiebreaker if required. //show the victorious grog and it's record of wins and losses //submit your three files - battle.cpp, grog.h, grog.cpp return 0; } endl;="" }="" =="======================================================" start="" coding="" here="" instantiate="" a="" vector="" of="" 10="" grogs,="" initialize="" each="" with="" prg="" data="" using="" a="" default="" constructor="" output="" the="" grog="" with:="" 1.="" highest="" hp="" 2.="" highest="" strength="" 3.="" lowest="" armor="" find="" the="" strongest="" grog!="" choose="" two="" grogs="" at="" a="" time,="" without="" repitition,="" to="" battle.="" save="" the="" victors="" in="" a="" new="" vector="" to="" battle,="" implement="" a="" hit="" function="" within="" the="" grog="" class="" and="" a="" takehit="" function="" as="" follows:="" 1.="" hit="" -="" generate="" prg="" amount="" of="" damage="" based="" on="" strength="" and="" hp="" and="" some="" randomness="" 2.="" takehit="" -="" receives="" a="" hit="" amount="" into="" the="" function,="" reduces="" that="" by="" the="" armor="" amount="" with="" some="" proportion="" that="" you="" figure="" out="" (your="" call="" on="" how="" that="" works),="" and="" subtracts="" that="" from="" the="" grog's="" hp="" until="" zero="" or="" less.="" winner="" is="" last="" one="" with="" hp,="" or="" the="" least="" negative="" hp="" if="" both="" are="" below="" 0.="" use="" a="" checkwinner="" function="" for="" this="" that="" you="" write.="" once="" you="" have="" a="" vector="" of="" 5="" winners,="" figure="" out="" an="" algorithm="" to="" have="" them="" fight="" round="" robin="" (each="" fights="" each="" other="" at="" least="" twice)="" -="" you="" may="" want="" to="" modify="" your="" class="" to="" include="" wins="" and="" losses="" to="" keep="" count="" of="" the="" wins="" and="" losses="" during="" this="" round.="" the="" top="" two="" from="" this="" round="" move="" to="" the="" final="" and="" battle="" each="" other="" directly="" for="" a="" winner.="" figure="" out="" a="" method="" to="" deal="" with="" ties="" if="" needed,="" including="" a="" tiebreaker="" if="" required.="" show="" the="" victorious="" grog="" and="" it's="" record="" of="" wins="" and="" losses="" submit="" your="" three="" files="" -="" battle.cpp,="" grog.h,="" grog.cpp="" return="" 0;="">
Jun 19, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here