#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) { data = d; next = n; } }; void add(Link * & head, item * it) { head = new Link(it, head); } void printlist(Link * ptr) { while (ptr != NULL) { ptr->data->print(); ptr = ptr->next; } } item * find(Link * ptr, string name) { while (ptr != NULL) { if (ptr->data->descr == name) return ptr->data; ptr = ptr->next; } return NULL; } int main() { Link * stock = NULL; add(stock, new item("chicken", 1000)); add(stock, new item("owl poinson", 2199)); add(stock, new item("scum", 98)); add(stock, new item("nitrogen", 3267)); add(stock, new item("things", 67)); add(stock, new item("beaks", 399)); Link * list = NULL; while (true) { string s; cout << "What do you want to buy? "; cin >> s; if (s == "end") break; item * it = find(stock, s); if (it == NULL) cout << "no such thing in stock\n"; else add(list, it); } cout << "you are buying: \n"; printlist(list); }