Guest User

Untitled

a guest
Jan 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. Question 12.
  2. a) Write the definition of a class called Product. A Product object should represent a product stocked in a supermarket, e.g. a 500 gram can of corn. It should contain the following information: a code for the product, the name of the product, the cost of the product, and the quantity of the product currently in stock Assume the code and the name are represented by strings of characters. Include the following constructor and member functions in the class definition.
  3.  
  4.  
  5. - A member function outOfStock()with no arguments, that will return the value true if there is none of this product in stock; otherwise it will return false.
  6.  
  7. c) Implement the member function outOfStock().
  8.  
  9. soln:
  10. class Product
  11. {
  12. private:
  13. string code;
  14. string name;
  15. float cost;
  16. int stock;
  17. public:
  18. Product(string code, string name);
  19. string getName();
  20. void addStock(int n);
  21. void subStock(int n);
  22. bool outOfStock();
  23. void setCost(double cost);
  24. float getCost();
  25. };
  26.  
  27.  
  28.  
  29.  
  30. c) bool Product::outOfStock()
  31. { return stock <= 0;}
Add Comment
Please, Sign In to add comment