Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include "product.hpp"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. Product::Product() {
  7.     setName("");
  8.     setAmount(0.0);
  9.     setPrice(0.0);
  10.     setUnit("");
  11. }
  12.  
  13. Product::Product(string Name, double Price, string Unit, double Amount) {
  14.     setName(Name);
  15.     setPrice(Price);
  16.     setUnit(Unit);
  17.     setAmount(Amount);
  18. }
  19.  
  20. void Product::setName(string name){
  21.     this->name = name;
  22. }
  23.  
  24. void Product::setUnit(string unit){
  25.     this->unit = unit;
  26. }
  27.  
  28. void Product::setPrice(double price){
  29.     this->price = price;
  30. }
  31.  
  32. void Product::setAmount(double amount){
  33.     this->amount = amount;
  34. }
  35.  
  36. string Product::getName() const{
  37.     return name;
  38. }
  39.  
  40. double Product::getPrice() const{
  41.     return price;
  42. }
  43.  
  44. double Product::getAmount() const{
  45.     return amount;
  46. }
  47.  
  48. string Product::getUnit() const{
  49.     return unit;
  50. }
  51.  
  52. double Product::getBought(){
  53.     return bought;
  54. }
  55.  
  56. void Product::buy(double amount_buy) {
  57.     if (getAmount() < amount_buy) {
  58.         cout << "Необходимого количества товара нет" << endl;
  59.         cout << "Вы можете купить только " << getAmount() << " " << getUnit() << " товара " << getName() << endl;
  60.         return;
  61.     }
  62.    
  63.     bought = bought + amount_buy;
  64.    
  65.     setAmount(getAmount() - amount_buy);
  66.    
  67.     cout << "Вы успешно купили " << getName() << " в количестве " << amount_buy << " " << getUnit() << endl;
  68. }
  69.  
  70. double Product::getProfit() {
  71.     return getBought() * getPrice();
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement