coffeeMachine.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "coffeeMachine.hpp"
  2. CoffeMachine::CoffeMachine():
  3. m_waterContainer(5000,5000), m_milkContainer(3000,3000), m_beansContainer(1000,1000), m_cupContainer(200,200), m_cashContainer(1000,0)
  4. {
  5. }
  6. CoffeMachine::~CoffeMachine(){ }
  7. CoffeMachine::Status CoffeMachine::getStatus()
  8. {
  9. return Status
  10. {
  11. m_waterContainer.getContent(),
  12. m_milkContainer.getContent(),
  13. m_beansContainer.getContent(),
  14. m_cupContainer.getContent(),
  15. m_cashContainer.getContent()
  16. };
  17. }
  18. Cup* CoffeMachine::orderCoffee(CoffeeType coffeeType, int &cash)
  19. {
  20. if(m_cupContainer.isEmpty()){ return nullptr; }
  21. Recipe temp;
  22. int cupContent;
  23. switch (coffeeType)
  24. {
  25. case CoffeeType::esspresso:
  26. temp = m_recipes[static_cast<int>(CoffeeType::esspresso)];
  27. break;
  28. case CoffeeType::latte:
  29. temp = m_recipes[static_cast<int>(CoffeeType::latte)];
  30. break;
  31. case CoffeeType::capuchino:
  32. temp = m_recipes[static_cast<int>(CoffeeType::capuchino)];
  33. break;
  34. default:
  35. return nullptr;
  36. break;
  37. }
  38. if(temp.m_cost>cash){ return nullptr; }
  39. if(temp.m_water <= m_waterContainer.getContent() && temp.m_milk <= m_milkContainer.getContent() && temp.m_beans <= m_beansContainer.getContent())
  40. {
  41. m_cupContainer.take(temp.m_cup);
  42. cash -= temp.m_cost;
  43. m_cashContainer.add(temp.m_cost);
  44. cupContent = m_waterContainer.take(temp.m_water) + m_milkContainer.take(temp.m_milk) + m_beansContainer.take(temp.m_beans);
  45. return new Cup(temp.m_name, cupContent);
  46. }
  47. return nullptr;
  48. }
  49. std::ostream& operator<<(std::ostream &out, const CoffeMachine::Status &status)
  50. {
  51. out<<"Вода"<<"\t"<<status.m_water<<"\n";
  52. out<<"Молоко"<<"\t"<<status.m_milk<<"\n";
  53. out<<"Зёрна"<<"\t"<<status.m_beans<<"\n";
  54. out<<"Стаканы"<<"\t"<<status.m_cups<<"\n";
  55. out<<"Выручка"<<"\t"<<status.m_cash<<"\n";
  56. return out;
  57. }