Site icon T4Tutorials.com

C++ program of Constructor Destructor to display a pattern for a number of rows

Write a C++ program of the constructor destructor to display a pattern for a number of rows using a number which will start with the number 1 and the first and the last number of each row will be 1. The pattern is as follows:

#include<iostream>
using namespace std;
class T4Tutorials
{
	public:
		int i,j,k,l,n;
		public:
			T4Tutorials()
			{
					cout<<"enter num of rows";
			cin>>n;
		for(i=1;i<=n;i++)
		{
	    	for(l=1;l<=n-i;l++)
	     	{
			cout<<" ";
			}	
			for(j=1;j<=i;j++)
			{
			cout<<j;	
			}
			for(k=i-1;k>=1;k--)
			{
				cout<<k;
			}
			cout<<endl;
		}
}
~T4Tutorials()
{
	cout<<"destructor has completed its work";
}
};
int main()
{
	T4Tutorials obj;
}

 

Exit mobile version