Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have an issue compiling. Can someone help? Im getting the following error: pok

ID: 3721418 • Letter: I

Question

I have an issue compiling. Can someone help? Im getting the following error:

pokemon.cpp:65:31: error: expected ';' at end of declaration

Pokedex* newMode = new Pokedex{NULL,NULL};

^

;

pokemon.cpp:105:30: error: expected ';' at end of declaration

Pokedex* newOne = new Pokedex{p,list};

   ^

   ;

pokemon.cpp:145:8: warning: generalized initializer lists are a C++11 extension

[-Wc++11-extensions]

return {name,0,-damage,0,0,0,0};

   ^~~~~~~~~~~~~~~~~~~~~~~~

pokemon.cpp:153:7: warning: generalized initializer lists are a C++11 extension

[-Wc++11-extensions]

return{name,hp,0,0,0,0,0};

Below is my code (I am using GCC on a Mac)

#include<iostream>

#include<string>

using namespace std;

struct Move

{

string name;

int selfHPEffect;

int otherHPEffect;

int selfAtkEffect;

int otherAtkEffect;

int selfDefEffect;

int otherDefEffect;

};

struct Pokemon

{

string name;

string type;

int centimeterHeight;

int gramWeight;

int hp;

int attack;

int defense;

Move move1;

Move move2;

};

struct Pokedex

{

Pokemon* p;

Pokedex* rest;

};

Pokedex* empty()

{

Pokedex* newMode = new Pokedex{NULL,NULL};

return newMode;

}

bool isEmpty(Pokedex* head)

{

return head->p == NULL;

}

int length(Pokedex* one)

{

if (isEmpty(one))

{

return 0;

}

else

{

return 1 + length(one->rest);

}

}

Pokedex* prepend(Pokemon* p, Pokedex* list)

{

Pokedex* newOne = new Pokedex{p,list};

return newOne;

}

string shortDescription (Pokemon* p)

{

return p-> name + " (" + p->type + " )";

}

string index (Pokedex* head)

{

if (isEmpty(head))

{

return "";

}

else

{

return shortDescription(head->p) + " " + index(head->rest);

}

}

Move simpleAttack(string name, int damage)

{

return {name,0,-damage,0,0,0,0};

}

Move healMove(string name, int hp)

{

return{name,hp,0,0,0,0,0};

}

int main()

{

Pokemon Charmander= {"Charmander","Fire" ,71, 16, 78, 75, 75, simpleAttack("Flame",75), healMove("Heal",60)};

Pokemon Tepig={"Tepig", "Fire", 71, 25, 65, 85, 50, simpleAttack("Flamethrower",85), healMove("Recover",65)};

Pokemon Vaporeon={"Vaporeon", "Water", 61, 17, 60, 69, 69, simpleAttack("Tsunami",60), healMove("Recover",60)};

Pokemon Charizard={"Charizard", "Fire", 71, 8, 39, 52, 43, simpleAttack("Blaze",39), healMove("Cure",25)};

Pokemon Moltres={"Moltres", "Fire", 170, 90, 78, 84, 78, simpleAttack("Solar Power",84), healMove("Safeguard",60)};

Pokedex* head = empty();

head=prepend(&Charmander, prepend(&Tepig, prepend(&Vaporeon,prepend(&Charizard, prepend(&Moltres, empty())))));

cout<< "There are " << length(head) << " Pokemons in the pokedex: " << endl;

cout<< index(head) << endl;

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

struct Move

{

string name;

int selfHPEffect;

int otherHPEffect;

int selfAtkEffect;

int otherAtkEffect;

int selfDefEffect;

int otherDefEffect;

};

struct Pokemon

{

string name;

string type;

int centimeterHeight;

int gramWeight;

int hp;

int attack;

int defense;

Move move1;

Move move2;

};

struct Pokedex

{

Pokemon* p;

Pokedex* rest;

};

Pokedex* empty()

{

Pokedex* newMode = new Pokedex;

newMode->p = NULL;

newMode->rest = NULL;

return newMode;

}

bool isEmpty(Pokedex* head)

{

return head->p == NULL;

}

int length(Pokedex* one)

{

if (isEmpty(one))

{

return 0;

}

else

{

return 1 + length(one->rest);

}

}

Pokedex* prepend(Pokemon* p, Pokedex* list)

{

Pokedex* newOne = new Pokedex;

newOne->p = p;

newOne->rest = list;

return newOne;

}

string shortDescription (Pokemon* p)

{

return p-> name + " (" + p->type + " )";

}

string index (Pokedex* head)

{

if (isEmpty(head))

{

return "";

}

else

{

return shortDescription(head->p) + " " + index(head->rest);

}

}

Move simpleAttack(string name, int damage)

{

    struct Move ob;

   

    ob.name = name;

    ob.selfHPEffect = 0;

    ob.otherHPEffect = -damage;

    ob.selfAtkEffect = 0;

    ob.otherAtkEffect = 0;

    ob.selfDefEffect = 0;

    ob.otherDefEffect = 0;

   

    return ob;

}

Move healMove(string name, int hp)

{

    struct Move ob;

   

    ob.name = name;

    ob.selfHPEffect = hp;

    ob.otherHPEffect = 0;

    ob.selfAtkEffect = 0;

    ob.otherAtkEffect = 0;

    ob.selfDefEffect = 0;

    ob.otherDefEffect = 0;

   

    return ob;

}

int main()

{

Pokemon Charmander= {"Charmander","Fire" ,71, 16, 78, 75, 75, simpleAttack("Flame",75), healMove("Heal",60)};

Pokemon Tepig={"Tepig", "Fire", 71, 25, 65, 85, 50, simpleAttack("Flamethrower",85), healMove("Recover",65)};

Pokemon Vaporeon={"Vaporeon", "Water", 61, 17, 60, 69, 69, simpleAttack("Tsunami",60), healMove("Recover",60)};

Pokemon Charizard={"Charizard", "Fire", 71, 8, 39, 52, 43, simpleAttack("Blaze",39), healMove("Cure",25)};

Pokemon Moltres={"Moltres", "Fire", 170, 90, 78, 84, 78, simpleAttack("Solar Power",84), healMove("Safeguard",60)};

Pokedex* head = empty();

head=prepend(&Charmander, prepend(&Tepig, prepend(&Vaporeon,prepend(&Charizard, prepend(&Moltres, empty())))));

cout<< "There are " << length(head) << " Pokemons in the pokedex: " << endl;

cout<< index(head) << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote