Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: berbash116 en 8 Enero 2019, 13:31 pm



Título: combinar programas
Publicado por: berbash116 en 8 Enero 2019, 13:31 pm
Hola me estan pidiendo encontrar la forma de juntar estos 2 codigo que les dejo aca abajo pero lo he intentado de diversas manera pero no me resulta

Código
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. struct nodo{
  6.       float nro;        // en este caso es un numero entero
  7.       struct nodo *sgte;
  8. };
  9.  
  10. typedef struct nodo *Tlista;
  11.  
  12. void insertarInicio(Tlista &lista, float valor)
  13. {
  14.    Tlista q;
  15.    q = new(struct nodo);
  16.    q->nro = valor;
  17.    q->sgte = lista;
  18.    lista  = q;
  19. }
  20.  
  21. void insertarFinal(Tlista &lista, float valor)
  22. {
  23.    Tlista t, q = new(struct nodo);
  24.  
  25.    q->nro  = valor;
  26.    q->sgte = NULL;
  27.  
  28.    if(lista==NULL)
  29.    {
  30.        lista = q;
  31.    }
  32.    else
  33.    {
  34.        t = lista;
  35.        while(t->sgte!=NULL)
  36.        {
  37.            t = t->sgte;
  38.        }
  39.        t->sgte = q;
  40.    }
  41.  
  42. }
  43.  
  44. int insertarAntesDespues()
  45. {
  46.    int _op, band;
  47.  
  48.   printf("\t 1. Antes de la posicion           \n");
  49.   printf("\t 2. Despues de la posicion         \n");
  50.   printf("\n\t Opcion : ");
  51.   scanf("%d",&_op);
  52.  
  53.    if(_op==1)
  54.        band = -1;
  55.    else
  56.        band = 0;
  57.  
  58.    return band;
  59. }
  60.  
  61. void insertarElemento(Tlista &lista, float valor, int pos)
  62. {
  63.    Tlista q, t;
  64.    int i;
  65.    q = new(struct nodo);
  66.    q->nro = valor;
  67.  
  68.    if(pos==1)
  69.    {
  70.        q->sgte = lista;
  71.        lista = q;
  72.    }
  73.    else
  74.    {
  75.        int x = insertarAntesDespues();
  76.        t = lista;
  77.  
  78.        for(i=1; t!=NULL; i++)
  79.        {
  80.            if(i==pos+x)
  81.            {
  82.                q->sgte = t->sgte;
  83.                t->sgte = q;
  84.                return;
  85.            }
  86.            t = t->sgte;
  87.        }
  88.    }
  89.    printf("   Error...Posicion no encontrada..!");
  90. }
  91.  
  92. void buscarElemento(Tlista lista, float valor)
  93. {
  94.    Tlista q = lista;
  95.    int i = 1, band = 0;
  96.  
  97.    while(q!=NULL)
  98.    {
  99.        if(q->nro==valor)
  100.        {
  101.            cout<<endl<<" Encontrada en posicion "<< i <<endl;
  102.            band = 1;
  103.        }
  104.        q = q->sgte;
  105.        i++;
  106.    }
  107.  
  108.    if(band==0)
  109.    printf("\n\n Numero no encontrado..!");
  110. }
  111.  
  112. void reportarLista(Tlista lista)
  113. {
  114.     int i = 0;
  115.  
  116.     while(lista != NULL)
  117.     {
  118.          cout <<' '<< i+1 <<") " << lista->nro << endl;
  119.          lista = lista->sgte;
  120.          i++;
  121.     }
  122. }
  123.  
  124.  
  125. void eliminarElemento(Tlista &lista, float valor)
  126. {
  127.    Tlista p, ant;
  128.    p = lista;
  129.  
  130.    if(lista!=NULL)
  131.    {
  132.        while(p!=NULL)
  133.        {
  134.            if(p->nro==valor)
  135.            {
  136.                if(p==lista)
  137.                    lista = lista->sgte;
  138.                else
  139.                    ant->sgte = p->sgte;
  140.  
  141.                delete(p);
  142.                return;
  143.            }
  144.            ant = p;
  145.            p = p->sgte;
  146.        }
  147.    }
  148.    else
  149.    printf(" Lista vacia..!");
  150. }
  151.  
  152. void eliminaRepetidos(Tlista &lista, float valor)
  153. {
  154.    Tlista q, ant;
  155.    q = lista;
  156.    ant = lista;
  157.  
  158.    while(q!=NULL)
  159.    {
  160.        if(q->nro==valor)
  161.        {
  162.            if(q==lista) // primero elemento
  163.            {
  164.                lista = lista->sgte;
  165.                delete(q);
  166.                q = lista;
  167.            }
  168.            else
  169.            {
  170.                ant->sgte = q->sgte;
  171.                delete(q);
  172.                q = ant->sgte;
  173.            }
  174.        }
  175.        else
  176.        {
  177.            ant = q;
  178.            q = q->sgte;
  179.        }
  180.  
  181.    }// fin del while
  182.  
  183.   printf("\n\n Valores eliminados..!");
  184. }
  185.  
  186.  
  187. /*                        Funcion Principal
  188. ---------------------------------------------------------------------*/
  189. struct dati{
  190. float mod;
  191. float ang;
  192. };
  193. int main()
  194. {
  195.    Tlista lista = NULL;
  196.    int op;     // opcion del menu
  197.    float _dato;  // elemenento a ingresar
  198.    int pos;    // posicion a insertar
  199.  
  200.  
  201.    do
  202.    {
  203.        printf("LISTA ENLAZADA SIMPLE \n");
  204.        printf("1. INSERTAR AL INICIO\n");
  205.        printf("2. INSERTAR AL FINAL\n");
  206.        printf("3. INSERTAR EN UNA POSICION \n");
  207.        printf("4. BUSCAR ELEMENTO\n");
  208.        printf("5. ELIMINAR ELEMENTO 'V'\n");
  209.        printf("6. ELIMINAR ELEMENTOS CON VALOR 'V\n");
  210.        printf("7. SALIR \n");
  211.        printf("INGRESE OPCION:  ");
  212.  
  213.        scanf("%d",&op);
  214.  
  215.  
  216.  
  217.  
  218.        switch(op)
  219.        {
  220.            case 1:
  221.  
  222.                 printf("\nNUMERO A INSERTAR ");
  223.                 scanf("%f",&_dato);
  224.                 insertarInicio(lista, _dato);
  225.  
  226.                 printf("\nMOSTRANDO LISTA\n");
  227.                 reportarLista(lista);
  228.            break;
  229.  
  230.  
  231.            case 2:
  232.  
  233.                 printf("\nNUMERO A INSERTAR ");
  234.                 scanf("%f",&_dato);
  235.                 insertarFinal(lista, _dato );
  236.  
  237.                 printf("\nMOSTRANDO LISTA\n");
  238.                 reportarLista(lista);
  239.            break;
  240.  
  241.  
  242.            case 3:
  243.  
  244.                  printf("\nNUMERO A INSERTAR ");
  245.                 scanf("%f",&_dato);
  246.                 printf("\nPosicion : ");
  247.                 scanf("%d",&pos);
  248.                 insertarElemento(lista, _dato, pos);
  249.  
  250.                 printf("\nMOSTRANDO LISTA\n");
  251.                 reportarLista(lista);
  252.            break;
  253.  
  254.            case 4:
  255.  
  256.                   printf("\nValor a buscar:  ");
  257.                 scanf("%f",&_dato);
  258.                 buscarElemento(lista, _dato);
  259.            break;
  260.  
  261.            case 5:                
  262.  
  263.                   printf("\nValor a eliminar:  ");
  264.                 scanf("%f",&_dato);
  265.                eliminarElemento(lista, _dato);
  266.  
  267.                printf("\nMOSTRANDO LISTA\n");
  268.                 reportarLista(lista);
  269.            break;
  270.  
  271.            case 6:
  272.  
  273.                 printf("\nValor repetido a eliminar:  ");
  274.                 scanf("%f",&_dato);
  275.                eliminaRepetidos(lista, _dato);
  276.  
  277.                printf("\nMOSTRANDO LISTA\n");
  278.                 reportarLista(lista);
  279.            break;
  280.  
  281.                    }
  282.  
  283.        printf("\n\n");
  284.        system("pause");  system("cls");
  285.  
  286.    }while(op<7);
  287.  
  288.  
  289.   return 0;
  290. }

y este codigo

Código
  1. #include<iostream>
  2. #include<complex>
  3.  
  4. using namespace std;
  5. double ang,rest,re,im,pot,mod;
  6.  
  7. int main()
  8. {
  9.  
  10. cout<<"Por favor introduzca la parte real de su numero complejo: ";
  11. cin>>re;
  12. cout<<endl<<"Ahora la parte imaginaria: ";
  13. cin>>im;
  14.  
  15.  
  16. ang = (atan (im/re))* 57,29578;
  17. mod = sqrt ((re*re)+(im*im));
  18.  
  19. cout<<"La expresion en forma polar es: ("<<mod<<" con angulo "<<ang<<")"<<endl;
  20.  
  21. system ("pause");
  22. cin.get();
  23. return 0;
  24. }


Título: Re: combinar programas
Publicado por: febef en 8 Enero 2019, 19:13 pm
Buenas!

Como lo intentaste?

Coméntanos un poco más...

Te doy un par de ideas:

»  a los main de cada programa cambia les el nombre por unos descriptivos a su funcionalidad
»  luego genera un main con un menú que te deje seleccionar un programa o el otro y ahí ejecutas la función correspondiente que renombraste.

Expone como encaras el tema para poder ayudarte más.


Saludos