1: void Markets::RemoveItem(AUser au)
2: {
3: char YN;
4: int key;
5:
6: try
7: {
8: //ask for an item
9: cout << "please select an item to delete" ;
10: cin >> key;
11:
12: //cast reference to item
13: item* ite =(item*)lst.at(key);
14: //cout << ite-> << endl;
15: if(ite->MaxDiscount < 0){ throw 'a'; };//end if
16: cout << "delete this item " << ite->Name <<"? (y/n): ";
17: //following was inspired by
18: //http://www.augustcouncil.com/~tgibson/tutorial/iotips.html#problems
19: int bad_input;
20: do{
21: bad_input=0;
22: std::cin >> YN;
23: if(!std::cin)
24: {
25: bad_input=1;
26: std::cin.clear();
27: std::cin.ignore();
28:
29: }
30:
31: }while(bad_input);
32: //end if inspiration
33: if(YN == 'y')
34: {
35: //remove the item
36: cat->removeproduct(ite);
37: };//end if
38:
39:
40: }
41: catch(...)
42: {
43: try
44: {
45: //cast reference to catagory
46: catagory* tcat = (catagory*)lst.at(key);
47: if(tcat->subcatagories.size()) throw 'b';
48:
49: cout << " delete this catagory " << tcat->name <<"? (y/n) " << endl;
50: //following was inspired by
51: //http://www.augustcouncil.com/~tgibson/tutorial/iotips.html#problems
52: int bad_input;
53: do{
54: bad_input=0;
55: std::cin >> YN;
56: if(!std::cin)
57: {
58: bad_input=1;
59: std::cin.clear();
60: std::cin.ignore();
61: }
62:
63: }while(bad_input);
64: //end of inspiritation
65: if(YN == 'y')
66: {
67: //the class value cat is the parent pass this object to delete
68: cat->removecatagory(tcat);
69: };//endif
70:
71:
72: }
73: catch (...)
74: {
75: cout << "item could not be removed press u and to continue:" << endl;
76: char temp;
77: cin >> temp;
78: };//end catch
79:
80: };//end catch
81:
82: };//end of remove item