#include #include #include using namespace std; class Account { private: double m_money; int m_acc; public: Account(int acc, double money) { m_acc = acc; m_money = money; } int getAcc() const { return m_acc; } double getMoney() const { return m_money; } void setMoney(double m) { m_money = m; } bool checkFunds(double money) { return m_money >= money; } void withdraw(double money) { cout << "withdraw " << fixed << setprecision(2) << money << ": "; if(checkFunds(money)) { m_money -= money; cout << "ok" << endl; } else { cout << "insufficient funds" << endl; } } void deposit(double money) { m_money += money; cout << "deposit " << fixed << setprecision(2) << money << ": ok" << endl; } void transfer(double money, Account &dest) { if(!checkFunds(money)) { cout << "transfer " << money << ": insufficient funds" << endl; return; } if((m_acc % 10) != (dest.getAcc() % 10)) { cout << "transfer " << money << ": interbank" << endl; } else { cout << "transfer " << money << ": ok" << endl; } //odecet setMoney(m_money - money); //pricist dest.setMoney(dest.getMoney() + money); } }; void getInput(int &acc, double &money) { int bank; cin >> acc; cin.get(); cin >> bank; cin >> money; acc = acc * 10 + bank; //cout << "pepa " << money << endl; } int main() { const int size = 100000; Account *accs[size]; for(int i = 0; i < size; ++i) accs[i] = NULL; vector accounts; int count, acc, bank, acc2; double money; string cmd; while(1) { cin >> count; if(count == 0) { cout << "goodbye" << endl; break; } for(int i = 0; i < count; ++i) { // nactem ucet a castku getInput(acc, money); if(accs[acc] != NULL) { cout << "create: already exists" << endl; continue; } accounts.push_back(acc); accs[acc] = new Account(acc, money); } cin >> cmd; while(cmd != "end") { if(cmd == "create") { cin >> acc; cin.get(); cin >> bank; acc = acc * 10 + bank; //cout << "pepa smrdi " << acc << endl; if(accs[acc] != NULL) { cout << "create: already exists" << endl; cin >> cmd; continue; } accounts.push_back(acc); accs[acc] = new Account(acc, 0.0); cout << "create: ok" << endl; } else if(cmd == "withdraw") { getInput(acc, money); if(accs[acc] == NULL) { cout << "withdraw "<< money << ": no such account" << endl; cin >> cmd; continue; } accs[acc]->withdraw(money); } else if(cmd == "deposit") { getInput(acc, money); if(accs[acc] == NULL) { cout << "deposit "<< money << ": no such account" << endl; cin >> cmd; continue; } accs[acc]->deposit(money); } else if(cmd == "transfer") { // ucet1 cin >> acc; cin.get(); cin >> bank; acc = acc * 10 + bank; // ucet2 cin >> acc2; cin.get(); cin >> bank; acc2 = acc2 * 10 + bank; // castka cin >> money; //kontrola //cout << "###pepa " << acc << " " << acc2 << endl; if((accs[acc] == NULL) || (accs[acc2] == NULL)) { cout << "transfer " << money << ": no such account" << endl; cin >> cmd; continue; } if(accs[acc] == accs[acc2]) { cout << "transfer " << money << ": same account" << endl; cin >> cmd; continue; } accs[acc]->transfer(money, *accs[acc2]); } cin >> cmd; } cout << "end" << endl; for(int i = 0; i < accounts.size(); ++i) { delete accs[accounts[i]]; accs[accounts[i]] = NULL; } accounts.clear(); cin.get(); // prazdnej radek cin.get(); // prazdnej radek cout << endl; } return 0; }