Accessing Inherited Functions

Sort by

recency

|

267 Discussions

|

  • + 0 comments

    This is beyond useless and unclear!

  • + 0 comments

    Accessing inherited functions allows a subclass to reuse and extend the behavior of its parent class, promoting code reusability. Use super() to call the parent class's method within the child class. Ekbet 12 login

  • + 1 comment

    Hello there here's a hint to get you to the answer yourself at one go: In this problem we are only required to call the func of A, B, and C if it is divisible by 2, 3 and 5. you dont have to do anything else you just make functions to call them when the number is divisible by

    there are multiple ways to do it steps: 1: inherit the classes 2 use while to check value is greater than value 3rd in while loop you can either create multiple if-else-if ladder to check divisibility and call function

    catch here: you can also use this pointer

    • + 0 comments

      here is my snippet: class D : public A, public B, public C {

      int val;
      public:
          //Initially val is 1
           D()
           {
              val = 1;
           }
      
      
           //Implement this function
           void update_val(int new_val)
           {
              while( val < new_val) {
                  if(new_val % (2*val)==0){
                      this->A::func(val);
                  } else if(new_val % (3*val)==0) {
                      this->B::func(val);
                  }   else if ( new_val %(5*val)==0) {
                      this->C::func(val);
                  } else {
                      break;
                  }
              }
      
           }
      
  • + 0 comments
    class D : public A, public B, public C
    {
    
    	int val;
    	public:
    		//Initially val is 1
    		 D()
    		 {
    		 	val = 1;
    		 }
    
    
    		 //Implement this function
    		 void update_val(int new_val)
    		 {
                while (new_val % 2 == 0) {
                    A::func(val);
                    new_val /= 2;
                }
                while (new_val % 3 == 0) {
                    B::func(val);
                    new_val /= 3;
                }
                while (new_val % 5 == 0) {
                    C::func(val);
                    new_val /= 5;
                }
    			
    		 }
    		 //For Checking Purpose
    		 void check(int); //Do not delete this line.
    };
    
  • + 0 comments

    What an annoying task. The requirements are so not clear. Just copy the solution posted by @mft1998 and go on with your life.