Vous êtes sur la page 1sur 3

#include <iostream>

#include <conio.h>
using namespace std;

struct nodo
{
char
char
char
nodo

*nombre;
*telefono;
*correo;
*sig;

nodo()
{

// Constructor por defecto


sig=NULL;

}
nodo(char*A,char*B,char*C) //Constructor parametrizado
{
nombre=new char[strlen(A)+1];
strcpy(nombre,A);
correo=new char[strlen(B)+1];
strcpy(correo,B);
telefono=new char[strlen(C)+1];
strcpy(telefono,C);
sig=NULL;
}
};
class Agenda
{
private:
nodo *inicio;
public:
void InsertarI();
void InsertarF();
void imprimir();
Agenda()
{
inicio=NULL;
}
};

void Agenda::InsertarI()
{
char N[20], T[20], e[50];
cout<<"Tecle nombre";
cin>>N;
cout<<"Teclee Telefono";
cin>>T;
cout<<"Teclee correo";
cin>>e;

if(inicio==NULL)
inicio=new nodo(N,e,T);
else
{
nodo*a= new nodo(N,e,T);
a->sig=inicio;
inicio=a;
}
}
void Agenda::InsertarF()
{
char N[20],T[20],e[50];
cout<<"Teclee el nombre:";
cin>>N;
cout<<"Teclee el Telefono:";
cin>>T;
cout<<"Teclee el correo:";
cin>>e;
if(inicio==NULL)
inicio=new nodo(N,e,T);
else
{
nodo *s=inicio;
while(s->sig!=NULL)
{
nodo *h=new nodo(N,e,T);
s->sig=h;
}
}
}
void Agenda::imprimir()
{
if(inicio==NULL)
cout<<"Lista vacia";
else
{
nodo *f=inicio;
while(f!=NULL)
{
cout<<f->nombre<<endl;
cout<<f->telefono<<endl;
cout<<f->correo<<endl;
f=f->sig;
}
}
}
int main()
{
Agenda B;
B.InsertarI();

B.imprimir();
system("pause");
return 1;
}

Vous aimerez peut-être aussi