00001
00002
00003
00004
00005
00006
00007
00008 #include "Basket.h"
00009 #include "Product.h"
00010
00011
00012 Basket::Basket()
00013 {
00014 _tot = 0.0;
00015 }
00016
00024 void Basket::addProduct(ProductProxy *p, int aQty)
00025 {
00026 _tot += p->getPrice();
00027
00028 int aPid = p->uniqueID();
00029 int aValue = aQty;
00030
00031 map<int,int>::iterator it = find(aPid);
00032 if (it != end())
00033 aValue += (*it).second;
00034 insert(pair<int, int>(aPid, aValue));
00035 }
00036
00042 float Basket::total() const
00043 {
00044 return _tot;
00045 }
00046
00047 ostream& operator<<(ostream& aStream, Basket & p) {
00048 for (map<int, int>::iterator it=p.begin(); it != p.end(); it++)
00049 aStream << setw(4) << (*it).first << " | " << (*it).second << endl;
00050
00051 return aStream;
00052 }