Multiple inheritances C++ program to display the cube of the number up to a given integer
Write a program in C++ to display the cube of the number up to a given integer using the multiple inheritances in object-oriented programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | //Multiple inheritance #include<iostream> using namespace std; class A { protected: int n; }; class B { protected: int i; }; class child:public A , public B { public: int cube() { cout<<"enter the number :"<<endl; cin>>n; for (int i=0; i<n; i++) { cout<<" cube of "<<i<<" is "<<"="<<(i*i*i)<<endl; } } }; int main() { child obj; obj.cube(); } |
Output
enter the number : 3
cube of 0 is 0.
cube of 1 is 1.
cube of 2 is 8