Site icon T4Tutorials.com

Inheritance C++ program to print hollow right triangle star pattern

C++ program to print hollow right triangle star pattern with class objects C++.

Virtual base class C++ program to print hollow right triangle star pattern

//program to print hollow right triangle star pattren
//simple program
#include<iostream>
using namespace std;
class pattren
{
	private:
		int i,j,rows;
		public:
			int number()
{
	cout<<"enter any num of rows"<<endl;
	cin>>rows;
	for(i=1; i<=rows; i++)
	{
		for(j=1; j<=i; j++)
		{
			if(j==1 || j==i || i==rows)
			{
				cout<<"*";
			}		
			else
			{
				cout<<" ";
			}
		}
		cout<<endl;
	}
}
};
	int main()
	{
	pattren f;
	f.number();
}

Write C++ program to print hollow right triangle star pattern with single Inheritance in C++.

//program to print hollow right triangle star pattren
//single inheritence program
#include<iostream>
using namespace std;
class pattren
{
	protected:
		int i,j,rows;
	};
	class child:public pattren
	{
		public:
			int number()
{
	cout<<"enter any num of rows"<<endl;
	cin>>rows;
	for(i=1; i<=rows; i++)
	{
		for(j=1; j<=i; j++)
		{
			if(j==1 || j==i || i==rows)
			{
				cout<<"*";
			}		
			else
			{
				cout<<" ";
			}
		}
		cout<<endl;
	}
}
};
	int main()
	{
	child f;
	f.number();
}

WAP in C++  to print hollow right triangle star pattern with multiple Inheritance in C++.

//program to print hollow right triangle star pattren
//multiple inheritence program
#include<iostream>
using namespace std;
class pattren
{
	protected:
		int i,j;
	};
	class pattren2
	{
	protected:
		int rows;
	};
	class child:public pattren,public pattren2
	{
		public:
			int number()
{
	cout<<"enter any num of rows"<<endl;
	cin>>rows;
	for(i=1; i<=rows; i++)
	{
		for(j=1; j<=i; j++)
		{
			if(j==1 || j==i || i==rows)
			{
				cout<<"*";
			}		
			else
			{
				cout<<" ";
			}
		}
		cout<<endl;
	}
}
};
	int main()
	{
	child f;
	f.number();
}

Write the C++ code to print the hollow right triangle star pattern with multi-level Inheritance.

//program to print hollow right triangle star pattren
//multi level inheritence program
#include<iostream>
using namespace std;
class pattren
{
	protected:
		int i,j;
	};
	class pattren2:public pattren
	{
	protected:
		int rows;
	};
	class child:public pattren2
	{
		public:
			int number()
{
	cout<<"enter any num of rows"<<endl;
	cin>>rows;
	for(i=1; i<=rows; i++)
	{
		for(j=1; j<=i; j++)
		{
			if(j==1 || j==i || i==rows)
			{
				cout<<"*";
			}		
			else
			{
				cout<<" ";
			}
		}
		cout<<endl;
	}
}
};
	int main()
	{
	child f;
	f.number();
}

 

Exit mobile version