daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ConsoleApplication136.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include"stdafx.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8. using namespace std;
  9.  
  10. class Ukraina
  11. {
  12. public:
  13.     vector <int> dolg;
  14.     void Create()
  15.     {
  16.         cout << "Ukraina was created" << endl;
  17.     }
  18.     void Add(int amount)
  19.     {
  20.         if (dolg.size() != 0)
  21.         {
  22.             dolg.push_back(dolg.back() + amount);
  23.                 cout << "GOSDOLD VIROS NA " << amount << " GRIVEN!!!!" << endl;
  24.         }
  25.         else
  26.         {
  27.             dolg.push_back(amount);
  28.             cout << "CONGRATS ETO VASH PERVII DOLG NA UKRAINE!!!" << endl;
  29.         }
  30.  
  31.     }
  32.  
  33.     void Cntr_z()
  34.     {
  35.         if (dolg.size()!=0)
  36.         {
  37.             dolg.pop_back();
  38.             cout << "Otmena poslednego kredita" <<endl;
  39.         }
  40.         else
  41.             cout << "DOLGA NET!!!!!!" << endl;
  42.     }
  43.  
  44.     void Show()
  45.     {
  46.         for (int i = 0; i<dolg.size(); ++i)
  47.         {
  48.             cout << i + 1 << ". " << dolg[i] << endl;
  49.         }
  50.     }
  51. };
  52.  
  53. class Command
  54. {
  55. protected:
  56.     Ukraina * doc;
  57. public:
  58.     virtual ~Command() {}
  59.     virtual void Execute() = 0;
  60.     virtual void unExecute() = 0;
  61.  
  62.     void setDocument(Ukraina * _doc)
  63.     {
  64.         doc = _doc;
  65.     }
  66. };
  67.  
  68. class InsertCommand : public Command
  69. {
  70.     int line;
  71. public:
  72.     InsertCommand(int _line) : line(_line) {}
  73.  
  74.     void Execute()
  75.     {
  76.         doc->Add(line);
  77.     }
  78.  
  79.     void unExecute()
  80.     {
  81.         doc->Cntr_z();
  82.     }
  83. };
  84.  
  85. class Receiver
  86. {
  87.     vector<Command*> DoneCommands;
  88.     Ukraina doc;
  89.     Command* command;
  90. public:
  91.     void Insert(int line)
  92.     {
  93.         command = new InsertCommand(line);
  94.         command->setDocument(&doc);
  95.         command->Execute();
  96.         DoneCommands.push_back(command);
  97.     }
  98.  
  99.     void Undo()
  100.     {
  101.         if (DoneCommands.size() == 0)
  102.         {
  103.             cout << "DOLGA NET!!!!!!" << endl;
  104.         }
  105.         else
  106.         {
  107.             command = DoneCommands.back();
  108.             DoneCommands.pop_back();
  109.             command->unExecute();
  110.             delete command;
  111.         }
  112.     }
  113.  
  114.     void Show()
  115.     {
  116.         doc.Show();
  117.     }
  118. };
  119.  
  120. int main()
  121. {
  122.     char s;
  123.     int line;
  124.     Receiver res;
  125.     while (1)
  126.     {
  127.         cout << "What to do: \n1.Dobavit' dolg \n2.Otmenit' poslednee deistvie\n3.Vihod " << endl;
  128.         cin >> s;
  129.         switch (s)
  130.         {
  131.         case '1':
  132.             cout << "NA skolko uvelichit'?: ";
  133.             cin >> line;
  134.             res.Insert(line);
  135.             break;
  136.         case '2':
  137.             res.Undo();
  138.             break;
  139.         case '3':
  140.             break;
  141.         }
  142.         cout<< endl ;
  143.         res.Show();
  144.         cout <<  endl << endl;
  145.     }
  146. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top