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

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: 1 2 3 [4] 5 6 7
31  Programación / Programación C/C++ / Re: Ayuda con un programa en C++ en: 3 Diciembre 2012, 20:03 pm
Muchas gracias! Pero hay un problema, cuando ya he introducido todos los números, se me cierra el programa de repente, sin poder leer el resultado. ¿Podrías hacer algo? Por lo demás genial, muchas gracias por ayudarme.

Ya he modificado el code para que se pueda ver el resultado un saludo. Si acaso sigue sin irte añade otro getchar() mas.
32  Programación / Programación C/C++ / Re: Ayuda con un programa en C++ en: 3 Diciembre 2012, 19:21 pm
Espero que te sirva si tienes dudas pregunta. Un saludo.

Código
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. bool primo(int n)
  7. {
  8.    int res;
  9.    for(int w=2; w < n-1; w++)
  10.    {
  11.        res = n % w;
  12.        if(res==0) return false;
  13.  
  14.    }
  15.  
  16.    return true;
  17. }
  18.  
  19. int main()
  20. {
  21.    int numero[100];
  22.    bool primos = false;
  23.    int cont = 0;
  24.  
  25.    cout << "Introducza los numeros" << endl;
  26.  
  27.    for(int j=0;j<10;j++)
  28.    {
  29.        cout << "Numero " << j+1 <<": ";
  30.        cin >> numero[j];
  31.  
  32.    }
  33.  
  34.    for(int h=0;h<10;h++)
  35.    {
  36.        primos = primo(numero[h]);
  37.        if(primos==true)
  38.        {
  39.            cout << numero[h]<< " ";
  40.            cont++;
  41.        }
  42.    }
  43.  
  44.    cout << "Hay " << cont << " numeros primos"<<endl;
  45.    getchar();
  46.    return 0;
  47.  
  48. }
33  Programación / Programación C/C++ / Re: quisiera que me digeran si este foro q estoy haciendo esta bien c++ en: 3 Diciembre 2012, 18:04 pm

                   sytem("pause");
                 
               


Con eso no creo que te compile tampoco
34  Programación / Programación C/C++ / Re: quisiera que me digeran si este foro q estoy haciendo esta bien c++ en: 3 Diciembre 2012, 18:04 pm
podrías poner que te pida los valores en el constructor de la clase y ser un poco mas ordenado con los saltos de linea y tal.
35  Programación / Programación C/C++ / Ayuda con Juego en: 2 Diciembre 2012, 22:24 pm
Hola que tal? Pues miren resulta que estoy haciendo un juego en c++ con allegro y esto es lo que llevo hecho, lo que me gustaría es que le echaran un vistazo al codigo para ver si se puede depurar y si hay algo que pueda mejorarse, tambien tengo que hacer unas rutinas para que las balas que se disparen colisionen con algun objeto y se reduzca la vida de este. ¿Como y donde seria correcto hacer esto? Si quieren las imagenes y eso puedo subir el proyecto a algun lado solo avisen. Gracias.



Código
  1. #include <allegro.h>
  2. #include "inicia.h"
  3. #include <iostream>
  4. #include <vector>
  5.  
  6.  
  7. BITMAP *buffer;
  8. //BITMAP *nave;
  9. const int ANCHO = 500;
  10. const int ALTO = 450;
  11. int i = 900/2;
  12.  
  13.  
  14.  
  15.  
  16. using namespace std;
  17.  
  18. class DISPARO
  19. {
  20.    private:
  21.    BITMAP *bala;
  22.    int x;
  23.    int y;
  24.    int dx;
  25.    int dy;
  26.  
  27.    public:
  28.  
  29.  
  30.    DISPARO(int _x,int _y,int _dx,int _dy);
  31.    int getx(void) const {return x;}
  32.    int gety(void) const {return y;}
  33.    void mover(void);
  34.    void pintar(void);
  35.  
  36.  
  37. };
  38.  
  39. DISPARO::DISPARO(int _x,int _y,int _dx,int _dy)//CONSTRUCTOR
  40.    {
  41.        x = _x;
  42.        y = _y;
  43.        dx = _dx;
  44.        dy = _dy;
  45.        if(dy > 0) bala = load_bitmap(".\\imagenes\\bala2.bmp",NULL);
  46.        else bala = load_bitmap(".\\imagenes\\bala3.bmp",NULL);
  47.    }
  48.  
  49. void DISPARO::pintar(void)
  50. {
  51.  
  52.   masked_blit( bala, buffer, 0, 0, x, y, 42, 43);
  53.  
  54. }
  55.  
  56. void DISPARO::mover(void)
  57. {
  58. y-=dy;
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65. /**************************************CLASE NAVE**********************************/
  66.  
  67.  
  68. class NAVE
  69. {
  70.    private:
  71.    BITMAP *nave;
  72.    int x;
  73.    int y;
  74.    int direccion;
  75.    int vida;
  76.    int ndisparos;
  77.    int maxdisp;
  78.    int dsw;
  79.    int cont;
  80.  
  81.    public:
  82.  
  83.  
  84.    NAVE(int _x=0,int _y=0,int _direccion=0,int _vida=50,int _maxdisp=5);
  85.  
  86.    int getx(void) const {return x;}
  87.    int gety(void) const {return y;}
  88.    int getdireccion(void) const {return direccion;}
  89.    int getvida(void) const {return vida;}
  90.  
  91.    void setx(int _x){x = _x;}
  92.    void sety(int _y){y = _y;}
  93.    void setdireccion(int _direccion){direccion = _direccion;}
  94.    void setvida(int _vida){vida = _vida;}
  95.  
  96.    void mover(void);
  97.    void pintar(void);
  98.    DISPARO *disparar(void);
  99.  
  100.  
  101.  
  102.  
  103. };
  104.  
  105. NAVE::NAVE(int _x,int _y,int _direccion,int _vida,int _maxdisp) //CONSTRUCTOR
  106.    {
  107.        x = _x;
  108.        y = _y;
  109.        direccion = _direccion;
  110.        vida = _vida;
  111.        nave = load_bitmap(".\\imagenes\\nave.bmp",NULL);
  112.        maxdisp = _maxdisp;
  113.        cont = 20;
  114.    }
  115.  
  116. void NAVE::mover(void)
  117. {
  118.    if(key[KEY_RIGHT]){ direccion = 2; x += 2; }
  119.  
  120.    else if(key[KEY_LEFT]) { direccion = 0; x -= 2; }
  121.  
  122.    if(key[KEY_UP])   { direccion = 3; y -= 2; }
  123.  
  124.    else if(key[KEY_DOWN]) { direccion = 1; y += 2; }
  125.  
  126.  
  127.    if(x-2 < 0) x +=2;
  128.        else if(x+2 > ANCHO-44) x -=2;
  129.  
  130.       if(y-2 < 0) y +=2;
  131.        else if(y+2 > ALTO-44) y -=2;
  132.  
  133.        if(cont > 0) cont--;
  134.  
  135.  
  136. }
  137. void NAVE::pintar(void)
  138. {
  139.  
  140.    masked_blit(nave, buffer, 40*direccion, 0, x, y, 40, 47);
  141.  
  142.    direccion = 1;
  143.  
  144. }
  145.  
  146. DISPARO *NAVE::disparar()
  147. {
  148.  
  149.    if(cont <= 0){ cont = 20; return new DISPARO(x+20,y,0,3); }
  150.  
  151.    else return new DISPARO(5000,5000,0,3);
  152.  
  153. }
  154.  
  155.  
  156. /****************************************CLASE ENEMIGO********************************/
  157.  
  158. class ENEMIGO
  159. {
  160.    private:
  161.    BITMAP *nave;
  162.    int x;
  163.    int y;
  164.    int direccion;
  165.    int vida;
  166.    int cont;
  167.  
  168.    public:
  169.  
  170.    ENEMIGO(int _x,int _y,int _direccion,int _vida);
  171.  
  172.    int getx(void) const {return x;}
  173.    int gety(void) const {return y;}
  174.    int getdireccion(void) const {return direccion;}
  175.    int getvida(void) const {return vida;}
  176.  
  177.    void setx(int _x){x = _x;}
  178.    void sety(int _y){y = _y;}
  179.    void setdireccion(int _direccion){direccion = _direccion;}
  180.    void setvida(int _vida){vida = _vida;}
  181.  
  182.    void mover(void);
  183.    void pintar(void);
  184.    DISPARO *disparar();
  185.  
  186.  
  187. };
  188.  
  189. ENEMIGO::ENEMIGO(int _x,int _y,int _direccion,int _vida)// CONSTRUCTOR
  190.    {
  191.        x = _x;
  192.        y = _y;
  193.        direccion = _direccion;
  194.        vida = _vida;
  195.        nave = load_bitmap(".\\imagenes\\enemigo.bmp",NULL);
  196.        cont = 2;
  197.    }
  198.  
  199. DISPARO *ENEMIGO::disparar()
  200. {
  201.  
  202.    if(cont <= 0){ cont = 20; return new DISPARO(x+20,y+40,0,-3); }
  203.  
  204.    else return new DISPARO(5000,5000,0,3);
  205.  
  206.  
  207. }
  208.  
  209. void ENEMIGO::mover(void)
  210. {
  211.     if(direccion == 0 && x >= 8){ x  -= 2; /*nav->y -= 2;*/}else direccion = 1;
  212.     if(direccion == 1 && x <=450){ x += 2;/*nav->y += 2;*/} else direccion = 0;
  213.  
  214.    if(x-2 < 0) x +=2;
  215.        else if(x+2 > ANCHO-44) x -=2;
  216.  
  217.       if(y-2 < 0) y +=2;
  218.        else if(y+2 > ALTO-44) y -=2;
  219.  
  220.    if(cont > 0) cont--;
  221. }
  222.  
  223. void ENEMIGO::pintar(void)
  224. {
  225.  
  226.   masked_blit( nave, buffer, 0, 0, x, y, 42, 43);
  227.  
  228.  
  229.  
  230. }
  231.  
  232.  
  233. vector<DISPARO*> disparos;
  234. vector<DISPARO*> disparos2;
  235.  
  236.  
  237. void limpia_disparos()
  238. {
  239.    unsigned int i;
  240.    vector<DISPARO*> vd;   // vector temporal
  241.  
  242.    /* eliminamos los disparos que se encuentren fuera de la pantalla*/
  243.  
  244.    for(i = 0; i < disparos.size(); i++)
  245.        if((disparos[i]->getx() > 0) && (disparos[i]->getx() < ANCHO) &&
  246.           (disparos[i]->gety() > 0) && (disparos[i]->gety() < ALTO))
  247.            vd.push_back(disparos[i]);
  248.        else
  249.            // liberamos la memoria
  250.            delete disparos[i];
  251.  
  252.    disparos.clear();
  253.  
  254.    for(i = 0; i < vd.size(); i++)
  255.        disparos.push_back(vd[i]);
  256.  
  257.    vd.clear();
  258. }
  259. void limpia_disparos2()
  260. {
  261.    unsigned int i;
  262.    vector<DISPARO*> vd;   // vector temporal
  263.  
  264.    /* eliminamos los disparos que se encuentren fuera de la pantalla*/
  265.  
  266.    for(i = 0; i < disparos2.size(); i++)
  267.        if((disparos2[i]->getx() > 0) && (disparos2[i]->getx() < ANCHO) &&
  268.           (disparos2[i]->gety() > 0) && (disparos2[i]->gety() < ALTO))
  269.            vd.push_back(disparos2[i]);
  270.        else
  271.            // liberamos la memoria
  272.            delete disparos2[i];
  273.  
  274.    disparos2.clear();
  275.  
  276.    for(i = 0; i < vd.size(); i++)
  277.        disparos2.push_back(vd[i]);
  278.  
  279.    vd.clear();
  280. }
  281.  
  282.  
  283.  
  284.  
  285. int main()
  286. {
  287.    inicia_allegro(ANCHO,ALTO);
  288.    inicia_audio(70,70);
  289.   BITMAP *nube = load_bitmap(".\\imagenes\\nube.bmp",NULL);
  290.   buffer = create_bitmap(ANCHO, ALTO);
  291.  
  292.   NAVE jugador(232,404,2,50);
  293.   ENEMIGO enemigo1(0,0,0,12);
  294.  
  295.   while(!key[KEY_ESC])
  296.   {
  297.       blit(nube,buffer,0,i--,0,0,ANCHO,ALTO);
  298.       if(i <= 0) i=450;
  299.       jugador.mover();
  300.       jugador.pintar();
  301.       enemigo1.mover();
  302.       enemigo1.pintar();
  303.       disparos2.push_back(enemigo1.disparar());
  304.       if(key[KEY_SPACE]){  disparos.push_back(jugador.disparar()); }
  305.  
  306.        for(unsigned int c = 0; c < disparos.size(); c++)
  307.       {
  308.           disparos.at(c)->mover();
  309.           disparos.at(c)->pintar();
  310.        }
  311.         for(unsigned int c = 0; c < disparos2.size(); c++)
  312.       {
  313.           disparos2.at(c)->mover();
  314.           disparos2.at(c)->pintar();
  315.  
  316.        }
  317.  
  318.         limpia_disparos();
  319.         limpia_disparos2();
  320.  
  321.       blit(buffer,screen,0,0,0,0,ANCHO,ALTO);
  322.       rest(5);
  323.       clear(buffer);
  324.  
  325.   }
  326.  
  327.    destroy_bitmap(buffer);
  328.    return 0;
  329. }
  330. END_OF_MAIN();
  331.  
36  Seguridad Informática / Hacking / Re: IP Spoofing en: 2 Diciembre 2012, 22:03 pm
Gente he estado ausente un tiempo muchas gracias por sus respuestas :)
37  Programación / Programación C/C++ / Re: como puedo convertir este programa a clases en c++ en: 23 Noviembre 2012, 16:05 pm
Bueno yo recien estoy empezando en esto, aqui te dejo lo que he podido hacer con clases por si te sirve de algo. Lo que falta te lo dejo para que completes ya que es usar los metodos de la clase y poco más, siempre igual. Un gran saludo.
Código
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Operacion
  7. {
  8.    private:
  9.  
  10.      double x;
  11.      double y;
  12.  
  13.    public:
  14.  
  15.      Operacion(double _x=0.0, double _y=0.0){x = _x; y = _y;}
  16.  
  17.      void SetNumero1(double _x){ x = _x;}
  18.      void SetNumero2(double _y){ y = _y;}
  19.  
  20.      inline double GetNumero1(void) const { return x;}
  21.      inline double GetNumero2(void) const { return y;}
  22.  
  23.      inline double Sumar(void) const {return x+y;}
  24.      inline double Restar(void)const {return x-y;}
  25.      inline double Multiplicar(void)const {return x*y;}
  26.      inline double Dividir(void) const { return x/y;}
  27.      inline double RaizCuadrada(void) const { sqrt(x);}
  28. };
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34.    int opcion;
  35.    double numero1, numero2, result;
  36.  
  37.    Operacion hf;
  38.  
  39.    cout << "Calculadora\n" << endl;
  40.    cout << "1.- Sumar\n2.-Restar\n3.-Multiplicar\n4.-Dividir\n5.-Raiz\n" << endl;
  41.    cout << "Ingrese opcion: ";
  42.    cin >> opcion;
  43.  
  44.    switch(opcion){
  45.        case 1:
  46.           cout << "Numero 1: " << endl;
  47.           cin >> numero1;
  48.           cout << "Numero 2: " << endl;
  49.           cin >> numero2;
  50.           hf.SetNumero1(numero1);
  51.           hf.SetNumero2(numero2);
  52.           result = hf.Sumar();
  53.           cout << result;
  54.    }
  55.  
  56.  
  57.  
  58.  
  59.    return 0;
  60. }
38  Seguridad Informática / Hacking / IP Spoofing en: 23 Octubre 2012, 01:01 am
Hola gente, tengo una duda. Necesito un ip spoofing para tener una ip publica especifica. Es posible o solo se puede dentro de la LAN? Y si es posible alguien me pasa un tuto o alguna info para echarle un vistazo? Muchas gracias un gran saludo.
39  Seguridad Informática / Hacking / Documentos compartidos en: 19 Junio 2012, 23:34 pm
Hola, alguien sabe si es posible teniendo acceso a los documentos compartidos de una pc en red local, acceder a todo el disco duro? Hablo de windows y ya estoy harto de ver videos e informacion de ms08_067_netapi ya que esta parcheada en la mayoria de los sistemas :S Existe alguna otra?
40  Programación / Programación C/C++ / Re: Duda sobre código en: 6 Mayo 2012, 21:49 pm
De nada :)... cuando usas funciones q manejan cadenas(ej: scanf, fgets...),el  caracter '\0' si se agrega solo, pero cuando usas bucles para crear algo como vos hicist, lo tenes q agregar

Saludos

Entendido, gracias.
Páginas: 1 2 3 [4] 5 6 7
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines