Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you change this code to use another method instead of pointers? Please pokemon.cpp==================== #include pokemon.h #include #include using namespace std; inline void _test(const char*

Can you change this code to use another method instead of pointers? Please

pokemon.cpp====================

#include "pokemon.h" #include #include 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__))

Pokemon::Pokemon(string name, int ndex, Type type1){ this->_name=name; this->_ndex=ndex; this->types[0]=type1; this->type_count=1; }

Pokemon::Pokemon(string name, int ndex, Type type1, Type type2){ this->_name=name; this->_ndex=ndex; this->types[0]=type1; this->types[1]=type2; this->type_count=2; }

string Pokemon::name(){ return _name; }

int Pokemon::Ndex(){ return _ndex; }

Pokemon::Type Pokemon::type1(){ return types[0]; }

bool Pokemon::is_multitype(){ if(type_count==1){ return false; } return true; }

Pokemon::Type Pokemon::type2(){ return types[1]; }

float Pokemon::damage_multiplier(Type attack_type){ //For all cases where damage multiplier gets 1, we don't need to explicitly put it. //So we will skip all cases where multiplier becomes 1 //Also, its safe to iterate that way, as X*1 = X float damageMultiplier=1; int i=0;

int iterations=1; //If multitype, we need to go through the same conditions twice if(is_multitype()) iterations =2; //Will execute twice if its multitype, once with type one, and then type two for(i=0;i

//For poison type attack else if(attack_type==Poison){ if(types[i]==Poison){ damageMultiplier*=0.5; } //Skipped all except poison, as they make it 1 }

} return damageMultiplier; }

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

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

Students also viewed these Databases questions

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago