// Test - Display inventory
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Invent {
public:
void Invent::displayInventory();
void Invent::addItem(string item);
void Invent::removeItem(string item);
private:
vector<string> Inventory;
vector<string>::const_iterator iter;
};
int main() {
Invent invent;
unsigned int userChoice;
bool quit = false;
cout << "\nWelcome to your item inventory" << endl;
while (quit == false) {
cout << "\n1. Display inventory" << endl;
cout << "2. Add item" << endl;
cout << "3. Remove item" << endl;
cout << "4. Quit\n" << endl;
cout << "Option: ";
cin >> userChoice;
string item = "";
switch (userChoice) {
case 1:
invent.displayInventory();
break;
case 2:
cout << "\nPlease type the item name: ";
cin.get();
getline(cin, item);
invent.addItem(item);
break;
case 3:
cout << "\nPlease type the item name to remove: ";
cin.get();
getline(cin, item);
invent.removeItem(item);
break;
case 4:
quit = true;
break;
default:
cout << "\nYou entered an incorrect value!\n";
break;
}
}
}
void Invent::displayInventory() {
if (Inventory.empty()) {
cout << "\nSorry but your inventory is currently empty.\n";
}
else {
cout << "\nDisplaying all the current items in your inventory.\n" << endl;
for (iter = Inventory.begin(); iter != Inventory.end(); ++iter) {
cout << "- " << *iter << endl;
}
}
}
void Invent::addItem(string item) {
Inventory.push_back(item);
cout << "\nThe item \"" << item << "\" was successfully added to your inventory." << endl;
}
void Invent::removeItem(string item) {
iter = find(Inventory.begin(), Inventory.end(), item);
if (iter != Inventory.end()) {
}
}