Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Goods {
- public:
- int price;
- int count;
- string name;
- string type;
- void read() {
- cin >> name >> type >> price >> count;
- }
- int calculatePrice() {
- return price * count;
- }
- void printGood()
- {
- cout << name << ":" << type << " count:" << count << " price:" << price << endl;
- }
- };
- int main()
- {
- vector<Goods> vec;
- string comm;
- int summ=0;
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cin >> comm;
- if (comm == "add")
- {
- Goods igor;
- igor.read();
- vec.push_back(igor);
- }
- else if (comm == "check")
- {
- cin >> comm;
- for (int i = 0; i < vec.size(); i++)
- {
- if (vec[i].type == comm)
- {
- summ += vec[i].calculatePrice();
- }
- }
- cout << comm << ":" << summ<<endl;
- summ = 0;
- }
- else if (comm == "all")
- {
- for (int i = 0; i < vec.size(); i++)
- {
- vec[i].printGood();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement