#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++.
#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++.
#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++.
#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(); }