/*
Copyright (C) 2008 Alessandro Bugatti (alessandro.bugatti@istruzione.it)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*! \file
* \brief Programma per testare la classe ContoCorrente
* \author Alessandro Bugatti
*
* \version 0.1
* \date Creazione 07/03/2009
* \date Ultima modifica 07/03/2009
*
*/
#include <iostream>
#include <vector>
#include "contocorrente.h"
using namespace std;
vector <ContoCorrente> contiCorrenti;
void menu()
{
cout << "1) Apri un nuovo conto" << endl;
cout << "2) Deposita soldi su un conto" << endl;
cout << "3) Preleva soldi da un conto" << endl;
cout << "4) Mostra il saldo di un conto" << endl;
cout << "0) Esci" << endl;
}
void apri()
{
string nome, cognome;
cout << "Inserisci il nome del correntista: ";
cin >> nome;
cout << "Inserisci il cognome del correntista: ";
cin >> cognome;
cout << endl;
ContoCorrente temp(nome,cognome);
contiCorrenti.push_back(temp);
}
int scegliCorrentista()
{
int scelta;
cout << "Scegli il correntista: " << endl;
for (int i=0;i< contiCorrenti.size();i++)
cout << i+1 << " - " << contiCorrenti[i].getNominativo() << endl;
cin >> scelta;
return scelta - 1;
}
void deposito()
{
int scelta;
double somma;
scelta = scegliCorrentista();
cout << "Inserisci la somma da depositare: " << endl;
cin >> somma;
contiCorrenti[scelta].deposito(somma);
}
void prelievo()
{
int scelta;
double somma;
bool fatto;
scelta = scegliCorrentista();
cout << "Inserisci la somma da prelevare: " << endl;
cin >> somma;
fatto = contiCorrenti[scelta].prelievo(somma);
if (fatto)
cout << "Prelievo eseguito correttamente" << endl;
else
cout << "Prelievo non disponibile" << endl;
}
void saldo()
{
int scelta;
double somma;
scelta = scegliCorrentista();
cout << "Il saldo di " << contiCorrenti[scelta].getNominativo()
<< " รจ di " << contiCorrenti[scelta].saldo() << " euro." << endl;
}
int main()
{
int scelta;
do
{
menu();
cin >> scelta;
switch (scelta)
{
case 1:
apri();
break;
case 2:
deposito();
break;
case 3:
prelievo();
break;
case 4:
saldo();
break;
}
}
while (scelta != 0);
return 0;
}