Write a program in C++ to make such a pattern like a pyramid with a number which will repeat the number in the same row 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 44 45 46 47 48 |
#include<iostream> using namespace std; class A { public: int n; public: A() { n=5; } }; class B:public virtual A { public: int r; }; class C:virtual public A { public: int sp; }; class D:public B,C { int disp; public: void T4Tutorials_Display() { for(r=1;r<=n;r++) { for(sp=1;sp<=n;sp++) { cout<<" "; } n--; for(disp=1;disp<=r;disp++) { cout<<" "<<r; } cout<<endl; } } }; int main() { D obj; obj.T4Tutorials_Display(); } |
Output
Develop a C++ Program to print the pattern like a pyramid repeating the number by using the Virtual base class in OOP.
Develop a C++ Program to print the pattern like a pyramid repeating the number by using multi level inheritance and virtual base class.
Develop a C++ Program to print the pattern like a pyramid repeating the number by using the Virtual base class with for loop.