Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<string.h>
- #include<stdio.h>
- #include<conio.h>
- #include<fstream>
- using namespace std;
- struct nodo{
- int no;
- int isbn;
- char autor[50];
- char titulo[50];
- float venta;
- float compra;
- int exis;
- char editorial[30];
- struct nodo *sgte;
- };
- typedef struct nodo *PLista;
- struct nodo2{
- int clave;
- char nom[50];
- char tel[12];
- char correo[40];
- struct nodo2 *sgt;
- };
- typedef struct nodo2 *PLista2;
- PLista lista=NULL;
- PLista2 lista2=NULL;
- int cont=1;
- int menu();//no recibe nada y retorna el valor de la opcion que elegiste
- int getRealKey(int);//recibe lo que retorne getch y lo retorna en un valor que puedas usar
- int menu(){
- int op;
- do{
- cout<<"\n\t\t\t\t\t[ LIBRERIA ESPECIALIZADA EN DEPORTES ]\n";
- cout<<"Elige tu opcion\n1. Libros\n2. Editoriales \n3. Reportes \n4. Ayuda \n5. Acerca de ...\n6. Salir\n"<<endl;
- op=getche();//lee una entrada por teclado y te retorna el valor en codigo ascci
- op=getRealKey(op);//obtiene el valor real pulsado para usarse -1 si es invalido
- if(op==-1){
- cout<<"\t INGRESE UNA OPCION VALIDA\n";
- }
- cout<<"\n";
- }while(op==-1/*opcion invalida*/);
- return op;
- }
- int getRealKey(int key){
- int aux;
- switch(key){
- case 49://1 en ascii
- case 12:// valor del ctrl+i
- return 1;
- case 50://2 en ascii
- case 5://valor del ctrl+e
- return 2;
- case 51://3 en ascii
- case 18://valor del ctrl+r
- return 3;
- case 52://4 en ascii
- return 4;
- case 0:
- aux=getch();
- if(aux==59){
- return 4; //f1 en ascii
- }
- else if(aux==60){ //f2 en ascii
- return 5;
- }
- else{
- return -1;//no se encuentra la combinacion valida
- }
- case 53:
- return 5; //5 en ascii
- case 54:
- case 4:
- return 6;
- default:
- return -1;
- }
- }
- void menulib(){
- cout<<"1. Agregar Libros"<<endl;
- cout<<"2. Eliminar Libros"<<endl;
- cout<<"3. Modificar datos de Libros"<<endl;
- cout<<"4. Buscar Libros"<<endl;
- cout<<"5. Regresar al Menu Principal"<<endl;
- }
- void menuedi(){
- cout<<"1. Agregar Editorial"<<endl;
- cout<<"2. Eliminar Editorial"<<endl;
- cout<<"3. Modificar datos de Editorial"<<endl;
- cout<<"4. Buscar Editorial por clave"<<endl;
- cout<<"5. Regresar al Menu Principal"<<endl;
- }
- void menurep(){
- cout<<"1. Reporte de libros"<<endl;
- cout<<"2. Reporte de editoriales"<<endl;
- cout<<"3. Reporte de inventarios"<<endl;
- cout<<"4. Regresar al Menu Principal"<<endl;
- }
- void insertarlib(PLista &lista){
- PLista q = new(struct nodo);
- int is;
- cout<<" \nREGISTRO DE NUEVOS LIBROS"<<endl;
- cout<<"Numero de libro:"<<cont<<endl;
- q->no=cont;
- cout<<"Ingresa el ISBN:";
- cin>>is;
- q->isbn=is;
- cin.ignore();
- cout<<"Ingresa el autor:";
- cin.getline(q->autor, 50);
- cout<<"Ingresa titulo del libro:";
- cin.getline(q->titulo, 50);
- cout<<"Costo al publico:";
- cin>>q->venta;
- cout<<"Costo original:";
- cin>>q->compra;
- cout<<"Existencia del libro:";
- cin>>q->exis;
- cin.ignore();
- cout<<"Editorial:";
- cin.getline(q->editorial, 30);
- nodo *aux1=lista;
- nodo *aux2;
- while ((aux1!=NULL) && (aux1->isbn<is)){
- aux2=aux1;
- aux1=aux1->sgte;
- }
- if (lista==aux1){
- lista=q;
- }
- else{
- aux2->sgte=q;
- }
- q->sgte=aux1;
- cont++;
- }
- void eliminarlib(PLista &lista){
- int cod;
- PLista q,t;
- q=lista;
- cout<<"\nELIMINAR DATOS DE UN LIBRO"<<endl;
- cout<<"Ingrese ISBN: ";
- cin>>cod;
- while(q!=NULL){
- if(q->isbn==cod){
- if(q==lista)
- lista=lista->sgte;
- else
- t->sgte=q->sgte;
- delete(q);
- cout<<"REGISTRO ELIMINADO CON EXITO"<<endl;
- return;
- }else {
- t=q;
- q=q->sgte;
- }
- }
- if(q==NULL)
- cout<<"ISBN NO COINCIDE CON NINGUN LIBRO"<<endl;
- }
- void modlib(PLista lista){
- int x, cod;
- PLista q;
- q=lista;
- cout<<"ACTUALIZAR REGISTRO DE UN LIBRO"<<endl;
- cout<<"\tIngrese el ISBN al que desea realizar modificaciones: ";
- cin>>cod;
- while(q!=NULL){
- if(q->isbn==cod){
- system("cls");
- cout<<"Dato encontrado exitosamente"<<endl;
- cout<<"Numero: "<<q->no<<endl;
- cout<<"ISBN: "<<q->isbn<<endl;
- cout<<"Autor: "<<q->autor<<endl;
- cout<<"Titulo: "<<q->titulo<<endl;
- cout<<"Venta: "<<q->venta<<endl;
- cout<<"Compra: "<<q->compra<<endl;
- cout<<"Existencia: "<<q->exis<<endl;
- cout<<"Editorial: "<<q->editorial<<endl;
- cout<<"\t[ SELECCIONE EL CAMPO QUE DESEA MODIFICAR ]\n";
- cout<<" 1. ISBN "<<endl;
- cout<<" 2. Autor "<<endl;
- cout<<" 3. Titulo "<<endl;
- cout<<" 4. Venta "<<endl;
- cout<<" 5. Compra "<<endl;
- cout<<" 6. Existencia "<<endl;
- cout<<" 7. Editorial "<<endl;
- cout<<" 8. Cancelar"<<endl;
- cout<<"Ingrese Opcion: ";
- cin>>x;
- switch(x){
- case 1: cout<<"Ingrese ISBN: ";
- cin>>q->isbn;
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 2: cout<<"Ingrese Autor: ";
- cin.ignore();
- cin.getline(q->autor, 50);
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 3: cin.ignore();
- cout<<"Ingrese Titulo: ";
- cin.getline(q->titulo, 50);
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 4: cout<<"Ingrese el Costo al Publico:"<<endl;
- cin>>q->venta;
- break;
- case 5: cout<<"Ingrese el Costo Original: "<<endl;
- cin>>q->compra;
- break;
- case 6: cout<<"Ingrese la Existencia: "<<endl;
- cin>>q->exis;
- break;
- case 7: cout<<"Ingrese Editorial: "<<endl;
- cin.ignore();
- cin.getline(q->editorial,30);
- break;
- case 8: cout<<"Proceso de actualizacion cancelado"<<endl;
- break;
- default: cout<<"INGRESE UNA OPCION VALIDA"<<endl;
- cout<<"\n";
- system("pause");
- system("cls");
- }
- return;
- }else {
- q=q->sgte;
- }
- }
- if(q==NULL)
- cout<<"ISBN INCORRECTO"<<endl;
- }
- void Buscar(PLista q){
- int cod;
- if(q!=NULL){
- cout<<"\nINGRESE NUMERO A BUSCAR: ";
- cin>>cod;
- while(q!=NULL){
- if(q->isbn==cod){
- system("cls");
- cout<<"Dato encontrado exitosamente"<<endl;
- cout<<"Numero: "<<q->no<<endl;
- cout<<"ISBN: "<<q->isbn<<endl;
- cout<<"Autor: "<<q->autor<<endl;
- cout<<"Titulo: "<<q->titulo<<endl;
- cout<<"Venta: "<<q->venta<<endl;
- cout<<"Compra: "<<q->compra<<endl;
- cout<<"Existencia: "<<q->exis<<endl;
- cout<<"Editorial: "<<q->editorial<<endl;
- cout<<"\n";
- return;
- }else {
- q=q->sgte;
- }
- }
- if(q==NULL)
- cout<<"ISBN INCORRECTO"<<endl;
- }
- }
- void insertaredit(PLista2 &lista2){
- PLista2 q = new(struct nodo2);
- int cla;
- cout<<" \nREGISTRO DE NUEVAS EDITORIALES"<<endl;
- cout<<"Ingresa la clave: ";
- cin>>cla;
- q->clave=cla;
- cin.ignore();
- cout<<"Ingresa el nombre: ";
- cin.getline(q->nom, 50);
- cout<<"Ingresa telefono de contacto: ";
- cin>>q->tel;
- cin.ignore();
- cout<<"Ingresa un correo: ";
- cin.getline(q->correo, 40);
- cout<<"\n";
- cout<<"EDITORIAL REGISTRADA"<<endl;
- nodo2 *aux1=lista2;
- nodo2 *aux2;
- while ((aux1!=NULL) && (aux1->clave<cla)){
- aux2=aux1;
- aux1=aux1->sgt;
- }
- if(lista2==aux1){
- lista2=q;
- }
- else{
- aux2->sgt=q;
- }
- q->sgt=aux1;
- }
- void eliminaredit(PLista2 &lista2){
- int cod;
- PLista2 q,t;
- q=lista2;
- cout<<"\nELIMINAR DATOS DE UNA EDITORIAL"<<endl;
- cout<<"Ingrese clave de editorial a eliminar: ";
- cin>>cod;
- while(q!=NULL){
- if(q->clave==cod){
- if(q==lista2)
- lista2=lista2->sgt;
- else
- t->sgt=q->sgt;
- delete(q);
- cout<<"\tREGISTRO ELIMINADO CON EXITO"<<endl;
- return;
- }else {
- t=q;
- q=q->sgt;
- }
- }
- if(q==NULL)
- cout<<"NUMERO NO COINCIDE CON NINGUN LIBRO"<<endl;
- }
- void modedit(PLista2 lista2){
- int cod, x;
- PLista2 q;
- q=lista2;
- cout<<"ACTUALIZAR REGISTRO DE UNA EDITORIAL"<<endl;
- cout<<"\tIngrese la clave para la que desea realizar modificaciones: ";
- cin>>cod;
- while(q!=NULL){
- if(q->clave==cod){
- system("cls");
- cout<<"Dato encontrado exitosamente"<<endl;
- cout<<"Clave: "<<q->clave<<endl;
- cout<<"Nombre: "<<q->nom<<endl;
- cout<<"Telefono: "<<q->tel<<endl;
- cout<<"Correo: "<<q->correo<<endl;
- cout<<"\t[ SELECCIONE EL CAMPO QUE DESEA MODIFICAR ]\n";
- cout<<" 1. Clave "<<endl;
- cout<<" 2. Nombre "<<endl;
- cout<<" 3. Telefono "<<endl;
- cout<<" 4. Correo "<<endl;
- cout<<" 5. Cancelar "<<endl;
- cout<<"Ingrese Opcion: ";
- cin>>x;
- switch(x){
- case 1: cout<<"Ingrese Clave Nueva: ";
- cin>>q->clave;
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 2: cout<<"Ingrese Nombre: ";
- cin>>q->nom;
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 3: cout<<"Ingrese Telefono: ";
- cin>>q->tel;
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 4: cin.ignore();
- cout<<"Ingrese Correo: ";
- cin.getline(q->correo, 50);
- cout<<"\tREGISTRO ACTUALIZADO EXITOSAMENTE"<<endl;
- break;
- case 5: cout<<"Proceso de actualizacion cancelado"<<endl;
- break;
- default: cout<<"INGRESE UNA OPCION VALIDA"<<endl;
- }
- return;
- }else {
- q=q->sgt;
- }
- }
- if(q==NULL)
- cout<<"CLAVE INCORRECTO"<<endl;
- }
- void Buscaredit(PLista2 q){
- int cod;
- if(q!=NULL){
- cout<<"\nINGRESE CLAVE A BUSCAR: ";
- cin>>cod;
- while(q!=NULL){
- if(q->clave==cod){
- system("cls");
- cout<<"Clave: "<<q->clave<<endl;
- cout<<"Nombre: "<<q->nom<<endl;
- cout<<"Telefono: "<<q->tel<<endl;
- cout<<"Correo: "<<q->correo<<endl;
- cout<<"\n";
- return;
- }else {
- q=q->sgt;
- }
- }
- if(q==NULL)
- cout<<"CLAVE INCORRECTA"<<endl;
- }
- }
- void replibro(PLista q){
- while(q!=NULL){
- cout<<q->no<<"\t"<<q->isbn<<"\t"<<q->autor<<"\t\t"<<q->titulo<<"\t"<<q->venta<<"\t"<<q->compra<<"\t\t"<<q->exis<<"\t\t"<<q->editorial<<"\n";
- q=q->sgte;
- }
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- }
- void repedit(PLista2 q){
- while(q!=NULL){
- cout<<q->clave<<"\t"<<q->nom<<"\t"<<q->tel<<"\t"<<q->correo<<endl;
- q=q->sgt;
- }
- }
- void invlibro(PLista q){
- float inv=0,gan=0;
- while(q!=NULL){
- cout<<q->no<<"\t"<<q->isbn<<"\t"<<q->autor<<"\t\t"<<q->titulo<<"\t"<<q->venta<<"\t"<<q->compra<<"\t\t"<<q->exis<<"\t\t"<<q->editorial<<"\n";
- inv=inv+((q->compra)*(q->exis));
- gan=gan+((q->venta)*(q->exis));
- q=q->sgte;
- }
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- cout<<"Total invertido: "<<inv<<"\t";
- cout<<"Ganancia esperada: "<<gan<<endl;
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- }
- void acerca(){
- ifstream archivo;
- string texto;
- archivo.open("Acerca de.txt",ios::in);//Agregar el nombre del archivo
- if(archivo.fail()){
- cout<<"Archivo no encontrado";
- exit(1);
- }
- while(!archivo.eof()){
- getline(archivo,texto);
- cout<<texto<<endl;
- }
- archivo.close();
- }
- void ayuda(){
- ifstream archivo;
- string texto;
- archivo.open("Ayuda.txt",ios::in);//Agregar el nombre del archivo
- if(archivo.fail()){
- cout<<"Archivo no encontrado";
- exit(1);
- }
- while(!archivo.eof()){
- getline(archivo,texto);
- cout<<texto<<endl;
- }
- archivo.close();
- }
- ///--------------------------------F U N C I O N P R I N C I P A L--------------------------------------------------------
- int main(){
- int op;
- do{
- op=menu();
- switch(op){
- case 1:
- do{
- system("cls");
- menulib();
- cin>>op;
- cout<<endl;
- switch(op){
- case 1: insertarlib(lista);
- system("pause");
- system("cls");
- break;
- case 2: if(lista == NULL){
- cout<<"\t No hay algun libro registrado\n";
- }else{
- eliminarlib(lista);
- system("pause");
- system("cls");
- }
- break;
- case 3: if(lista==NULL){
- cout<<"\nNo hay algun libro registrado\n";
- }else{
- modlib(lista);
- }
- system("pause");
- system("cls");
- break;
- case 4: if(lista==NULL){
- cout<<"\n\tNo hay algun libro registrado\n";
- }else{
- Buscar(lista);
- }
- system("pause");
- system("cls");
- break;
- }
- }while(op!=5);
- system("cls");
- break;
- case 2:
- do{
- menuedi();
- cin>>op;
- cout<<endl;
- switch(op){
- case 1: insertaredit(lista2);
- system("pause");
- system("cls");
- break;
- case 2: if(lista2 == NULL){
- cout<<"\t No hay editorial registrada\n";
- }else{
- eliminaredit(lista2);
- }
- system("pause");
- system("cls");
- break;
- case 3: if(lista2==NULL){
- cout<<"\n\tNo hay editorial registrada\n";
- }else{
- modedit(lista2);
- }
- system("pause");
- system("cls");
- break;
- case 4: if(lista2==NULL){
- cout<<"\n\tNo hay editorial registrada\n";
- }else{
- Buscaredit(lista2);
- }
- system("pause");
- system("cls");
- break;
- }
- }while(op!=5);
- system("cls");
- break;
- case 3:
- do{
- menurep();
- cin>>op;
- system("cls");
- switch(op){
- case 1:
- if(lista==NULL){
- cout<<"No se encuentran registros para generar un reporte"<<endl;
- }else{
- cout<<"\t\t\t\tREPORTE DE LIBROS"<<endl;
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- cout<<"\t\t\t\t\t\t PRECIO"<<endl;
- cout<<"No.\t ISBN \t AUTOR \t\t TITULO \t VENTA \t COMPRA \t EXISTENCIA \t EDITORIAL\n ";
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- replibro(lista);
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- }
- system("pause");
- system("cls");
- break;
- case 2: if(lista2==NULL){
- cout<<"No se encuentran registros para generar un reporte"<<endl;
- }else{
- cout<<"\t\t\t\tREPORTE DE EDITORIALES"<<endl;
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- cout<<"CLAVE\t NOMBRE \t TELEFONO \t CORREO\n ";
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- repedit(lista2);
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- }
- system("pause");
- system("cls");
- break;
- case 3: if(lista==NULL){
- cout<<"No se encuentran registros para generar un reporte"<<endl;
- }else{
- cout<<"\t\t\t\tREPORTE DE INVENTARIO DE LIBROS"<<endl;
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- cout<<"\t\t\t\t\t\t PRECIO"<<endl;
- cout<<"No.\t ISBN \t AUTOR \t\t TITULO \t VENTA \t COMPRA \t EXISTENCIA \t EDITORIAL\n ";
- cout<<"--------------------------------------------------------------------------------------------------"<<endl;
- invlibro(lista);
- }
- }
- system("pause");
- system("cls");
- break;
- }while(op!=4);
- break;
- case 4: ayuda();
- system("pause");
- system("cls");
- break;
- case 5:acerca();
- system("pause");
- system("cls");
- break;
- case 6: exit(0);
- }
- }while(op!=6);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement