Question: To the code below I have to do the following. 3. Call a function to display the inventory. 4. Create pointers. 5. Create references. 6.
To the code below I have to do the following.
3. Call a function to display the inventory.
4. Create pointers.
5. Create references.
6. Create a Hero object.
7. Create a health level for the Hero.
8. Announce the Hero and his/her health level
//Hero's Inventory 3.0
//Demonstrates iterators
#include
#include
#include
using namespace std;
int main()
{
vector
inventory.push_back("Handcannon");
inventory.push_back("Rifle");
inventory.push_back("RiotGear");
vector
vector
cout << "Your Iteems: ";
for (iter = inventory.begin(); iter != inventory.end(); ++iter)
{
cout << *iter << endl;
}
cout << " You trade your handcannon for a combat knife.";
myIterator = inventory.begin();
*myIterator = "Combat Knife";
cout << " Your items: ";
for (iter = inventory.begin(); iter != inventory.end(); ++iter)
{
cout << *iter << endl;
}
cout << " The item name' "<<*myIterator<<"' has ";
cout << (*myIterator).size() << " letter in it. ";
cout << " The item name' " << *myIterator << "' has ";
cout << myIterator->size() << " letters in it. ";
cout << " You recover a Auto-Rifle from a slain enemy.";
inventory.insert(inventory.begin(), "Auto-Rifle");
cout << " Your items: ";
for (iter = inventory.begin(); iter != inventory.end(); ++iter)
{
cout << *iter << endl;
}
cout << " Your RiotGear is destroyed in a fierce battle.";
inventory.erase((inventory.begin() + 2));
cout << " Your items: ";
for (iter = inventory.begin(); iter != inventory.end(); ++iter)
{
cout << *iter << endl;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
