Está en la página 1de 4

#include <iostream> #include <fstream> #include <string> using namespace std; void menu(); struct alumno{ string nombre;

string apellido_paterno; string apellido_materno; }; struct nodo_alumno{ alumno usuario; nodo_alumno *siguiente; }; alumno usuario_aux; nodo_alumno *lista_alumnos; alumno leer_usuario(); nodo_alumno* insertar_inicio(nodo_alumno *Lista, alumno usuario_insertar) ; nodo_alumno* buscar(nodo_alumno *Lista, string x); nodo_alumno* buscar_anterior(nodo_alumno *Lista, string x); void eliminar(nodo_alumno *aux); void mostrar_lista(nodo_alumno *L);

void opcion(); int main(){ string Busqueda; system("color E"); system("Lista Simple"); int opciones; char continuar; do{ system("cls"); menu(); cout<<" cin>>opciones; switch(opciones){ case 1 : system("cls"); nodo_alumno *aux; lista_alumnos = NULL; cout << endl << " REGISTRAR ALUMNOS " << endl;

SELECCIONE OPCION : ";

cout << " -----------------" << endl << endl; lista_alumnos = insertar_inicio( lista_alumnos, leer_usuario()); cout << " ----------------------------------- " << endl; lista_alumnos = insertar_inicio( lista_alumnos, leer_usuario()); opcion(); break; case 2: system("cls"); cout<<endl<<" BUSCAR ALUMNO POR APELLIDO PATERNO"<<endl; cout<<" ----------------------------------"<<endl; cout<<endl<<" APELLIDO PATERNO DEL ALUMNO : "; cin>>Busqueda; aux = buscar(lista_alumnos,Busqueda); cout<<endl; cout<< " NOMBRE : " << aux->usuario.nombre<<endl; cout<< " APELLIDO PATERNO : " << aux->usuario.apellido_paterno<<endl; cout<< " APELLIDO MATERNO : " << aux->usuario.apellido_materno<<endl; opcion(); break; case 3: system("cls"); cout<<endl<<" APELLIDO PATERNO DEL 2do ALUMNO INGRESADO: "; cin>>Busqueda; eliminar(buscar(lista_alumnos,Busqueda)); opcion(); break; case 4: system("cls"); mostrar_lista(lista_alumnos); break;

case 5: system("cls"); return EXIT_SUCCESS; opcion(); break; } cout << endl; cout<<"Desea Continuar (S/N) : "; cin>>continuar;} while (continuar=='s');} void opcion(){ float alternativas; cout<<endl<<" -----------------------------"<<endl; cout<< " 1. Regresar Al Menu Principal"<<endl; cout<< " 2. Abandonar Aplicacion "<<endl;

cout<< " -----------------------------"<<endl; cout<< " OPCION : "; cin>>alternativas; while(alternativas!=1 && alternativas!=2){ system("cls"); cout<<"-------------------------------"<<endl; cout<<" OPCION NO VALIDA "<<endl; cout<<"-------------------------------"<<endl; cout<<"1. REGRESAR AL MENU PRINCIPAL "<<endl; cout<<"2. SALIR DE LA APLICACION "<<endl; cout<<"-------------------------------"<<endl; cout<<"OPCION : "; cin>>alternativas;} if ( alternativas==1 ){ system("cls"); main();} else{ return; }} void menu(){ cout<<endl<<endl<<endl; cout<<" * * * * * * * * cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" *> cout<<" * * * * * * * * cout<<endl; } /* IMPLEMENTACION DE FUNCIONES */ /* FUNCION QUE MUESTRA TODA LA void mostrar_lista(nodo_alumno nodo_alumno *paux; paux = L; while(paux != NULL){ cout <<" DATOS INGRESADOS cout <<" ---------------cout <<" NOMBRE cout <<" APELLIDO PATERNO cout <<" APELLIDO MATERNO paux = paux->siguiente; }} LISTA */ *L){

* * * M E N U * * * * * * * * * * --------<* <* <* 1. REGISTRAR ALUMNO <* 2. BUSCAR ALUMNO <* 3. ELIMINAR ALUMNO <* 4. MOSTRAR ALUMNOS <* 5. SALIR DE LA APLICACION <* <* <* * * * * * * * * * * * * * * * * * *

"<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl; "<<endl;

" << endl; " << endl; : " << paux->usuario.nombre << endl; : " << paux->usuario.apellido_paterno << endl; : " << paux->usuario.apellido_materno << endl;

/* INSERTA NODO AL INICIO DE LA LISTA */ nodo_alumno* insertar_inicio(nodo_alumno *Lista, alumno usuario_insertar){ nodo_alumno *tmpnodo;

tmpnodo = new nodo_alumno; tmpnodo->usuario= usuario_insertar; if (Lista == NULL){ tmpnodo->siguiente = NULL; Lista = tmpnodo; } else{ tmpnodo->siguiente = Lista; Lista = tmpnodo; } return Lista; } alumno leer_usuario(){ cout << " INGRESAR NOMBRE DE ALUMNO : " ; cin >> usuario_aux.nombre; cout << " INGRESAR APELLIDO PATERNO DE ALUMNO : "; cin >> usuario_aux.apellido_paterno; cout << " INGRESAR APELLIDO MATERNO DE ALUMNO : "; cin >> usuario_aux.apellido_materno; return usuario_aux;}

/* ELIMINA UN NODO CUALQUIERA DE LA LISTA */ void eliminar( nodo_alumno *aux){ nodo_alumno *aux_eliminar; aux_eliminar = aux->siguiente; aux->siguiente = aux_eliminar->siguiente; delete aux_eliminar; } /* BUSCA UN DATO Y DEVUELVE UN PUNTERO AL NODO QUE LO CONTIENE */ nodo_alumno* buscar(nodo_alumno *Lista, string x){ nodo_alumno *aux; aux = Lista; while(aux && aux->usuario.apellido_paterno!=x){ aux = aux->siguiente; } return aux; }

/* BUSCA EL NODO ANTERIOR AL NODO QUE CONTIENE EL DATO INDICADO */ nodo_alumno* buscar_anterior(nodo_alumno *Lista, string x){ nodo_alumno *aux; aux = Lista; while(aux && aux->siguiente->usuario.apellido_paterno!= x){ aux = aux->siguiente; } return aux; }

También podría gustarte