Create an Inventory class that a warehouse might use to represent their stock of products and raw materials. Include a data member of type string to provide a description of the product, and data member of type int to represent the balance stock. Provide a constructor that receives an initial product and uses it to initialize the data members. The constructor should validate the initial product to ensure it has a stock greater than 20, which is the company’s minimum stock level. If not, it should display an error message. Provide three member functions. Member function Purchase should add a product to the current stock. Member function Sale should reduce stock. Ensure after each sale that the stock level does not drop below 20. Member function getStock should return the current stock. Create a program that creates two Inventory objects and tests the member functions of the class.
Here is the program:
class Inventory
{
public:
Inventory(string DescriptProduct, int BalanceStock)
{
this->DescriptProduct = DescriptProduct;
this->BalanceStock = BalanceStock;
if (BalanceStock < 20 )
{
cout << DescriptProduct << endl;
cout << "Error! Balance stock < 20! " << endl;
}
}
void Purchase()
{
BalanceStock++;
}
void Sell()
{
BalanceStock--;
}
void getStock()
{
cout << DescriptProduct << endl;
cout << "Balance stock: " << BalanceStock << endl;
}
private:
string DescriptProduct;
int BalanceStock;
};
int main()
{
Inventory inv("Sugar",20);
Inventory prod("Chocolate",19);
prod.Purchase();
inv.Sell();
inv.getStock();
prod.getStock();
}
Comments
Leave a comment