Site icon T4Tutorials.com

C++ Program to make such a pattern like a pyramid with numbers increased by 1

Write a program in C++ to make such a pattern like a pyramid with numbers increased by 1 by using the virtual base class in object oriented programming.

#include<iostream>
using namespace std;
class A
{
	public:
		int rows,i;
};
class B:virtual public A
{
	public:
		int sp,p,space;
};
class C:virtual public A
{
	public:
		int space;
};
class D: public B,C
{
	public:
		void T4Tutorials_GetNumber()
		{
			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()
{
	D d;
	d.T4Tutorials_GetNumber();
}

Output

Enter the number of Rows. 4

1

22

33

4444

Exit mobile version