Monday, March 16, 2020

WEEK 7 ASSIGNMENT SOLUTION

QUESTION 1:


Container& operator =(int val) {      // LINE-1

        this->arr[++i] = val;
        return *this;
    }

    operator int()  {      // LINE-2

        return arr[i--];
    }
};


QUESTION 2:


    virtual void print(int i)=0;          // LINE-1
};

class derived1 : public base{ // LINE-2
public:
    void print(int i) { cout << i * 1 << " "; }
};

class derived2 : public base { // LINE-3
public:
    void print(int i) { cout << i * 2 << " "; }
};

class derived3 : public base{ // LINE-4

QUESTION 3:


void updateSem(int new_sem) const{             // LINE-1

        student* ptr=const_cast<student*> (this);
      ptr->sem = new_sem;             // LINE-2
    }

    void show() const { 


QUESTION 4:


class derived1 : virtual public base {    // LINE-1
public:
    derived1();
    derived1(int _pr);
};

class derived2 : virtual public base {    // LINE-2
public:
    derived2();
    derived2(int _pr);
};

class dd : public derived2, public derived1 {          // LINE-3

1 comment: