#include <iostream>
#include <sstream>
#include <stdio.h>
using namespace std;
class Cliente
{
public:
Cliente(string nombre, string apellido, long int cedula, short int edad);
// funciones de la clase.
// tipo de dato a retornar/ nombre / (lista de parametros),.
string getNombre();
string getApellido();
long int getCedula();
short int getEdad();
string toString();
void setNombre(string nombre);
void setApellido(string apellido);
void setCedula(long int cedula);
void setEdad(short int edad);
string convertirCedula(long int cedula);
string convertirEdad(short int edad);
private:
string nombre, apellido;
long int cedula;
short int edad;
};
// Constructor, fuera de la clase.
Cliente::Cliente(string nombre, string apellido, long int cedula, short int edad)
{
this->nombre=nombre;
this->apellido = apellido;
this->cedula = cedula;
this->edad = edad;
}
string Cliente::getApellido()
{
return apellido;
}
string Cliente::getNombre()
{
return nombre;
}
long int Cliente::getCedula()
{
return cedula;
}
short int Cliente::getEdad()
{
return edad;
}
void Cliente::setNombre(string nombre)
{
this->nombre = nombre;
}
void Cliente::setApellido(string apellido)
{
this->apellido = apellido;
}
void Cliente::setCedula(long int cedula)
{
this->cedula = cedula;
}
void Cliente::setEdad(short int edad)
{
this->edad = edad;
}
string Cliente::toString()
{
string total;
string cedulaTrans, edadTrans;
cedulaTrans = convertirCedula(cedula);
edadTrans = convertirEdad(edad);
total = nombre + "\n" + apellido + "\n" + cedulaTrans + "\n" + edadTrans;
return total;
}
string Cliente::convertirCedula(long int cedula)
{
stringstream flujo;
flujo << cedula;
return (flujo.str());
}
string Cliente::convertirEdad(short int edad)
{
stringstream flujo;
flujo << edad;
return (flujo.str());
}
class Banco
{
public:
Banco();
string agregar(Cliente c);
string mostrar();
private:
Cliente c[20];
int cont;
};
Banco::Banco()
{
this->cont=0;
}
string Banco::agregar(Cliente aux){
if(cont<20)
{
c[cont]=aux;
cont++;
return "Cliente agregado satisfactoriamente";
}
return "Banco lleno. No se puede agregar mas personas";
}
string Banco::mostrar()
{
string x;
for(int i=0; i<cont; i++)
{
x = x + c[i].toString();
}
return x;
}
int leerentero(string sms)
{
int aux;
cout << sms;
cin >> aux;
return aux;
}
Cliente leercliente()
{
string nombre;
string apellido;
short int edad;
long int cedula;
cout << "\nIngrese Nombre: " << endl;
cin.clear();
fflush(stdin);
getline(cin, nombre);
cout << "\nIngrese Apellido: " << endl;
cin.clear();
fflush(stdin);
getline(cin, apellido);
cout << "\nIngrese Cedula: " << endl;
cin >> cedula;
cout << "\nIngrese Edad: " << endl;
cin >> edad;
Cliente aux(nombre, apellido, cedula, edad);
return aux;
}
int main()
{
Banco b;
int opc;
do
{
cout << "\n[1]Agregar Persona. \n[2]Mostrar Personas. \n[3]Salir" << endl;
opc = leerentero("\nIngrese su opcion: ");
switch(opc)
{
case 1:
cout << b.agregar(leercliente()) << endl;
break;
case 2: cout << b.mostrar() << endl;
break;
case 3: return 0;
break;
}
}while(opc!=3);
return 0;
}