Question: need help with podex.cpp and pokemon.cpp MY POKEMON.CPP #include pokemon.h #include / / Constructor for Pok mon with one type Pokemon::Pokemon ( string name,

need help with podex.cpp and pokemon.cpp
MY POKEMON.CPP
#include "pokemon.h"
#include
// Constructor for Pokmon with one type
Pokemon::Pokemon(string name, int ndex, Type type1)
: _ndex(ndex),_name(name), type_count(1){
types[0]= type1;
}
// Constructor for Pokmon with two types
Pokemon::Pokemon(string name, int ndex, Type type1, Type type2)
: _ndex(ndex),_name(name), type_count(2){
types[0]= type1;
types[1]= type2;
}
// Constructor that initializes a Pokmon from a summary string
Pokemon::Pokemon(string summary){
stringstream ss(summary);
string temp_name, temp_ndex_str, temp_type1, temp_type2;
getline(ss, temp_name, ',');
_name = temp_name;
getline(ss, temp_ndex_str,',');
_ndex = stoi(temp_ndex_str.substr(1)); // Remove the '#' and convert to int
getline(ss, temp_type1,',');
types[0]= string_to_type(temp_type1);
if (getline(ss, temp_type2,',')){// Check if there's a second type
types[1]= string_to_type(temp_type2);
type_count =2;
} else {
type_count =1;
}
}
// Returns the name of the Pokmon
string Pokemon::name(){
return _name;
}
// Returns the Ndex number of the Pokmon
int Pokemon::Ndex(){
return _ndex;
}
// Returns the first type of the Pokmon
Pokemon::Type Pokemon::type1(){
return types[0];
}
// Checks if the Pokmon has two types
bool Pokemon::is_multitype(){
return type_count ==2;
}
// Returns the second type of the Pokmon or the first type if it has only one type
Pokemon::Type Pokemon::type2(){
return is_multitype()? types[1] : types[0];
}
// Calculates the damage multiplier for a given attack type
float Pokemon::damage_multiplier(Type attack_type){
float multiplier =1.0;
if (attack_type == Normal){
return 1.0;
} else if (attack_type == Fighting){
if (type1()== Normal || type2()== Normal){
multiplier *=2.0;
}
if (type1()== Flying || type2()== Flying || type1()== Poison || type2()== Poison){
multiplier *=0.5;
}
} else if (attack_type == Flying){
if (type1()== Fighting || type2()== Fighting){
multiplier *=2.0;
}
} else if (attack_type == Poison){
if (type1()== Poison || type2()== Poison){
multiplier *=0.5;
}
}
return multiplier;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!