Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class commodity {
- string id, name, color, size;
- int price, num;
- public:
- commodity(){}
- commodity(string id,string name,string size,string color,int price,int num):id(id),name(name),size(size), color(color),price(price), num(num){}
- void couttotalprice() {
- cout << price * num << ".00"<<endl;
- }
- void coutinformation() {
- cout << name << "," << size<< "," << color << "," << price << ".00" << "," << num << ",";
- couttotalprice();
- }
- string getid() {return id;}
- int getnum() {return num;}
- int getprice() {return price;}
- void addnum() {num++;}
- void subtractnum() {num--;}
- void deletenum() {num = 0;}
- }; commodity a[100];
- int main() {
- int t;
- cin >> t;
- while (t--) {
- int n;
- string id, name, color, size;
- int price, num;
- cin >> n;
- for(int i=n-1;i>=0;i--) {
- string way;
- cin >> way;
- if (way == "ADD") {
- cin >> id >> name >> size >> color >> price >> num;
- a[i] = commodity(id, name, size, color, price, num);
- }
- if (way == "UP") {
- string upnum;
- cin >> upnum;
- for (int i = 0; i < n; i++) {
- if (upnum == a[i].getid())
- a[i].addnum();
- }
- }
- if (way == "DELETE") {
- string deletenum;
- cin >> deletenum;
- for (int i = 0; i < n; i++) {
- if (deletenum == a[i].getid())
- a[i].deletenum();
- }
- }
- if (way == "DOWN") {
- string downnum;
- cin >> downnum;
- for (int i = 0; i < n; i++) {
- if (downnum == a[i].getid()) {
- a[i].subtractnum();
- }
- }
- }
- }
- cout << "商品清单:" << endl << "商品,颜色,尺码,单价,数量,小计" << endl;
- int cnt = 0, sum = 0;
- for (int i = 0; i < n; i++) {
- if (a[i].getnum()) {
- cnt += a[i].getnum();
- sum += a[i].getnum() * a[i].getprice();
- a[i].coutinformation();
- }
- }
- cout << "----------" << endl << cnt << "件商品,总商品金额" << sum << ".00" << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement