Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use your knowledge of classes to implement a basic Pokmon class, including a method that determines a Pokmons vulnerability to attack! The following files are

Use your knowledge of classes to implement a basic Pokmon class, including a method that determines a Pokmons vulnerability to attack! The following files are given to you: 1. A C++ header file (pokemon.h) declaring the Pokemon class. 2. A C++ source file (main.cpp) containing a main() function with tests. Create a new C++ source file named pokemon.cpp that implements the class declared in pokemon.h so that pokemon.cpp and the provided files compile into a program that runs with no failed tests.

#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;

}

#define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__))

int main()

{

// Create a bunch of pokemon objects.

// (Data taken from the official list, plz don't sue me The Pokemon Company)

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);

Pokemon hoothoot("Hoothoot", 163, Pokemon::Flying, Pokemon::Normal);

Pokemon pikachu("Pikachu", 001, Pokemon::Normal, Pokemon::Poison);

// 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(hoothoot.name() == "Hoothoot");

test(pikachu.name() == "Pikachu");

// 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(hoothoot.Ndex() == 163);

test(pikachu.Ndex() == 001);

// 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(hoothoot.is_multitype());

test(pikachu.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(hoothoot.type1() == Pokemon::Flying);

test(pikachu.type1() == Pokemon::Normal);

// Test type2()

test(bouffalant.type2() == Pokemon::Normal);

test(cinccino.type2() == Pokemon::Normal);

test(garbodor.type2() == Pokemon::Poison);

test(mankey.type2() == Pokemon::Fighting);

test(tornadus.type2() == Pokemon::Flying);

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(hoothoot.type2() == Pokemon::Normal);

test(pikachu.type2() == Pokemon::Poison);

// Test damage_multiplier() for single-type Pokemon

test(bouffalant.damage_multiplier(Pokemon::Normal) == 1.0);

test(bouffalant.damage_multiplier(Pokemon::Fighting) == 2.0);

test(bouffalant.damage_multiplier(Pokemon::Flying) == 1.0);

test(bouffalant.damage_multiplier(Pokemon::Poison) == 1.0);

test(garbodor.damage_multiplier(Pokemon::Normal) == 1.0);

test(garbodor.damage_multiplier(Pokemon::Fighting) == 0.5);

test(garbodor.damage_multiplier(Pokemon::Flying) == 1.0);

test(garbodor.damage_multiplier(Pokemon::Poison) == 0.5);

test(mankey.damage_multiplier(Pokemon::Normal) == 1.0);

test(mankey.damage_multiplier(Pokemon::Fighting) == 1.0);

test(mankey.damage_multiplier(Pokemon::Flying) == 2.0);

test(mankey.damage_multiplier(Pokemon::Poison) == 1.0);

test(tornadus.damage_multiplier(Pokemon::Normal) == 1.0);

test(tornadus.damage_multiplier(Pokemon::Fighting) == 0.5);

test(tornadus.damage_multiplier(Pokemon::Flying) == 1.0);

test(tornadus.damage_multiplier(Pokemon::Poison) == 1.0);

// Test damage_multiplier() for multitype Pokemon

test(pidgey.damage_multiplier(Pokemon::Normal) == 1.0);

test(pidgey.damage_multiplier(Pokemon::Fighting) == 1.0);

test(pidgey.damage_multiplier(Pokemon::Flying) == 1.0);

test(pidgey.damage_multiplier(Pokemon::Poison) == 1.0);

test(fletchling.damage_multiplier(Pokemon::Normal) == 1.0);

test(fletchling.damage_multiplier(Pokemon::Fighting) == 1.0);

test(fletchling.damage_multiplier(Pokemon::Flying) == 1.0);

test(fletchling.damage_multiplier(Pokemon::Poison) == 1.0);

test(zubat.damage_multiplier(Pokemon::Normal) == 1.0);

test(zubat.damage_multiplier(Pokemon::Fighting) == 0.25);

test(zubat.damage_multiplier(Pokemon::Flying) == 1.0);

test(zubat.damage_multiplier(Pokemon::Poison) == 0.5);

test(toxicroak.damage_multiplier(Pokemon::Normal) == 1.0);

test(toxicroak.damage_multiplier(Pokemon::Fighting) == 0.5);

test(toxicroak.damage_multiplier(Pokemon::Flying) == 2.0);

test(toxicroak.damage_multiplier(Pokemon::Poison) == 0.5);

test(hawlucha.damage_multiplier(Pokemon::Normal) == 1.0);

test(hawlucha.damage_multiplier(Pokemon::Fighting) == 0.5);

test(hawlucha.damage_multiplier(Pokemon::Flying) == 2.0);

test(hawlucha.damage_multiplier(Pokemon::Poison) == 1.0);

test(hoothoot.damage_multiplier(Pokemon::Normal) == 1.0);

test(hoothoot.damage_multiplier(Pokemon::Fighting) == 1.0);

test(hoothoot.damage_multiplier(Pokemon::Flying) == 1.0);

test(hoothoot.damage_multiplier(Pokemon::Poison) == 1.0);

test(pikachu.damage_multiplier(Pokemon::Normal) == 1.0);

test(pikachu.damage_multiplier(Pokemon::Fighting) == 1.0);

test(pikachu.damage_multiplier(Pokemon::Flying) == 1.0);

test(pikachu.damage_multiplier(Pokemon::Poison) == 0.5);

cout << "Assignment complete." << endl;

}

#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();

// If the Pokemon has two types, returns the second type of the Pokemon.

// Otherwise returns the Pokemon's only type.

Type type2();

// The damage multiplier of a move against a Pokemon

// is the product of the multipliers for each of the Pokemon's types.

// Reference: http://bulbapedia.bulbagarden.net/wiki/Type/Type_chart#Generation_I

// See the above chart (for Generation I) to understand the examples below.

// Rows represent: Attacking types

// Columns represent: Pokemon defending types

// Normal attacks: 1.0 against all Pokemon defending types.

// Fighting attacks: 2.0 against Normal, 0.5 against Flying or Poison, 1.0 against Fighting.

// Flying attacks: 1.0 against all defending types except Fighting, 2.0 against Fighting.

// Poison attacks: 1.0 against all types except Poison, 0.5 against Poison.

// Example 1: if the attack type is Fighting against a Pokemon with Normal and Flying defending types (2 types)

// the damage multiplier is 1.0 (results from multiplying 2.0 * 0.5).

// Example 2: if the attack type is Poison against a Pokemon with the Poison defending type (only 1 type)

// the damage multiplier is 0.5 (there is only one type).

// 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]; // Array's 1st element stores type 1. When there is a second type, array's 2nd element stores type 2

int type_count; // Stores the Pokemon's quantity of types (1 or 2)

};

#endif

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago