Ask Question
10 September, 16:50

Write the one Sale method of the GroceryStore class. Method oneSale has one parameter: the name of one product (that a customer would like to buy). Method oneSale should attempt to carry out the sale of the named product, and it should return true or false depending on whether the sale is successful. The sale is successful if there is a product in the stock array with the given name and if the number of items in stock of that product is greater than zero. In that case, one Sale should subtract one from the number of items in stock and return true. If there is no product in the stock array with the given name or if the number of items in stock for that product is less than or equal to zero, oneSale should return false.

+5
Answers (1)
  1. 10 September, 17:36
    0
    Check the explanation

    Explanation:

    bool oneSale (string item) {

    for (int i=0; i
    if (item==grocerryList[i]. name ()) { / / if name matches

    if (grocerryList[i]. getStock () >0) { / / and stock is greater than 0

    grocerryList[i]. setStock (grocerryList[i]. getStock () - 1); / / subtract 1 from the stock

    / / or alternate is grocerryList[i]. stock = grocerryList[i]. stock-1;

    return true; / / return true

    }

    }

    else if (item==grocerryList[i]. name ()) { / / if name matches

    if (grocerryList. getStock () = =0) { / / but stock is empty

    return false; / / return falsse

    }

    }

    else{ / / means item is not available so there is no need to check stock

    return false; / / return false

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write the one Sale method of the GroceryStore class. Method oneSale has one parameter: the name of one product (that a customer would like ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers