Você está na página 1de 8

#include"stdafx.

h"
#include <iostream>
#include <fstream>
using namespace std;

//Prototipo de funciones.
void Anadir();
void Eliminar();
void Editar();
void Ver();
void VerTodo();

//Definicion de estructura.
struct informacion
{
char nombre[25];
char apellido[25];
char telefono[25];
char celular[25];
char correo[25];
char direccion[100];
}
persona[70];

//Declaracion de variables globales.


int opcion;
int registro = 0;
char sn[10];

//Inicio main.
int main()
{
cout << endl;
cout << " //////// //////// //////// // // ////// //////// " <<
endl;
cout << " // // // // // //// // // // // // " <<
endl;
cout << " // // // // // // // // // // // " <<
endl;
cout << " //////// // //// ////// // //// // // //////// " <<
endl;
cout << " // // // // // // /// // // // // " <<
endl;
cout << " // // //////// //////// // // ////// // // " <<
endl;
cout << endl;
cout << "Agenda" << endl << endl;
cout << "1. Anadir un contacto." << endl << endl;
cout << "2. Eliminar un contacto." << endl << endl;
cout << "3. Editar un contacto." << endl << endl;
cout << "4. Ver informacion de un contacto." << endl << endl;
cout << "5. Ver todos los contactos." << endl << endl;
cout << "6. Salir." << endl << endl;
cout << "Numero de operacion a realizar: ";
cin >> opcion;
cin.ignore();
cout << endl;
switch (opcion)
{
case 1:
system("cls");
Anadir();
break;

case 2:
system("cls");
Eliminar();
break;

case 3:
system("cls");
Editar();
break;

case 4:
system("cls");
Ver();
break;

case 5:
system("cls");
VerTodo();
break;

case 6:
system("exit");
break;

default:
cout << "Operacion incorrecta. Escriba nuevamente la operacion a
realizar";
system("pause > nul");
system("cls");
main();
break;
}
return 0;
}
//Fin main.

//Definicion de funciones.
void Anadir()
{
cout << "Escriba la siguiente informacion del contacto.";
cout << endl << endl;
cout << "1. Nombre: ";
cin.getline(persona[registro].nombre, 25, '\n');
cout << endl;
cout << "2. Apellido: ";
cin.getline(persona[registro].apellido,25, '\n');
cout << endl;
cout << "3. Telefono: ";
cin.getline(persona[registro].telefono, 25, '\n');
cout << endl;
cout << "4. Celular: ";
cin.getline (persona[registro].celular,25, '\n');
cout << endl;
cout << "5. Correo: ";
cin.getline (persona[registro].correo,25,'\n');
cout << endl;
cout << "6. Direccion: ";
cin.getline(persona[registro].direccion,25,'\n');
cout << endl;
cout << "Anadir contacto a la agenda? [S/N]: ";
cin >> sn;
if ((strcmp(sn, "s") == 0) || (strcmp(sn, "S") == 0))
{
registro++;
cout << endl << "Contacto anadido." << endl;
system("pause > nul");
system("cls");
main();
}
if ((strcmp(sn, "n") == 0) || (strcmp(sn, "N") == 0))
{
cout << endl << "Contacto no anadido." << endl;
system("pause > nul");
system("vvcls");
main();
}
}
//Eliminar

void Eliminar()
{
int opcionEliminar;
cout << "Numero de registro a eliminar: ";
cin >> opcionEliminar;
cout << endl;
opcionEliminar--;
if (opcionEliminar < registro)
{
cout << "1. Nombre: ";
cout << persona[opcionEliminar].nombre;
cout << endl << endl;
cout << "2. Apellido: ";
cout << persona[opcionEliminar].apellido;
cout << endl << endl;
cout << "3. Telefono: ";
cout << persona[opcionEliminar].telefono;
cout << endl << endl;
cout << "4. Celular: ";
cout << persona[opcionEliminar].celular;
cout << endl << endl;
cout << "5. Correo: ";
cout << persona[opcionEliminar].correo;
cout << endl << endl;
cout << "6. Direccion: ";
cout << persona[opcionEliminar].direccion;
cout << endl << endl;
cout << "Eliminar contacto de la agenda? [S/N]: ";
cin >> sn;
if ((strcmp(sn, "s") == 0) || (strcmp(sn, "S") == 0))
{
persona[opcionEliminar] = persona[registro];
cout << endl << "Contacto eliminado." << endl;
system("pause > nul");
system("cls");
main();
}
if ((strcmp(sn, "n") == 0) || (strcmp(sn, "N") == 0))
{
cout << endl << "Contacto no eliminado." << endl;
system("pause > nul");
system("cls");
main();
}
}
else
{
cout << "Numero de registro no existente.";
system("pause > nul");
system("cls");
main();
}
}
//Editar

void Editar()
{
int opcionEditar;
int informacionEditar;
cout << "Numero de registro a editar: ";
cin >> opcionEditar;
cout << endl;
opcionEditar--;
if (opcionEditar < registro)
{
cout << "1. Nombre: ";
cout << persona[opcionEditar].nombre;
cout << endl << endl;
cout << "2. Apellido: ";
cout << persona[opcionEditar].apellido;
cout << endl << endl;
cout << "3. Telefono: ";
cout << persona[opcionEditar].telefono;
cout << endl << endl;
cout << "4. Celular: ";
cout << persona[opcionEditar].celular;
cout << endl << endl;
cout << "5. Correo: ";
cout << persona[opcionEditar].correo;
cout << endl << endl;
cout << "6. Direccion: ";
cout << persona[opcionEditar].direccion;
cout << endl << endl;
cout << "7. Todo. ";
cout << endl << endl;
cout << "Informacion a editar: ";
cin >> informacionEditar;
cout << endl;
switch (informacionEditar)
{
case 1:
cout << "1. Nombre: ";
cin >> persona[opcionEditar].nombre;
cout << endl;
break;
case 2:
cout << "2. Apellido: ";
cin >> persona[opcionEditar].apellido;
cout << endl;
break;
case 3:
cout << "3. Telefono: ";
cin >> persona[opcionEditar].telefono;
cout << endl;
break;
case 4:
cout << "4. Celular: ";
cin >> persona[opcionEditar].celular;
cout << endl;
break;
case 5:
cout << "5. Correo: ";
cin >> persona[opcionEditar].correo;
cout << endl;
break;
case 6:
cout << "6. Direccion: ";
cin >> persona[opcionEditar].direccion;
cout << endl;
break;
case 7:
cout << "1. Nombre: ";
cin >> persona[opcionEditar].nombre;
cout << endl;
cout << "2. Apellido: ";
cin >> persona[opcionEditar].apellido;
cout << endl;
cout << "3. Telefono: ";
cin >> persona[opcionEditar].telefono;
cout << endl;
cout << "4. Celular: ";
cin >> persona[opcionEditar].celular;
cout << endl;
cout << "5. Correo: ";
cin >> persona[opcionEditar].correo;
cout << endl;
cout << "6. Direccion: ";
cin >> persona[opcionEditar].direccion;
cout << endl;
break;
default:
cout << "Operacion incorrecta. Escriba nuevamente la informacion
a editar.";
system("pause > nul");
system("cls");
Editar();
break;
}
system("pause > nul");
system("cls");
main();
}
else
{
cout << "Numero de registro no existente.";
system("pause > nul");
system("cls");
main();
}
}
//ver contactos

void Ver()
{
int ver;
cout << "Numero de registro a ver: ";
cin >> ver;
cout << endl;
ver--;
if (ver < registro)
{
cout << "1. Nombre: ";
cout << persona[ver].nombre;
cout << endl << endl;
cout << "2. Apellido: ";
cout << persona[ver].apellido;
cout << endl << endl;
cout << "3. Telefono: ";
cout << persona[ver].telefono;
cout << endl << endl;
cout << "4. Celular: ";
cout << persona[ver].celular;
cout << endl << endl;
cout << "5. Correo: ";
cout << persona[ver].correo;
cout << endl << endl;
cout << "6. Direccion: ";
cout << persona[ver].direccion;
cout << endl << endl;
system("pause > nul");
system("cls");
main();
}
else
{
cout << "Numero de registro no existente.";
system("pause > nul");
system("cls");
main();
}
}
//ver todos los contactos
void VerTodo()
{
int verTodo;
for (verTodo = 0; verTodo < registro; verTodo++)
{
cout << "1. Nombre: ";
cout << persona[verTodo].nombre;
cout << endl << endl;
cout << "2. Apellido: ";
cout << persona[verTodo].apellido;
cout << endl << endl;
cout << "3. Telefono: ";
cout << persona[verTodo].telefono;
cout << endl << endl;
cout << "4. Celular: ";
cout << persona[verTodo].celular;
cout << endl << endl;
cout << "5. Correo: ";
cout << persona[verTodo].correo;
cout << endl << endl;
cout << "6. Direccion: ";
cout << persona[verTodo].direccion;
cout << endl << endl;
system("pause > nul");
cout << "----------------------------------------" << endl << endl;
}
system("pause > nul");
system("cls");
main();
}

void exportar() {
ofstream guardar, guardar2;
int verTodo;
guardar.open("Agenda.doc");
guardar2.open("Agenda.xls");
registro = 0;

for (verTodo = 0; verTodo < registro; verTodo++) {


guardar
guardar<< "1. Nombre: ";
guardar << persona[verTodo].nombre;
guardar << endl << endl;
cout << "2. Apellido: ";
cout << persona[verTodo].apellido;
cout << endl << endl;
cout << "3. Telefono: ";
cout << persona[verTodo].telefono;
cout << endl << endl;
cout << "4. Celular: ";
cout << persona[verTodo].celular;
cout << endl << endl;
cout << "5. Correo: ";
cout << persona[verTodo].correo;
cout << endl << endl;
cout << "6. Direccion: ";
cout << persona[verTodo].direccion;
cout << endl << endl;
system("pause > nul");
cout << "----------------------------------------" << endl << endl;
}
}

Você também pode gostar