In this HackerRank Accessing Inherited Functions problem in c++, You need to modify the class D and implement the function update_val which sets D's Val to new_val by manipulating the value by only calling the func defined in classes A, B, and C.

HackerRank Accessing Inherited Functions in C++ problem solution

HackerRank Accessing Inherited Functions in C++ problem

 solution

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)
		 {
            int const_new_val = new_val;
            while(val != const_new_val){
                if (new_val % 2 == 0) {
                    A::func(val);
                    new_val /= 2;
                } else if (new_val % 3 == 0) {
                    B::func(val);
                    new_val /= 3;
                } else if (new_val % 5 == 0) {
                    C::func(val);
                    new_val /= 5;
                }
            } 
		 }
		 //For Checking Purpose
		 void check(int); //Do not delete this line.
};