// Simulazione di un Conto Corrente Bancario versione 2 // #include #include #include using namespace std; class MiniCCB { private: double dare; double avere; int tentativiPIN; bool blocco; string PIN; bool CheckPIN(string p) { bool r; if (blocco) return false; if(p==PIN){ tentativiPIN=0; return true; } tentativiPIN++; if(tentativiPIN>3) blocco=true; return false; } public: MiniCCB() { dare=avere=0; tentativiPIN=0; PIN="11111"; blocco=false; }; MiniCCB(string p) { dare=avere=0; tentativiPIN=0; PIN=p; blocco=false; }; bool Saldo(double &importo, string p) { if(blocco || !CheckPIN(p)) return false; importo=avere-dare; return true; }; bool Deposito(double importo, string p) { if(blocco || !CheckPIN(p)) return false; avere+=importo; return true; }; bool Prelievo(double importo, string p) { if(blocco || !CheckPIN(p)) return false; dare+=importo; return true; }; bool Bloccato() { return blocco; } }; int main() { double saldo=0, importo=0; bool ancora=true; int scelta=0; MiniCCB Conto("12345"); string mioPIN; cout << fixed << setprecision(2); do { cout << endl << endl <<"Simulazione di un C/C Bancario v.2" << endl; cout << "MENU"<> scelta; switch(scelta){ case 0: ancora=false; break; case 1: cout << "Inserisci l'importo da versare: "; cin >> importo; cout << "Inserisci il PIN: "; cin >> mioPIN; if(!Conto.Deposito(importo,mioPIN)) { cout << "L'operazione non è andata a buon fine!" << endl; cout << "Verificare che il PIN sia corretto o contattare la banca"<> importo; cout << "Inserisci il PIN: "; cin >> mioPIN; if(!Conto.Prelievo(importo,mioPIN)){ cout << "L'operazione non è andata a buon fine!" << endl; cout << "Verificare che il PIN sia corretto o contattare la banca"<> mioPIN; if(!Conto.Saldo(importo,mioPIN)){ cout << "L'operazione non è andata a buon fine!" << endl; cout << "Verificare che il PIN sia corretto o contattare la banca"<