Multiple inheritance C++ program pattern like a pyramid repeat
Write a program in C++ to make such a pattern like a pyramid with a number that will repeat the number in the same row using Multiple inheritances in 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 35 36 37 38 39 40 41 42 43 44 45 | #include<iostream> using namespace std; class a { protected: int no,n; public: void get() { cout<<"enter a numer of rows="; cin>>no; n=no; } }; class b { protected: int r,sp,disp; }; class c:public a,public b { public: void display() { for(r=1;r<=no ;r++) { for(sp=1;sp<n;sp++) { cout<<" "; } n--; for(disp=1;disp<=r;disp++) { cout<<" "<<r; } cout<<endl; } } }; int main() { c myobj; myobj.get(); myobj.display(); } |