Write a program in C++ to make such a pattern like a pyramid with numbers increased by 1 by using the virtual base class 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 33 34 35 36 37 38 39 40 41 42 43 | #include<iostream> using namespace std; class A { public: int rows,i; }; class B:virtual public A { public: int sp,p,space; }; class C:virtual public A { public: int space; }; class D: public B,C { public: void T4Tutorials_GetNumber() { cout<<"Enter the number of Rows. "<<endl; cin>>rows; for(i=1;i<=rows;i++) { for(sp=i;sp<rows;sp++) { cout<<" "; } for(p=1;p<=(2*i-1);p++) { cout<<"*"; } cout<<endl; } } }; int main() { D d; d.T4Tutorials_GetNumber(); } |
Output
Enter the number of Rows. 4
1
22
33
4444