1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help with creating a derived c++ class

Discussion in 'C++' started by edouard89, Aug 22, 2008.

  1. edouard89

    edouard89 New Member

    Joined:
    Aug 22, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone! I am need of assistance with creating a derived class. I have the following abstract base class:
    Code:
    class Field{
        public:
        virtual void display() = 0;
        virtual int edit() = 0;
        virtual bool editable() const = 0;
        virtual void *data() = 0;
        virtual Field *clone() const = 0;
    };
    I need to make a derived class with the following specification:
    This is how I have my derived class in my header file:
    Code:
    class LField : public Field{
        int row_loc, col_loc, width_tot, index;
        char *initval;
        bool edib;
        
        public:
            LField(int row, int col, int width);
            LField(int row, int col, int width, char *s);
            LField(int row, int col, int width, char *s, bool editable);
            void initialize(int r, int c, int w, bool e);
            ~LField();
            void display();
            int edit();
            bool editable() const;
            void *data();
            Field *clone() const;
            LField& operator = (const LField & rhs);
            LField(const LField & source );
    }
    This is what I have done so far:
    Code:
    LField::LField(int row, int col, int width){
        //Checks for valid coords
        if(row < 0){
            row = 0;
        }
        if(row > dtioRows()){
            row = dtioRows() - 1;
        }
        if(col < 0){
            col = 0;
        }
        if(col > dtioColumns()){
            col = dtioColumns() - 1;
        }
        //Checks for width and location
        if((col + width) > dtioColumns()){
            width = width - ((col + width) - dtioColumns());
        }
        
        initialize(row, col, width, true);
        initval = NULL;
    }
    LField::LField(int row, int col, int width, char *s){
        //Checks for valid coords
        if(row < 0){
            row = 0;
        }
        if(row > dtioRows()){
            row = dtioRows() - 1;
        }
        if(col < 0){
            col = 0;
        }
        if(col > dtioColumns()){
            col = dtioColumns() - 1;
        }
        //Checks for width and location
        if((col + width) > dtioColumns()){
            width = width - ((col + width) - dtioColumns());
        }
        initialize(row, col, width, true);
        if(strlen(s) > width){
            initval = new char[width];
            for(int i = 0; i < width; i++){
                initval[i] = s[i];
            }
        }
        else{
            initval = new char[strlen(s) + 1];
            strcpy(initval, s);
        }
        
    }
    LField::LField(int row, int col, int width, char *s, bool editable){
        //Checks for valid coords
        if(row < 0){
            row = 0;
        }
        if(row > dtioRows()){
            row = dtioRows() - 1;
        }
        if(col < 0){
            col = 0;
        }
        if(col > dtioColumns()){
            col = dtioColumns() - 1;
        }
        //Checks for width and location
        if((col + width) > dtioColumns()){
            width = width - ((col + width) - dtioColumns());
        }
        initialize(row, col, width, editable);
        if(strlen(s) > width){
            initval = new char[width];
            for(int i = 0; i < width; i++){
                initval[i] = s[i];
            }
        }
        else{
            initval = new char[strlen(s) + 1];
            strcpy(initval, s);
        }
    }
    //Function that initializes LField
    void LField::initialize(int r, int c, int w, bool e){
        row_loc = r;
        col_loc = c;
        width_tot = w;
        edib = e;
        index = 0;
    }
    I am unsure if what I am doing is correct and would like some input. If there is something that has to be changed or corrected please tell me. Any input is greatly appreciated!
     
  2. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    it's okay... If any problem or specific features you wanna then post exact point? beacuse here there is no team for review your code without giving any proper reason/problem/code defects/ features...
     

Share This Page