Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <string>
- #include <iomanip>
- #include <iostream>
- using namespace std;
- struct toys {
- char name[10];
- int price;
- };
- void create(list<toys>& t);
- void print(list<toys>& t);
- void search(list<toys>& t);
- void expensive_toy(list<toys>& t);
- int main()
- {
- int n,c;
- cout << "Enter the number of toys: ";
- cin >> n;
- list<toys> toy(n);
- cout << "Entetr the manage command:\n\t1. Create list;\n\t2. Print list;\n\t3. Find the cost of a toy;\n\t4. Display information about the most expensive toy;\n\t5. The end;\n->";
- cin >> c;
- while (c != 5)
- {
- switch (c) {
- case 1:
- create(toy);
- break;
- case 2:
- print(toy);
- break;
- case 3:
- search(toy);
- break;
- case 4:
- expensive_toy(toy);
- break;
- }
- cout << "->";
- cin >> c;
- }
- return 0;
- }
- void create(list<toys>& t)
- {
- list<toys>::iterator i;
- for (i = t.begin(); i != t.end(); ++i)
- {
- cin.get();
- cin.clear();
- cout << "Enter the information about toy:\nName: ";
- cin.getline(i->name, 10);
- cout << "Price: ";
- cin >> i->price;
- cout << endl;
- }
- }
- void print(list<toys>& t)
- {
- list<toys>::iterator i;
- for (i = t.begin(); i != t.end(); ++i)
- {
- cout << "Name: " << setw(10) << left << i->name << setw(5) << left << " Price: " << i->price << endl;
- }
- }
- void search(list<toys>& t)
- {
- char Name[10];
- list<toys>::iterator i;
- cout << "Enter the name of the toy: ";
- cin >> Name;
- for (i = t.begin(); i != t.end(); ++i)
- {
- if (strcmp(i->name, Name) == 0)
- {
- cout << "Price:" << i->price << endl;
- break;
- }
- }
- if (i == t.end()) cout << "There is no such toy!" << endl;
- }
- void expensive_toy(list<toys>& t)
- {
- list<toys>::iterator i;
- int max = 0;
- cout << "The most expensive toy: " << endl;
- for (i = t.begin(); i != t.end(); ++i)
- {
- if (i->price > max) max = i->price;
- }
- for (i = t.begin(); i != t.end(); ++i)
- {
- if (i->price == max) cout << "Name: " << setw(10) << left << i->name << setw(5) << left << " Price: " << i->price << endl;
- }
- }
Add Comment
Please, Sign In to add comment