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] 2 3 4 5 6
1  Programación / Scripting / Re: No consigo abrir módulos en python en: 5 Febrero 2018, 20:57 pm
Vale, acabo de solucionarlo... efectivamente, el problema estaba en Pycharm. Para añadir módulos se debe de ir a settings y en las opciones del compilador aparece un menú con los módulos instalados y otra opción para añadir más.
2  Programación / Scripting / Re: No consigo abrir módulos en python en: 5 Febrero 2018, 20:16 pm
empiezo a pensar que tal vez sea problema del Pycharm, alguien que use el programa sabe si hay que importar o incluir los módulos en el programa también?
3  Programación / Scripting / Re: No consigo abrir módulos en python en: 4 Febrero 2018, 21:59 pm
Pyton 3.6.4

El error es "ModuleNotFoundError: No module named 'Numpy'"
4  Programación / Scripting / No consigo abrir módulos en python en: 3 Febrero 2018, 22:02 pm
Hola
Mi problema es que instalo módulos desde la CMD con el comando "pip install numpy" , pero cuando trato de usarlos en un programa el compilador me da error en la linea en la que lo importo. Tengo windows 10 64bits y para programar en python uso Pycharm.
Si alguien sabe que puede causarlo me seria de gran ayuda.
5  Programación / Programación C/C++ / Error de definición múltiple en: 20 Enero 2018, 22:31 pm
Hola!
Cada vez que hago una clase en CodeBlocks y trato de incluirla en el archivo header de otra clase, el compilador me da un error de declaración múltiple en todos los métodos y no se a que se puede deber ya que estos solo son definidos una vez y todos los headers tienen al principio el #ifndef
Mi programa:

TicTacToeEngine.h
Código
  1. #ifndef TICTACTOEENGINE_H
  2. #define TICTACTOEENGINE_H
  3.  
  4. #include <vector>
  5. using namespace std;
  6.  
  7. class TicTacToeEngine
  8. {
  9. protected:
  10.    vector <unsigned short> board;
  11.    unsigned short state;
  12.    bool first__player_turn;
  13.  
  14.    void Check();
  15.  
  16. public:
  17.    TicTacToeEngine(void);
  18.    TicTacToeEngine( const vector<unsigned short>);
  19.    TicTacToeEngine( const TicTacToeEngine&);
  20.    ~TicTacToeEngine(void);
  21.    TicTacToeEngine operator=( const TicTacToeEngine&);
  22.  
  23.    bool Movement(unsigned short);
  24.    vector<unsigned short> Board(void) const;
  25.    void Restart(void);
  26.    unsigned short State(void) const;
  27.    bool FirstPlayer(void) const;
  28.  
  29. };
  30.  
  31. #endif // TICTACTOEENGINE_H
  32.  

TicTacToeEngine.cpp
Código
  1. #include "TicTacToeEngine.h"
  2.  
  3. //////////////////////////////////////////////////////////////////////////////////////////
  4.  
  5. // win checker
  6.  
  7. //checks if there is a line
  8. void TicTacToeEngine::Check(void)
  9. {
  10.    /////////////
  11.    //CHECK TIE//
  12.    /////////////
  13.  
  14.    unsigned short i = 0;
  15.  
  16.    while(i < 9 && board[i] != 0) {
  17.  
  18.        if(i == 8) {
  19.            state = 3;
  20.            return;
  21.        }
  22.        i++;
  23.    }
  24.  
  25.    //////////////////////
  26.    //CHECK FIRST PLAYER//
  27.    //////////////////////
  28.  
  29.    //CHECK HORIZONTAL
  30.  
  31.    //first line
  32.    if(board[0] == 1 && board[1] == 1 && board[2] == 1)
  33.        state = 1;
  34.        return;
  35.  
  36.    //second line
  37.    if(board[3] == 1 && board[4] == 1 && board[5] == 1)
  38.        state = 1;
  39.        return;
  40.  
  41.    //third line
  42.    if(board[6] == 1 && board[7] == 1 && board[8] == 1)
  43.        state = 1;
  44.        return;
  45.  
  46.    //CHECK VERTICAL
  47.  
  48.    //first line
  49.    if(board[0] == 1 && board[3] == 1 && board[6] == 1)
  50.        state = 1;
  51.        return;
  52.  
  53.    //second line
  54.    if(board[1] == 1 && board[4] == 1 && board[7] == 1)
  55.        state = 1;
  56.        return;
  57.  
  58.    //third line
  59.    if(board[2] == 1 && board[5] == 1 && board[8] == 1)
  60.        state = 1;
  61.        return;
  62.  
  63.    //DIAGONAL LINES
  64.  
  65.    //top right to bottom left
  66.    if(board[2] == 1 && board[4] == 1 && board[6] == 1 )
  67.        state = 1;
  68.        return;
  69.  
  70.    //top left to bottom right
  71.    if(board[0] == 1 && board[4] == 1 && board[8] == 1 )
  72.        state = 1;
  73.        return;
  74.  
  75.    ///////////////////////
  76.    //CHECK second PLAYER//
  77.    ///////////////////////
  78.  
  79.    //CHECK HORIZONTAL
  80.  
  81.    //first line
  82.    if(board[0] == 2 && board[1] == 2 && board[2] == 2 )
  83.        state = 2;
  84.        return;
  85.  
  86.    //second line
  87.    if(board[3] == 2 && board[4] == 2 && board[5] == 2 )
  88.        state = 2;
  89.        return;
  90.  
  91.    //third line
  92.    if(board[6] == 2 && board[7] == 2 && board[8] == 2 )
  93.        state = 2;
  94.        return;
  95.  
  96.    //CHECK VERTICAL
  97.  
  98.    //first line
  99.    if(board[0] == 2 && board[3] == 2 && board[6] == 2 )
  100.        state = 2;
  101.        return;
  102.  
  103.    //second line
  104.    if(board[1] == 2 && board[4] == 2 && board[7] == 2 )
  105.        state = 2;
  106.        return;
  107.  
  108.    //third line
  109.    if(board[2] == 2 && board[5] == 2 && board[8] == 2 )
  110.        state = 2;
  111.        return;
  112.  
  113.    //DIAGONAL LINES
  114.  
  115.    //top right to bottom left
  116.    if(board[2] == 2 && board[4] == 2 && board[6] == 2 )
  117.        state = 2;
  118.        return;
  119.  
  120.    //top left to bottom right
  121.    if(board[0] == 2 && board[4] == 2 && board[8] == 2 )
  122.        state = 2;
  123.        return;
  124.  
  125.    return;
  126. }
  127.  
  128.  
  129. //////////////////////////////////////////////////////////////////////////////////////////
  130.  
  131. // constructors & destructor
  132.  
  133. //normal constructor
  134. TicTacToeEngine::TicTacToeEngine(void) :
  135.    state(0), first__player_turn(false)
  136. {
  137.    //creates an array filled with 0 (empty board)
  138.    for(int i = 0; i < 9; i++) {
  139.        board.push_back(0);
  140.    }
  141. }
  142.  
  143. //constructor with vector as argument
  144. TicTacToeEngine::TicTacToeEngine( const vector<unsigned short> original_board) :
  145.    board(original_board), first__player_turn(false)
  146. {
  147.    Check();
  148. }
  149.  
  150. //copy constructor
  151. TicTacToeEngine::TicTacToeEngine( const TicTacToeEngine& original) :
  152.    board( original.board), state(original.state),
  153.    first__player_turn(original.first__player_turn) {}
  154.  
  155. TicTacToeEngine::~TicTacToeEngine(void) {}
  156.  
  157.  
  158. //////////////////////////////////////////////////////////////////////////////////////////
  159.  
  160. // operator =
  161.  
  162. TicTacToeEngine TicTacToeEngine::operator=( const TicTacToeEngine& original)
  163. {
  164.    board = original.board;
  165.    state = original.state;
  166.    first__player_turn = original.first__player_turn;
  167.  
  168.    return *this;
  169. }
  170.  
  171.  
  172. //////////////////////////////////////////////////////////////////////////////////////////
  173.  
  174. // Movement method
  175.  
  176. bool TicTacToeEngine::Movement(unsigned short place)
  177. {
  178.    //if the place is not between 0 and 8 or occupied or if the game has finished returns false
  179.    if( place < 0 || place > 8 || board[place] != 0 || state != 0)
  180.        return false;
  181.  
  182.    //else the place in the board is filled
  183.    if(first__player_turn) {
  184.        board[place] = 1;
  185.    }
  186.  
  187.    else {
  188.        board[place] = 2;
  189.    }
  190.  
  191.    //check if the game has ended
  192.    Check();
  193.    first__player_turn = !first__player_turn;
  194.  
  195.    return true;
  196. }
  197.  
  198.  
  199. //////////////////////////////////////////////////////////////////////////////////////////
  200.  
  201. // Return board method
  202.  
  203. vector<unsigned short> TicTacToeEngine::Board(void) const
  204. {
  205.    return board;
  206. }
  207.  
  208.  
  209. //////////////////////////////////////////////////////////////////////////////////////////
  210.  
  211. // Restart method
  212.  
  213. void TicTacToeEngine::Restart(void)
  214. {
  215.    //restarts the board array with all elements at 0
  216.    board.clear();
  217.  
  218.    for(int i = 0; i < 9; i++) {
  219.        board.push_back(0);
  220.    }
  221.  
  222.    //restarts game data
  223.    state = 0;
  224.    first__player_turn = true;
  225. }
  226.  
  227.  
  228. //////////////////////////////////////////////////////////////////////////////////////////
  229.  
  230. // Returns true if the game has finished
  231.  
  232. unsigned short TicTacToeEngine::State(void) const
  233. {
  234.    return state;
  235. }
  236.  
  237.  
  238. //////////////////////////////////////////////////////////////////////////////////////////
  239.  
  240. // Returns true if it is the turn of the first player
  241.  
  242. bool TicTacToeEngine::FirstPlayer(void) const
  243. {
  244.    return first__player_turn;
  245. }
  246.  
  247.  
  248. //////////////////////////////////////////////////////////////////////////////////////////
  249.  

TicTacToe.h
Código
  1. #ifndef TICTACTOE_H
  2. #define TICTACTOE_H
  3.  
  4. #include <iostream>
  5. #include <windows.h>
  6. #include "TicTacToeEngine.h"
  7.  
  8. using namespace std;
  9.  
  10. class TicTacToe : public TicTacToeEngine
  11. {
  12.    void Graphic(unsigned short);
  13.  
  14. public:
  15.    TicTacToe(void);
  16.    bool GraphicMovement(void);
  17.    void Play(void);
  18. };
  19.  
  20. /*
  21.  
  22. base class methods:
  23.  
  24.     TicTacToeEngine(void);
  25.     TicTacToeEngine( const vector<unsigned short>);
  26.     TicTacToeEngine( const TicTacToeEngine&);
  27.     ~TicTacToeEngine(void);
  28.     TicTacToeEngine operator=( const TicTacToeEngine&);
  29.  
  30.     bool Movement(unsigned short);
  31.     vector<unsigned short> Board(void) const;
  32.     void Restart(void);
  33.     unsigned short State(void) const;
  34.     bool FirstPlayer(void) const;
  35.  
  36. */
  37.  
  38. #endif // TICTACTOE_H

TicTacToe.cpp
Código
  1. #include "TicTacToe.h"
  2.  
  3. //////////////////////////////////////////////////////////////////////////////////////////
  4.  
  5. // constructors & destructor
  6.  
  7. //normal constructor
  8. TicTacToeEngine::TicTacToeEngine(void) :
  9.    state(0), first__player_turn(false)
  10. {
  11.    //creates an array filled with 0 (empty board)
  12.    for(int i = 0; i < 9; i++) {
  13.        board.push_back(0);
  14.    }
  15. }
  16.  
  17.  
  18. //////////////////////////////////////////////////////////////////////////////////////////
  19.  
  20. // Graphic Movement
  21.  
  22. void TicTacToe::Graphic(unsigned short i)
  23. {
  24.    if(board[i] == 0) {
  25.        cout << " ";
  26.    }
  27.  
  28.    if(board[i] == 1) {
  29.        cout << "x";
  30.    }
  31.  
  32.    if(board[i] == 2) {
  33.        cout << "O";
  34.    }
  35. }
  36.  
  37. bool TicTacToe::GraphicMovement(void)
  38. {
  39.    system("CLS");
  40.  
  41.    cout << endl << endl;
  42.    cout << "   "; Graphic(0); cout << " | "; Graphic(1); cout << " | "; Graphic(2); cout << endl;
  43.    cout << "  ------------" << endl;
  44.    cout << "   "; Graphic(3); cout << " | "; Graphic(4); cout << " | "; Graphic(5); cout << endl;
  45.    cout << "  ------------" << endl;
  46.    cout << "   "; Graphic(6); cout << " | "; Graphic(7); cout << " | "; Graphic(8); cout << endl;
  47.    cout << endl << endl;
  48.  
  49.    cout << "Movimiento del jugador";
  50.  
  51.    if(first__player_turn)
  52.        cout << " 1: ";
  53.  
  54.    if(!first__player_turn)
  55.        cout << " 2: ";
  56.  
  57.    unsigned short movement;
  58.    bool moved;
  59.    cin >> movement;
  60.  
  61.    moved = Movement(movement);
  62.  
  63.    return moved;
  64. }
  65.  
  66.  
  67. //////////////////////////////////////////////////////////////////////////////////////////
  68.  
  69. //Just play
  70.  
  71. void TicTacToe::Play(void)
  72. {
  73.    while(state == 0) {
  74.        GraphicMovement();
  75.    }
  76.  
  77.    cout << endl << endl << "End of the game." << endl << endl << "Result: ";
  78.  
  79.    if(state == 1) {
  80.        cout << "First player has won." << endl << endl;
  81.    }
  82.  
  83.    if(state == 2) {
  84.        cout << "Second player has won." << endl << endl;
  85.    }
  86.  
  87.    if(state == 3) {
  88.        cout << "Tie" << endl << endl;
  89.    }
  90. }
  91.  
  92.  
  93. //////////////////////////////////////////////////////////////////////////////////////////
  94.  
6  Programación / Programación C/C++ / Re: Crear puntero a clase abstracta y problema usando vector en: 8 Enero 2018, 16:13 pm
y al hacer
Código
  1. ficha[i] = new CFicha
no estoy usando punteros solamente?
7  Programación / Programación C/C++ / Re: Crear puntero a clase abstracta y problema usando vector en: 7 Enero 2018, 20:42 pm
Awww dios, que error más tonto el primero  :-X
Respecto al segundo, mi intención es crear un puntero de una clase base para almacenar en el un objeto de una clase derivada de esta. En algún libro de POO he visto que hacen eso y me suena que era algo por el estilo de lo que estoy haciendo yo .-.
8  Programación / Programación C/C++ / Crear puntero a clase abstracta y problema usando vector en: 7 Enero 2018, 19:24 pm
Hola!
Estoy haciendo un programa que consiste en una biblioteca que puede almacenar una serie de items, que son guardados en un vector (ficha). La clase CFicha es abstracta y es la clase base para todas las demás (libros, revistas, etc...). Aquí les dejo la clase CBiblioteca:
Código
  1. class CBiblioteca
  2. {
  3.    vector<CFicha *> ficha;
  4.  
  5.    public:
  6.        //basico
  7.        CBiblioteca();
  8.        CBiblioteca(const CBiblioteca&);
  9.        ~CBiblioteca();
  10.        CBiblioteca operator=(const CBiblioteca&);
  11.        CFicha* operator[](unsigned);
  12.  
  13.        //funciones
  14.        void AnyadirFicha(CFicha&);
  15.        int BuscarFicha(const string) const;
  16.        //eliminar siguiente ?
  17.        bool EliminarFicha(unsigned);
  18.        bool MostrarFicha(unsigned);
  19.        bool MostrarBiblioteca(void);
  20. };
Mi problema se da en el método 'operator=' y 'AnyadirFicha()', los cuales son definidos así:
Código
  1. CBiblioteca CBiblioteca::operator=(const CBiblioteca& bib)
  2. {
  3.    //primero vaciamos la matriz
  4.    for(int i = 0; i < ficha.size(); i++)
  5.        delete ficha[i];
  6.  
  7.    ficha.clear();
  8.  
  9.    //ahora copiamos los elementos
  10.    for(int i = 0; i < bib.ficha.size(); i++)
  11.        ficha.push_back(new CFicha(*(bib.ficha[i])));
  12.  
  13.    return *this;
  14. }
y
Código
  1. void CBiblioteca::AnyadirFicha(CFicha& ficha)
  2. {
  3.    ficha.push_back(new CFicha(ficha));
  4. }
ambas me dan los mismos dos errores:
 'class CFicha' has no member named 'push_back'
 invalid new-expression of abstract class type 'CFicha'

pero no entiendo por que interpreta que push_back es un método de CFicha y no de la clase vector, así como mi otra duda de si se puede crear un objeto abstracto con el operador new.
9  Programación / Programación C/C++ / Re: Array atributo de una clase de tamaño igual a otro atributo en: 1 Enero 2018, 21:02 pm
Gracias a ambos :D
10  Programación / Programación C/C++ / Array atributo de una clase de tamaño igual a otro atributo en: 31 Diciembre 2017, 17:34 pm
Hola! Necesito hacer un array de una clase y que el tamaño de este se lo de otro atributo de la misma clase, algo así:
Código
  1. private:
  2.    int tamanyo;
  3.    float array [tamanyo];
y hacerle a la clase un constructor asi:
Código
  1. Clase::Clase(int _tamanyo) : tamanyo (_tamanyo)
pero el compilador me da error... Alguien puede indicarme la forma correcta de hacerlo?
Páginas: [1] 2 3 4 5 6
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines