C++ program to print hollow rhombus, parallelogram star pattern using the Virtual Base Class.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include<iostream> using namespace std; class A // common base class of B and C { public: int n; public: A() //constructor or default function { n=4; } }; class B:public virtual A // derived class of A and by using "virtual" keyword we use only one copy of A class members in "D" class { public: int r; }; class C:virtual public A // derived class of A { public: int sp; }; class D: public B,C { public: void disp() { for(r=1;r<=n;r++) { for(sp=r;sp<n;sp++) { cout<<" "; } if(r==1||r==n) { for(sp=1;sp<=n;sp++) { cout<<"*"; } } else { cout<<"*"; for(sp=1;sp<=2;sp++) { cout<<" "; } cout<<"*"; } cout<<endl; } } }; int main() { D obj; // object or instance obj.disp(); } |
Output

FAQ
hollow parallelogram star pattern in C++ using the Virtual Base Class.
hollow mirrored rhombus star pattern in c++ using the Virtual Base Class.
hollow-rhombus pattern coding blocks using the Virtual Base Class.
hollow square pattern in c++ using the Virtual Base Class.
hollow triangle pattern in c++ using the Virtual Base Class.
given an integer n display the hollow mirrored right triangle star pattern as described in output using the Virtual Base Class.