We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<iostream>usingnamespacestd;classA{public:A(){callA=0;}private:intcallA;voidinc(){callA++;}protected:voidfunc(int&a){a=a*2;inc();}public:intgetA(){returncallA;}};classB{public:B(){callB=0;}private:intcallB;voidinc(){callB++;}protected:voidfunc(int&a){a=a*3;inc();}public:intgetB(){returncallB;}};classC{public:C(){callC=0;}private:intcallC;voidinc(){callC++;}protected:voidfunc(int&a){a=a*5;inc();}public:intgetC(){returncallC;}};classD:A,B,C{intval;public://Initially val is 1D(){val=1;}//Implement this functionvoidupdate_val(intnew_val){while(new_val!=1){if(new_val%5==0){C::func(val);new_val/=5;}elseif(new_val%3==0){B::func(val);new_val/=3;}elseif(new_val%2==0){A::func(val);new_val/=2;}}}//For Checking Purposevoidcheck(int);//Do not delete this line.};voidD::check(intnew_val){update_val(new_val);cout<<"Value = "<<val<<endl<<"A's func called "<<getA()<<" times"<<endl<<"B's func called "<<getB()<<" times"<<endl<<"C's func called "<<getC()<<" times"<<endl;}intmain(){Dd;intnew_val;cin>>new_val;d.check(new_val);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Accessing Inherited Functions
You are viewing a single comment's thread. Return to all comments →