WAP to implement single and multiple inheritance in c++

WAP to implement single inheritance in C++.

Example Program

WAP in C++ to display such a pattern for n 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 with the help of multiple inheritances. The pattern is as follows:

In the following program, the child is the child class of the parent class.

WAP to implement Single Inheritance

 

implement Single Inheritance class
implement Single Inheritance class

 

#include<iostream>
using namespace std;
class parent
{
	protected:
		int i,j,k,l,n;
};
class child:public parent
{
	public:
		int show()
		{
			cout<<"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;
			}
			
		}
};
int main()
{
	child obj;
	obj.show();
}

WAP to implement Multiple Inheritance

#include<iostream>
using namespace std;
class A
{
	protected:
		int i,j,k,l;
};
class B
{
	protected:
		int n;
};
class C:public A,public B
{
	public:
		int show()
		{
			cout<<"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;
			}
		}		      
 };
 int main()
 {
 	C obj;
 	obj.show();
 }
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.