Write a program in C++ to make such a pattern like a pyramid with numbers increased by 1 by using the classes and object in Object-oriented programming. The pattern is as follows:
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 |
#include<iostream> using namespace std; class base { protected: int rows,sp,p,space,i; public: int pyramid() { cout<<"Enter the number of rows"<<endl; cin>>rows; { for(i=1; i<=rows; i++) { for(sp=i; sp<rows; sp++) { cout<<" "; } for(p=1;p<=(2*i-1);p++) { cout<<"*"; } cout<<endl; } } } }; int main() { base p; p.pyramid(); } |
Write a program to make such a pattern like a pyramid with numbers increased by 1 by using the single inheritance in C++.
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 |
#include<iostream> using namespace std; class base { protected: int rows,sp,p,space,i; }; class child: public base { public: int pyramid() { cout<<"Enter the number of rows"<<endl; cin>>rows; { for(i=1; i<=rows; i++) { for(sp=i; sp<rows; sp++) { cout<<" "; } for(p=1;p<=(2*i-1);p++) { cout<<"*"; } cout<<endl; } } } }; int main() { child p; p.pyramid(); } |
WAP to make such a pattern like a pyramid with numbers increased by 1 by using the multiple inheritances in C++.
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 |
#include<iostream> using namespace std; class M { protected: int rows,sp; }; class N { protected: int p,space,i; }; class child: public M, public N { public: int pyramid() { cout<<"Enter the number of rows"<<endl; cin>>rows; { for(i=1; i<=rows; i++) { for(sp=i; sp<rows; sp++) { cout<<" "; } for(p=1;p<=(2*i-1);p++) { cout<<"*"; } cout<<endl; } } } }; int main() { child p; p.pyramid(); } |
Write a C++ program to make a pyramid pattern with numbers increased by 1 with the help of Multi-level inheritance in C++.
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 |
#include<iostream> using namespace std; class M { protected: int rows,sp; }; class N: public M { protected: int p,space,i; }; class P: public N { public: int pyramid() { cout<<"Enter the number of rows"<<endl; cin>>rows; { for(i=1; i<=rows; i++) { for(sp=i; sp<rows; sp++) { cout<<" "; } for(p=1;p<=(2*i-1);p++) { cout<<"*"; } cout<<endl; } } } }; int main() { P obj; obj.pyramid(); } |