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 Multilevel inheritance 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 46 47 48 49 50 51 52 53 54 55 |
#include<iostream> using namespace std; class A { protected: int no; public: void get(int); }; void A::get(int) { cout<<"enter a number of rows="; cin>>no; } class B:public A { protected: int n; public: void show(int); }; void B::show(int) { n=no; } class C:public B { protected: int r,sp,disp; public: void display(int); }; void C::display(int) { 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(3); myobj.show(3); myobj.display(6); } |