Write a program in C++ to display the cube of the number upto a given integer by using the virtual base class in Object Oriented Programming(OOP).

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 33 34 |
#include<iostream> using namespace std; class T4Tutorials { public: int i; }; class A:public virtual T4Tutorials { }; class B:public virtual T4Tutorials { public: int n; }; class D: public A,B { public: void disp() { cout<<"enter the Number"<<endl; cin>>n; for(i=1;i<=n;i++) { cout<<"cube of "<<i<<"is ="<<(i*i*i)<<endl; } } }; int main() { D obj; obj.disp(); } |