Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Add pokemon to Pokedex, keep the Pokedex list sorted // Can have multiple pokemon with the same name // Pokemon is not inserted if

// Add pokemon to Pokedex, keep the Pokedex list sorted

// Can have multiple pokemon with the same name

// Pokemon is not inserted if Pokedex is already full

void insert(const string &pokemon); // Need help writing code for this function

private:

// maximum capacity of Pokedex

static const int MAX = 10;

// sorted list of pokemon in Pokedex

string pokemons[MAX];

// current internal size

int msize = 0;

test code:

okedex pdx;

stringstream strs;

// // NOLINTNEXTLINE - would normally use empty

assert(pdx.size() == 0);

assert(pdx.empty());

strs << pdx;

assert(strs.str() == "[]");

cout << "test1 complete" << endl;

}

void test2() {

Pokedex pdx;

stringstream strs;

pdx.insert("Pikachu");

assert(pdx.size() == 1);

assert(!pdx.empty());

assert(pdx.at(0) == "Pikachu");

assert(pdx.front() == pdx.back());

strs.str("");

strs << pdx;

assert(strs.str() == "[Pikachu]");

cout << "test2 complete" << endl;

}

void test3() {

Pokedex pdx;

stringstream strs;

pdx.insert("Pikachu");

pdx.insert("Charmander");

assert(pdx.size() == 2);

assert(pdx.at(0) == pdx.front());

assert(pdx.at(1) == pdx.back());

strs.str("");

strs << pdx;

assert(strs.str() == "[Charmander, Pikachu]");

pdx.erase(0);

assert(pdx.front() == pdx.back());

strs.str("");

strs << pdx;

assert(strs.str() == "[Pikachu]");

cout << "test3 complete" << endl;

}

void test4() {

Pokedex pdx;

stringstream strs;

pdx.insert("Charmander");

pdx.insert("Pikachu");

pdx.insert("Bulbasaur");

strs << pdx;

assert(strs.str() == "[Bulbasaur, Charmander, Pikachu]");

pdx.erase(1);

strs.str("");

strs << pdx;

assert(strs.str() == "[Bulbasaur, Pikachu]");

cout << "test4 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

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago