Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication136.cpp : Defines the entry point for the console application.
- //
- #include"stdafx.h"
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Ukraina
- {
- public:
- vector <int> dolg;
- void Create()
- {
- cout << "Ukraina was created" << endl;
- }
- void Add(int amount)
- {
- if (dolg.size() != 0)
- {
- dolg.push_back(dolg.back() + amount);
- cout << "GOSDOLD VIROS NA " << amount << " GRIVEN!!!!" << endl;
- }
- else
- {
- dolg.push_back(amount);
- cout << "CONGRATS ETO VASH PERVII DOLG NA UKRAINE!!!" << endl;
- }
- }
- void Cntr_z()
- {
- if (dolg.size()!=0)
- {
- dolg.pop_back();
- cout << "Otmena poslednego kredita" <<endl;
- }
- else
- cout << "DOLGA NET!!!!!!" << endl;
- }
- void Show()
- {
- for (int i = 0; i<dolg.size(); ++i)
- {
- cout << i + 1 << ". " << dolg[i] << endl;
- }
- }
- };
- class Command
- {
- protected:
- Ukraina * doc;
- public:
- virtual ~Command() {}
- virtual void Execute() = 0;
- virtual void unExecute() = 0;
- void setDocument(Ukraina * _doc)
- {
- doc = _doc;
- }
- };
- class InsertCommand : public Command
- {
- int line;
- public:
- InsertCommand(int _line) : line(_line) {}
- void Execute()
- {
- doc->Add(line);
- }
- void unExecute()
- {
- doc->Cntr_z();
- }
- };
- class Receiver
- {
- vector<Command*> DoneCommands;
- Ukraina doc;
- Command* command;
- public:
- void Insert(int line)
- {
- command = new InsertCommand(line);
- command->setDocument(&doc);
- command->Execute();
- DoneCommands.push_back(command);
- }
- void Undo()
- {
- if (DoneCommands.size() == 0)
- {
- cout << "DOLGA NET!!!!!!" << endl;
- }
- else
- {
- command = DoneCommands.back();
- DoneCommands.pop_back();
- command->unExecute();
- delete command;
- }
- }
- void Show()
- {
- doc.Show();
- }
- };
- int main()
- {
- char s;
- int line;
- Receiver res;
- while (1)
- {
- cout << "What to do: \n1.Dobavit' dolg \n2.Otmenit' poslednee deistvie\n3.Vihod " << endl;
- cin >> s;
- switch (s)
- {
- case '1':
- cout << "NA skolko uvelichit'?: ";
- cin >> line;
- res.Insert(line);
- break;
- case '2':
- res.Undo();
- break;
- case '3':
- break;
- }
- cout<< endl ;
- res.Show();
- cout << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement