Answer to Question #306592 in C++ for SAFFA

Question #306592

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.


1
Expert's answer
2022-03-06T04:51:48-0500
class Inventory
{
private:
    int itemNumber;
    int quantity;
    double cost;
    double totalCost;
public:
    Inventory()     // declare the Inventory object using the default constructor
    {
        itemNumber = 0;
        quantity = 0;
        cost = 0;
        totalCost = 0;
        
    }
    Inventory(int newItemNumber, int newQuantity, double newCost) 
    {
        itemNumber = newItemNumber;
        quantity = newQuantity;
        cost = newCost;
        setTotalCost(quantity, cost);
    }
    
    void setItemNumber(int)   
    {
        itemNumber = itemNumber;
    }
    void setQuantity(int)	
    {
        quantity = quantity;
    }
    void setCost(double)  
    {
        cost = cost;
    }
    void setTotalCost(int, double)
    {
        totalCost = quantity * cost;
    }
    
    int getItemNumber()
    {
        return itemNumber;
    }
    int getQuantity()
    {
        return quantity;
    }
    double getCost()
    {
        return cost;
    }
    double getTotalCost()
    {
        return totalCost;
    }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog