Created
February 27, 2026 12:57
-
-
Save nicolekorch/d7b3f63746ab2a0bde3e4559ebf3c024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| /* | |
| Интерфейс Контроллер | |
| */ | |
| class Controller | |
| { | |
| public: | |
| virtual void start() = 0; | |
| }; | |
| /* | |
| Контроллер Банкомата | |
| Наследуется от Controller | |
| */ | |
| class ATMController : public Controller | |
| { | |
| public: | |
| void start() | |
| { | |
| cout << "ATM Controller started" << endl; | |
| } | |
| }; | |
| /* | |
| Класс Транзакция Банкомата | |
| */ | |
| class Transaction | |
| { | |
| public: | |
| // Атрибуты | |
| int cardID; // идентификатор карточки | |
| int pinValue; // значение PIN | |
| int enteredPIN; // введенный PIN | |
| double cashAmount; // сумма | |
| // Операции | |
| void createTransaction() | |
| { | |
| cout << "Transaction created" << endl; | |
| } | |
| bool checkPIN() | |
| { | |
| return pinValue == enteredPIN; | |
| } | |
| void finishTransaction() | |
| { | |
| cout << "Transaction finished" << endl; | |
| } | |
| }; | |
| /* | |
| Контроллер Банка | |
| */ | |
| class BankController | |
| { | |
| public: | |
| bool checkCardID(int cardID) | |
| { | |
| return cardID > 0; | |
| } | |
| void openAccount(int cardID) | |
| { | |
| cout << "Account opened for card " | |
| << cardID << endl; | |
| } | |
| bool checkBalance(int cardID, | |
| double amount) | |
| { | |
| if(amount <= 1000) | |
| return true; | |
| else | |
| return false; | |
| } | |
| bool reduceBalance(int cardID, | |
| double amount) | |
| { | |
| if(amount <= 1000) | |
| return true; | |
| else | |
| return false; | |
| } | |
| }; | |
| /* | |
| Устройство чтения карточки | |
| */ | |
| class CardReader | |
| { | |
| public: | |
| int readCardID() | |
| { | |
| int id; | |
| cout << "Enter card ID: "; | |
| cin >> id; | |
| return id; | |
| } | |
| int readPIN() | |
| { | |
| int pin; | |
| cout << "Enter PIN: "; | |
| cin >> pin; | |
| return pin; | |
| } | |
| void returnCard() | |
| { | |
| cout << "Card returned" << endl; | |
| } | |
| void blockCard() | |
| { | |
| cout << "Card blocked" << endl; | |
| } | |
| }; | |
| /* | |
| Экран Банкомата | |
| */ | |
| class Screen | |
| { | |
| public: | |
| void showMenu() | |
| { | |
| cout << endl; | |
| cout << "1 - Withdraw money" << endl; | |
| cout << "2 - Exit" << endl; | |
| } | |
| void showWithdrawMenu() | |
| { | |
| cout << "Enter amount:" << endl; | |
| } | |
| }; | |
| /* | |
| Клавиатура Банкомата | |
| */ | |
| class Keyboard | |
| { | |
| public: | |
| int enterPIN() | |
| { | |
| int pin; | |
| cout << "Input PIN: "; | |
| cin >> pin; | |
| return pin; | |
| } | |
| bool enterTransactionType() | |
| { | |
| int type; | |
| cout << "Choose transaction (1-withdraw): "; | |
| cin >> type; | |
| if(type == 1) | |
| return true; | |
| else | |
| return false; | |
| } | |
| }; | |
| /* | |
| Главная программа | |
| */ | |
| int main() | |
| { | |
| ATMController atm; | |
| Transaction transaction; | |
| BankController bank; | |
| CardReader reader; | |
| Screen screen; | |
| Keyboard keyboard; | |
| atm.start(); | |
| transaction.createTransaction(); | |
| // чтение карточки | |
| transaction.cardID = reader.readCardID(); | |
| if(!bank.checkCardID(transaction.cardID)) | |
| { | |
| cout << "Invalid card" << endl; | |
| reader.blockCard(); | |
| return 0; | |
| } | |
| // ввод PIN | |
| transaction.enteredPIN = | |
| keyboard.enterPIN(); | |
| transaction.pinValue = 1111; | |
| if(!transaction.checkPIN()) | |
| { | |
| cout << "Wrong PIN" << endl; | |
| reader.blockCard(); | |
| return 0; | |
| } | |
| screen.showMenu(); | |
| if(keyboard.enterTransactionType()) | |
| { | |
| screen.showWithdrawMenu(); | |
| cin >> transaction.cashAmount; | |
| if(bank.checkBalance( | |
| transaction.cardID, | |
| transaction.cashAmount)) | |
| { | |
| bank.reduceBalance( | |
| transaction.cardID, | |
| transaction.cashAmount); | |
| cout << "Money выдаются" | |
| << endl; | |
| } | |
| else | |
| { | |
| cout << "Недостаточно средств" | |
| << endl; | |
| } | |
| } | |
| transaction.finishTransaction(); | |
| reader.returnCard(); | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cd