/********************************************************************* C201 Computer Programming II Fall 2006 Dana Vrajitoru & A class to represent products in stock in a shop. **********************************************************************/ #include "product.h" #include using namespace std; // **************************** Constructors ************************** // Default constructor. Product::Product() { name[0] = '\0'; type = food_ty; quantity = 0; barcode = 0; price = 0.0; } //Copy constructor. Product::Product(Product &data) { Init(data); } // ************************** Initializing functions ***************** // Reset to empty values. It looks like the default constructor but it // can be called at any type to recycle the target object. void Product::Init() { name[0] = '\0'; type = food_ty; quantity = 0; barcode = 0; price = 0.0; } // Initialize the target object from the parameter data so that we can // copy an object to another one even after the object was created. void Product::Init(Product &data) { strcpy(name, data.name); type = data.type; quantity = data.quantity; barcode = data.barcode; price = data.price; } // Input-output void Product::Input() { } void Product::Output() { } // ************************** Data manipulation ********************** // Add more products to the stock. void Product::Add(int how_many) { quantity += how_many; } // Remove some products from the stock. It needs to be a bool because // if we don't have that many items in the stock we can't remove // them. If the function returns false, the target object is // unchanged. bool Product::Remove(int how_many) { if (how_many <= quantity) { quantity -= how_many; return true; } else return false; }