Question: Create a basic c++ pokemon.cpp file based on the pokemon.h and main.cpp files. Make sure you use the chart provided on the website for float
Create a basic c++ pokemon.cpp file based on the pokemon.h and main.cpp files. Make sure you use the chart provided on the website for float damage_multiplier(Type attack_type);. Everything is provided
just need to create the methods and functions for pokemon.cpp file.
//This is pokemon.h file #ifndef POKEMON_H #define POKEMON_H #include using namespace std; class Pokemon { public: // This works like a custom type with just four values. // Inside Pokemon methods, reference them by their names, e.g.: // "if (x == Fighting)", "if (y != Poison)", etc. enum Type {Normal, Fighting, Flying, Poison}; // Initializes a single-type Pokemon using the information provided Pokemon(string name, int ndex, Type type1); // Initializes a multi-type Pokemon using the information provided Pokemon(string name, int ndex, Type type1, Type type2); // Returns the name of the pokemon string name(); // Returns the Ndex (national index) of the Pokemon int Ndex(); // Returns the first (and possibly only) type of the Pokemon Type type1(); // Returns whether the Pokemon has multiple types bool is_multitype(); // Returns the second type of the Pokemon (if it has one) // and otherwise the Pokemon's only type Type type2(); // The damage multiplier of a move against a Pokemon // is the product of the multiplier for each of the Pokemon's types. // Reference: http://bulbapedia.bulbagarden.net/wiki/Type/Type_chart#Generation_I // Example 1: a move with a 2.0 multiplier against Fighting and Flying Pokemon // has a 4.0 multiplier against a Pokemon that is both Fighting and Flying. // Example 2: a move with a 0.5 multiplier against Flying and Poison Pokemon // has a 0.5 multiplier against a Pokemon that is both Flying and Poison. // Normal moves: 1.0 against all Pokemon types. // Fighting moves: 2.0 against Normal, 0.5 against Flying and Poison, 1.0 against Fighting. // Flying moves: 1.0 against all types except Fighting, 2.0 against Fighting. // Poison moves: 1.0 against all types except Poison, 0.5 against Poison. // Returns the damage multiplier against this Pokemon // for a move of the parameter type. float damage_multiplier(Type attack_type); private: int _ndex; // Stores the Pokemon's Ndex string _name; // Stores the Pokemon's name Type types[2]; // Stores the Pokemon's types (1 or 2 of them) int type_count; // Stores how many types the Pokemon has }; #endif //This is the main.cpp file #include #include #include "pokemon.h" using namespace std; inline void _test(const char* expression, const char* file, int line) { cerr << "test(" << expression << ") failed in file " << file << ", line " << line << "." << endl; abort(); } #define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__)) int main() { // pokemon objects. Pokemon bouffalant("Bouffalant", 626, Pokemon::Normal); Pokemon cinccino("Cinccino", 573, Pokemon::Normal); Pokemon garbodor("Garbodor", 569, Pokemon::Poison); Pokemon mankey("Mankey", 56, Pokemon::Fighting); Pokemon tornadus("Tornadus", 641, Pokemon::Flying); Pokemon pidgey("Pidgey", 16, Pokemon::Normal, Pokemon::Flying); Pokemon fletchling("Fletchling", 661, Pokemon::Normal, Pokemon::Flying); Pokemon zubat("Zubat", 41, Pokemon::Poison, Pokemon::Flying); Pokemon toxicroak("Toxicroak", 454, Pokemon::Poison, Pokemon::Fighting); Pokemon hawlucha("Hawlucha", 701, Pokemon::Fighting, Pokemon::Flying); // Test name() test(bouffalant.name() == "Bouffalant"); test(cinccino.name() == "Cinccino"); test(garbodor.name() == "Garbodor"); test(mankey.name() == "Mankey"); test(tornadus.name() == "Tornadus"); test(pidgey.name() == "Pidgey"); test(fletchling.name() == "Fletchling"); test(zubat.name() == "Zubat"); test(toxicroak.name() == "Toxicroak"); test(hawlucha.name() == "Hawlucha"); // Test Ndex() test(bouffalant.Ndex() == 626); test(cinccino.Ndex() == 573); test(garbodor.Ndex() == 569); test(mankey.Ndex() == 56); test(tornadus.Ndex() == 641); test(pidgey.Ndex() == 16); test(fletchling.Ndex() == 661); test(zubat.Ndex() == 41); test(toxicroak.Ndex() == 454); test(hawlucha.Ndex() == 701); // Test is_multitype() test(!bouffalant.is_multitype()); test(!cinccino.is_multitype()); test(!garbodor.is_multitype()); test(!mankey.is_multitype()); test(!tornadus.is_multitype()); test(pidgey.is_multitype()); test(fletchling.is_multitype()); test(zubat.is_multitype()); test(toxicroak.is_multitype()); test(hawlucha.is_multitype()); // Test type1() test(bouffalant.type1() == Pokemon::Normal); test(cinccino.type1() == Pokemon::Normal); test(garbodor.type1() == Pokemon::Poison); test(mankey.type1() == Pokemon::Fighting); test(tornadus.type1() == Pokemon::Flying); test(pidgey.type1() == Pokemon::Normal); test(fletchling.type1() == Pokemon::Normal); test(zubat.type1() == Pokemon::Poison); test(toxicroak.type1() == Pokemon::Poison); test(hawlucha.type1() == Pokemon::Fighting); // Test type2() test(pidgey.type2() == Pokemon::Flying); test(fletchling.type2() == Pokemon::Flying); test(zubat.type2() == Pokemon::Flying); test(toxicroak.type2() == Pokemon::Fighting); test(hawlucha.type2() == Pokemon::Flying); // Test damage_multiplier() for single-type Pokemon test(bouffalant.damage_multiplier(Pokemon::Normal) == 1.0f); test(bouffalant.damage_multiplier(Pokemon::Fighting) == 2.0f); test(bouffalant.damage_multiplier(Pokemon::Flying) == 1.0f); test(bouffalant.damage_multiplier(Pokemon::Poison) == 1.0f); test(garbodor.damage_multiplier(Pokemon::Normal) == 1.0f); test(garbodor.damage_multiplier(Pokemon::Fighting) == 0.5f); test(garbodor.damage_multiplier(Pokemon::Flying) == 1.0f); test(garbodor.damage_multiplier(Pokemon::Poison) == 0.5f); test(mankey.damage_multiplier(Pokemon::Normal) == 1.0f); test(mankey.damage_multiplier(Pokemon::Fighting) == 1.0f); test(mankey.damage_multiplier(Pokemon::Flying) == 2.0f); test(mankey.damage_multiplier(Pokemon::Poison) == 1.0f); test(tornadus.damage_multiplier(Pokemon::Normal) == 1.0f); test(tornadus.damage_multiplier(Pokemon::Fighting) == 0.5f); test(tornadus.damage_multiplier(Pokemon::Flying) == 1.0f); test(tornadus.damage_multiplier(Pokemon::Poison) == 1.0f); // Test damage_multiplier() for multitype Pokemon test(pidgey.damage_multiplier(Pokemon::Normal) == 1.0f); test(pidgey.damage_multiplier(Pokemon::Fighting) == 1.0f); test(pidgey.damage_multiplier(Pokemon::Flying) == 1.0f); test(pidgey.damage_multiplier(Pokemon::Poison) == 1.0f); test(zubat.damage_multiplier(Pokemon::Normal) == 1.0f); test(zubat.damage_multiplier(Pokemon::Fighting) == 0.25f); test(zubat.damage_multiplier(Pokemon::Flying) == 1.0f); test(zubat.damage_multiplier(Pokemon::Poison) == 0.5f); test(toxicroak.damage_multiplier(Pokemon::Normal) == 1.0f); test(toxicroak.damage_multiplier(Pokemon::Fighting) == 0.5f); test(toxicroak.damage_multiplier(Pokemon::Flying) == 2.0f); test(toxicroak.damage_multiplier(Pokemon::Poison) == 0.5f); test(hawlucha.damage_multiplier(Pokemon::Normal) == 1.0f); test(hawlucha.damage_multiplier(Pokemon::Fighting) == 0.5f); test(hawlucha.damage_multiplier(Pokemon::Flying) == 2.0f); test(hawlucha.damage_multiplier(Pokemon::Poison) == 1.0f); cout << "Assignment complete." << endl; Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
