Advertisement
Daniel_leinaD

Вовчик 4 лаба

Nov 15th, 2022 (edited)
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. class Automat
  7. {
  8. protected:
  9.     vector<Automat> atm;
  10.     int milk;
  11.     int coffee;
  12.  
  13. public:
  14.     Automat(int milk = 5000, int coffee = 1500)
  15.     {
  16.         this->milk = milk;
  17.          this->coffee = coffee;
  18.     }
  19.  
  20.  
  21.     void SetCoffee()
  22.     {
  23.         if (this->coffee == 0)
  24.         {
  25.             cout << "Add coffee: ";
  26.             cin >> coffee;
  27.             this->coffee = +coffee;
  28.         }
  29.     }
  30.     void SetMilk()
  31.     {
  32.         if (this->milk == 0)
  33.         {
  34.             cout << "Add milk: ";
  35.             cin >> milk;
  36.             this->milk = +milk;
  37.         }
  38.     }
  39.  
  40.  
  41.     int Getmilk() { return this->milk; }
  42.     int GetCoffee() { return this->coffee; }
  43.  
  44.     void Show()
  45.     {
  46.         cout << "Automat is full: \n";
  47.         cout << "milk: \t" << milk << '\n';
  48.         cout << "Cofe: \t" << coffee << '\n';
  49.     }
  50. };
  51.  
  52. class Coffee :public Automat
  53. {
  54.     int coffeeMilk;
  55.     int coffeeCoffee;
  56.     int count;
  57. public:
  58.  
  59.     Coffee()
  60.     {
  61.         coffeeMilk = 100;
  62.         coffeeCoffee = 15;
  63.     }
  64.     void CookingCoffee()
  65.     {
  66.         cout << "What type of coffee u want? -- (latte, cappucino, ordinary)\n";
  67.         string type_coffee;
  68.         cin >> type_coffee;
  69.  
  70.         cout << "How many " << type_coffee << " u want?\n";
  71.         cin >> count;
  72.         int ost_coffee, ost_milk, ost;
  73.         if (type_coffee == "latte") {
  74.             coffeeMilk = 300;
  75.             coffeeCoffee = 15;
  76.             this->milk -= coffeeMilk * count;
  77.             this->coffee -= coffeeCoffee * count;
  78.             ost_coffee = this->coffee / coffeeCoffee;
  79.             ost_milk = this->milk / coffeeMilk;
  80.             if (ost_coffee < ost_milk) {
  81.                 ost = ost_coffee;
  82.             }
  83.             else {
  84.                 ost = ost_milk;
  85.             }
  86.         }
  87.         if (type_coffee == "cappucino") {
  88.             coffeeMilk = 30;
  89.             coffeeCoffee = 30;
  90.             this->milk -= coffeeMilk * count;
  91.             this->coffee -= coffeeCoffee * count;
  92.             ost_coffee = this->coffee / coffeeCoffee;
  93.             ost_milk = this->milk / coffeeMilk;
  94.             if (ost_coffee < ost_milk) {
  95.                 ost = ost_coffee;
  96.             }
  97.             else {
  98.                 ost = ost_milk;
  99.             }
  100.         }
  101.         if (type_coffee == "ordinary") {
  102.             this->milk -= coffeeMilk * count;
  103.             this->coffee -= coffeeCoffee * count;
  104.             ost_coffee = this->coffee / coffeeCoffee;
  105.             ost_milk = this->milk / coffeeMilk;
  106.             if (ost_coffee < ost_milk) {
  107.                 ost = ost_coffee;
  108.             }
  109.             else {
  110.                 ost = ost_milk;
  111.             }
  112.         }
  113.         this->milk -= coffeeMilk * count;
  114.         this->coffee -= coffeeCoffee * count;
  115.         for (int i = 0; i < count; i++) {
  116.             cout << i << " cup " << type_coffee << "\n";
  117.         }
  118.         cout << "U can buy " << ost << " more\n ";
  119.     }
  120.  
  121. };
  122.  
  123. class Admin
  124. {
  125.     Automat* tmp;
  126. public:
  127.     void Add()
  128.     {
  129.         tmp = new Automat;
  130.         tmp->SetMilk();
  131.         tmp->SetCoffee();
  132.     }
  133. };
  134.  
  135. class Client :public Coffee
  136. {
  137.  
  138. public:
  139.     void DrinkCofe()
  140.     {
  141.         Coffee* drink = new Coffee;
  142.         drink->CookingCoffee();
  143.     }
  144. };
  145.  
  146.  
  147. int main()
  148. {
  149.     Client Vova;
  150.     cout << "PROCESS COFFEE" << "\n";
  151.     Vova.CookingCoffee();
  152.     Vova.GetCoffee();
  153.     Vova.Getmilk();
  154.     Vova.SetCoffee();
  155.     Vova.SetMilk();
  156.     Vova.Show();
  157.     system("pause");
  158.     return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement