elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / multiplexar matriz 8x8 en: 17 Octubre 2019, 18:24 pm
hola tengo una duda sobre como multiplexar una matriz led de 8x8 por codigo ya que no tengo un multiplexor para realizar esta tarea
2  Programación / Programación C/C++ / combinar programas 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. }
3  Programación / Programación C/C++ / Re: ingresar datos a lista en: 7 Enero 2019, 14:36 pm
hola de nuevo, como dicjiste realice la estructura pero cunado corro el programa no me lo guarda en la listam, es mas, me guarda un 0

Código:
//Cola de datos.Programa de prueba
#include<iostream>
#include "list.h"
#include<cmath>
using namespace std;

template<class T>
void testList(List<T> &listObject, const char *type)
{
cout<<"Programa de prueba de una cola de valores "<<type<<".\n";
cout<<"Ingrese una de las siguientes opciones:\n"
<<" 1 para insertar al final de la cola.\n"
<<" 2 para eliminar al principio de la cola.\n"
<<" 3 para finalizar.\n";

struct polar {
double modulo,angulo;
};
int choice;

T polar;
do
{
cout<<"? ";
cin>>choice;
switch(choice)
{

case 1:

double angulo,real,imaginario,modulo;


cout<<"Por favor introduzca la parte real de su numero complejo: ";
cin>>real;
cout<<endl<<"Ahora la parte imaginaria: ";
cin>>imaginario;


angulo = (atan (imaginario/real))* 57,29578;
modulo = sqrt (real*real+(imaginario*imaginario));

cout<<"La expresion en forma polar es: ("<<modulo<<" con angulo "<<angulo<<")"<<endl;

listObject.insertAtBack(polar);
listObject.print();
break;

case 2:
if(listObject.removeFromFront(polar))
cout<<polar<<" removido de la cola.\n";
listObject.print();
break;
}
}
while(choice!=3);
cout<<"Finalizar prueba de cola.\n";
}
int main()
{
List<int>integerQueue;
testList(integerQueue,"entero");

List<double>doubleQueue;
testList(doubleQueue,"doble precision");

return 0;
}
4  Programación / Programación C/C++ / ingresar datos a lista en: 4 Enero 2019, 04:03 am
Hola como estan

Necesito ayuda para ingresar 2 datos en una lista, ya tengo un codigo en donde me permite agregar o quitarvalores de una lista, pero no me permite hacerlo para 2, en mi caso quiero registras valores rectangulares y polares.
les dejo los codigos que tengo

Código:
#include<iostream>
#include<cmath>

//Programa para transformar de Rectangular a Polar

using namespace std;
int n,i;
double ang,rest,re,im,pot,mod;

int main()
{
cout<<"\nIngrese cantidad de Tensiones Complejas\n";
cin>>n;

for(i=1;i<=n;i++)
{
cout<<"Por favor introduzca la parte real de su numero complejo"<<i<<":  \n";
cin>>re;
cout<<endl<<"Ahora la parte imaginaria"<<i<<": \n";
cin>>im;


ang = (atan (im/re))* 57,29578;
mod = sqrt ((re*re)+(im*im));

cout<<"La expresion en forma polar"<<i<<" es: "<<mod<<" con angulo "<<ang<<"\n"<<endl;

}

system ("pause");
cin.get();
return 0;
}

Código:
// Programa para pasar de Polar a Rctangular
#include<iostream>
#include<cmath>

using namespace std;
int i,n;
double ang,rest,re,im,pot,mod,rad;

int main()
{
cout<<"\nIngrese cantidad de Tensiones Polares  :    ";
cin>>n;

for(i=1;i<=n;i++)
{
cout<<"Por favor introduzca el modulo: "<<i<<":   \n";
cin>>mod;
cout<<endl<<"Ahora el angulo en grados: "<<i<<":   \n";
cin>>ang;

rad=ang*3.1416/180.0;
re = mod * cos (rad);
im = mod * sin(rad);

cout<<"La expresion en forma rectangular"<<i<<" es: "<<re<<"   "<<im<<"j \n"<<endl;

}
system ("pause");
cin.get();
return 0;
}
5  Programación / Programación C/C++ / Re: Listas enlazadas por punteros en: 3 Enero 2019, 02:05 am
gracias igual me hacen falta jajajaj pero como puedo agregarlo al programa que ya tengo
es copiar y pegar o tengo que arreglarlo de algun modo??
6  Programación / Programación C/C++ / Listas enlazadas por punteros (SOLUCIONADO) en: 3 Enero 2019, 01:30 am
que tal, tengo una tarea en donde me piden: "elaborar un programa para anotar en una lista enlazada
 por punteros, el voltaje y la corriente a través de los componentes de un circuito de n componentes resistivos puros, calculando cada vez el valor de la resistencia correspondiente"

tengo hecho un programa en el cual puedo ingresar estas n variables y hacer el calculo para que me de la resistencia como resultado, mi problema es que no entiendo como hacer una lista enlazada por punteros, ojala puedan ayudarme.

les dejo el programa que hice:

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<iostream>

using std::cin;
using std::cout;

main ()
{
   int n,i;
   float r,v,c;
   
   cout << "\ningrese cantidad de resistencias a calcular   : \n";
   cin>> n;
   
   for(i=1;i<=n;i++)
   {
      cout<<"\ningrese tension "<< i<<":"<<"\n";
      cin>> v;
      cout<< "\ningrese corriente "<< i<<":"<<"\n";
      cin>> c;
      
      r= (v/c);
      
      cout<< "el resultado de la resistencia R "<< i << "   es  :"<< r<<"\n";
      
   }
   system ("pause");
   return 0;
}
7  Programación / Programación C/C++ / Re: porque aparece Id returned 1 exit status??? en: 3 Enero 2019, 01:26 am
aaaa dale, muchas gracias.
8  Programación / Programación C/C++ / porque aparece Id returned 1 exit status??? (solucionado) en: 1 Enero 2019, 23:46 pm
hola como estan?, hace un tiempo mi profesor nos dio este programa sin decirnos la gran cosa solo dijo "intenten ejecutarla para antes del examen", lo arregle y todo pero aun me arroja error, ojala puedan ayudarme

les dejo el programa

      // Fig. 17.4: list.h
      // Template List class definition.
      #ifndef LIST_H
      #define LIST_H
      
      #include <iostream>
      
      using std::cout;
      
    #include <new>
    #include "list"  // ListNode class definition
    
    template< class NODETYPE >
    class List {
    
    public:
       List();      // constructor
       ~List();     // destructor
       void insertAtFront( const NODETYPE & );
       void insertAtBack( const NODETYPE & );
       bool removeFromFront( NODETYPE & );    
       bool removeFromBack( NODETYPE & );    
       bool isEmpty() const;                  
       void print() const;                    
    
    private:
       List< NODETYPE > *firstPtr;  // pointer to first node
       List< NODETYPE > *lastPtr;   // pointer to last node
    
       // utility function to allocate new node
       List< NODETYPE > *getNewNode( const NODETYPE & );
    
    }; // end class List
    
    // default constructor
    template< class NODETYPE >
    List< NODETYPE >::List()
       : firstPtr( 0 ),
         lastPtr( 0 )
    {
       // empty body
    
    } // end List constructor
    
    // destructor
    template< class NODETYPE >
    List< NODETYPE >::~List()
    {
       if ( !isEmpty() ) {    // List is not empty
          cout << "Destroying nodes ...\n";
    
          List< NODETYPE > *currentPtr = firstPtr;
          List< NODETYPE > *tempPtr;
    
          while ( currentPtr != 0 ) {  // delete remaining nodes
             tempPtr = currentPtr;
             cout << tempPtr->data << '\n';
             currentPtr = currentPtr->nextPtr;
             delete tempPtr;
    
          } // end while
    
       } // end if
    
       cout << "All nodes destroyed\n\n";
    
    } // end List destructor
    
    // insert node at front of list
    template< class NODETYPE >
    void List< NODETYPE >::insertAtFront( const NODETYPE &value )
    {
       List< NODETYPE > *newPtr = getNewNode( value );
    
       if ( isEmpty() )  // List is empty
         firstPtr = lastPtr = newPtr;
    
       else {  // List is not empty
          newPtr->nextPtr = firstPtr;
          firstPtr = newPtr;
    
       } // end else
    
    } // end function insertAtFront
    
    // insert node at back of list
    template< class NODETYPE >
    void List< NODETYPE >::insertAtBack( const NODETYPE &value )
    {
       List< NODETYPE > *newPtr = getNewNode( value );
    
       if ( isEmpty() )  // List is empty
          firstPtr = lastPtr = newPtr;
    
       else {  // List is not empty
          lastPtr->nextPtr = newPtr;
          lastPtr = newPtr;
    
       } // end else
  
  } // end function insertAtBack
  
  // delete node from front of list
  template< class NODETYPE >
  bool List< NODETYPE >::removeFromFront( NODETYPE &value )
  {
     if ( isEmpty() )  // List is empty
        return false;  // delete unsuccessful
  
     else {  
        List< NODETYPE > *tempPtr = firstPtr;
  
        if ( firstPtr == lastPtr )
           firstPtr = lastPtr = 0;
        else
           firstPtr = firstPtr->nextPtr;
  
        value = tempPtr->data;  // data being removed
        delete tempPtr;
  
        return true;  // delete successful
  
     } // end else
  
  } // end function removeFromFront
  
  // delete node from back of list
  template< class NODETYPE >
  bool List< NODETYPE >::removeFromBack( NODETYPE &value )
  {
     if ( isEmpty() )
        return false;  // delete unsuccessful
  
     else {
        List< NODETYPE > *tempPtr = lastPtr;
  
        if ( firstPtr == lastPtr )
           firstPtr = lastPtr = 0;
        else {
           List< NODETYPE > *currentPtr = firstPtr;
  
           // locate second-to-last element            
           while ( currentPtr->nextPtr != lastPtr )    
              currentPtr = currentPtr->nextPtr;        
  
           lastPtr = currentPtr;
           currentPtr->nextPtr = 0;
  
        } // end else
  
        value = tempPtr->data;
        delete tempPtr;
  
        return true;  // delete successful
  
     } // end else
  
  } // end function removeFromBack
  
  // is List empty?
  template< class NODETYPE >
  bool List< NODETYPE >::isEmpty() const
  {
     return firstPtr == 0;
    
  } // end function isEmpty
  
  // return pointer to newly allocated node
  template< class NODETYPE >
  List< NODETYPE > *List< NODETYPE >::getNewNode(
     const NODETYPE &value )
  {
     return new List< NODETYPE >( value );
  
  } // end function getNewNode
  
  // display contents of List
  template< class NODETYPE >
  void List< NODETYPE >::print() const
  {
     if ( isEmpty() ) {
        cout << "The list is empty\n\n";
        return;
  
     } // end if
  
     List< NODETYPE > *currentPtr = firstPtr;
  
     cout << "The list is: ";
  
     while ( currentPtr != 0 ) {
        cout << currentPtr->data << ' ';
        currentPtr = currentPtr->nextPtr;
  
     } // end while
  
     cout << "\n\n";
  
  } // end function print

  #endif
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines