#include #include #include using namespace std; struct item { string descr; int price; item(string d, int p) { descr = d; price = p; } void print() { cout << descr << " @ " << price << "cents\n"; } }; struct Link { item * data; Link * next; Link(item * d, Link * n = NULL) { data = d; next = n; } }; item * find(vector & stuff, string des) { for (int i = 0; i < stuff.size(); i += 1) if (stuff[i]->descr == des) return stuff[i]; return NULL; } void add(Link * & list, item * it) { list = new Link(it, list); } int main() { vector stock; stock.push_back(new item("chicken", 1000)); stock.push_back(new item("owl poison", 2199)); stock.push_back(new item("scum", 98)); stock.push_back(new item("nitrogen", 3267)); stock.push_back(new item("things", 67)); stock.push_back(new item("beaks", 399)); Link * hand = NULL; while (true) { string s; getline(cin, s); if (s == "stop") break; item * it = find(stock, s); if (it == NULL) { cout << "Can't find it\n"; continue; } add(hand, it); } print(hand); cout << "Total price is " << totalprice(hand) << "\n"; }