#include #include #include using namespace std; struct item { string description; int upc; int price; item(string d, int u, int p) { description = d; upc = u; price = p; } void print() { cout << description << ", upc=" << upc << ", " << price << "c\n"; } }; struct Link { item * data; Link * next; Link(item * i, Link * n) { data = i; next = n; } }; class List { protected: Link * first; public: List() { first = NULL; } void add(item * i) { first = new Link(i, first); } void print() { Link * ptr = first; while (ptr != NULL) { ptr->data->print(); ptr = ptr->next; } } item * find(string d) { Link * ptr = first; while (ptr != NULL) { if (d == ptr->data->description) return ptr->data; ptr = ptr->next; } return NULL; } void delete_all() { Link * ptr = first; while (ptr != NULL) { delete ptr->data; ptr = ptr->next; } } ~List() { while (first != NULL) { Link * follower = first->next; delete first; first = follower; } } }; int main() { List L; ifstream fin("input"); while (true) { string desc; int up, pr; fin >> desc >> up >> pr; if (fin.fail()) break; item * i = new item(desc, up, pr); L.add(i); } fin.close(); cout << "Inventory:\n"; L.print(); cout << "End of list\n"; int total = 0; while (true) { cout << "Item and quantity? "; string des; int qty; cin >> des; if (des == "stop") break; cin >> qty; item * i = L.find(des); if (i == NULL) cout << "Item not found\n"; else total += qty * i->price; } cout << "Total price = " << total << "c\n"; L.delete_all(); }