Virtual base class C++ program to print hollow right triangle star pattern
C++ program to print the hollow right triangle star pattern 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 49 | //program to print hollow right triangle star T4Tutorials_Pattern // virtual class #include<iostream> using namespace std; class T4Tutorials_Pattern { public: int i; }; class parent:virtual public T4Tutorials_Pattern { public: int j; }; class parent1:virtual public T4Tutorials_Pattern { public: int rows; }; class print:public parent , public parent1 { public: int number() { cout<<"enter any num of rows"<<endl; cin>>rows; for(i=1; i<=rows; i++) { for(j=1; j<=i; j++) { if(j==1 || j==i || i==rows) { cout<<"*"; } else { cout<<" "; } } cout<<endl; } } }; int main() { print f; f.number(); } |