Hi guys,
Well, I am currently taking a C++ course focusing on learning about object-oriented design concepts, including polymorphism. The assignment I am currently working on involves the creation of a point-of-sale system. The details of the problem are quite involved and challenging (for me, at least!). I am determined to solve the problem myself, however, I am in real need of some help.
We have been provided with /some/ code for the project. This has been helpful but also creates certain constraints for the way in which the project is completed. The partial solution we have been provided with used arrays for storing product codes. I wish to instead use a map which contains a string with the product code of various items as the key, paired to a pointer to each product.
I should add, at this point, that there are three different types of product:
1 - Standard product line (product code, no serial number, no expiry date)
2 - Itemized product line (product code, serial number, no expiry date)
3 - Perishable product line (product code, no serial number, expiry date)
However, my current issue is with the implementation of a map. I am currently working with more than five classes, so the following is supposed to be a helpful excerpt. May I say beforehand how grateful I am to those of you who are taking the time to read the code. Here is some code to demonstrate where I am up to:
class Inventory{
public:
static void AddProduct(ProductLine* prod);
static void SellProduct(ProductCode const& prod, int qty);
static void IncreaseStock(ProductCode const& prod, int qty);
static ProductLine* GetProduct(ProductCode const& prod);
private:
static map<string, ProductLine*, less<string> > productMap;
static int numberProds;
};
using namespace std;
int Inventory::numberProds = 0;
// add another product line
void Inventory::AddProduct(ProductLine* prod)
{
// add product then increment the total number of products
productMap.insert (prod->GetCode(), prod);
numberProds++;
}
It is quite difficult to present a single portion of this problem clearly, as there are so many different things involved in making it work. However, being able to make the map work would be very helpful. I have not included the other functions as I wish to work them out for myself.
I would be happy to post more of the code I have, but I do not want to give the impression that I do not want to solve the problem, myself. If I have not been clear, I apologize - after you have been looking at a problem for a while, you can make the mistake of assuming that you have explained everything when you haven't.
Thank you to all of you who have taken the time to read this post.
Kind regards,
Daniel
NB: The class declaration of Inventory was provided except for the map component. It is this component that I am trying to make work. I just wanted to make sure that I am not unintentionally passing off someone else's work as my own. D