#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; } }; class List { protected: Link * first; Link * last; public: List() { first = NULL; last = NULL; } item * find(string des) { Link * list = first; while (list != NULL) { if (list->data->descr == des) return list->data; list = list->next; } return NULL; } void add_to_end(item * it) { if (first == NULL) { first = new Link(it, first); last = first; return; } last->next = new Link(it, NULL); last = last->next; } void add_to_front(item * it) { if (first == NULL) { first = new Link(it, first); last = first; return; } first = new Link(it, first); } void print() { Link * ptr = first; while (ptr != NULL) { ptr->data->print(); ptr = ptr->next; } } int totalprice() { Link * list = first; int total = 0; while (list != NULL) { total += list->data->price; list = list->next; } return total; } }; int main() { List stock; stock.add_to_end(new item("chicken", 1000)); stock.add_to_end(new item("owl poison", 2199)); stock.add_to_end(new item("scum", 98)); stock.add_to_end(new item("nitrogen", 3267)); stock.add_to_end(new item("things", 67)); stock.add_to_end(new item("beaks", 399)); List hand; while (true) { string s; getline(cin, s); if (s == "stop") break; item * it = stock.find(s); if (it == NULL) { cout << "Can't find it\n"; continue; } hand.add_to_end(it); } hand.print(); cout << "Total price is " << hand.totalprice() << "\n"; }