Write a C++ program to print rhombus star pattern of Number of rows using constructor overloading and destructor.
C++ program to print rhombus star pattern of Number of rows using constructor overloading
#include<iostream>
using namespace std;
class T4Tutorials
{
protected :
int i,j,k,n;
public :
T4Tutorials()
{
cout<<"Enter Number of rows : ";
cin>>n;
for(i=1 ; i<=n ; i++)
{
for(k=1 ;k<=n-i; k++)
{
cout<<" ";
}
for(j=1 ; j<=n ; j++)
{
cout<<"*";
}
cout<<endl;
}
}
};
int main()
{
T4Tutorials a;
}
C++ program to print rhombus star pattern of Number of rows using destructor
#include<iostream>
using namespace std;
class T4Tutorials
{
protected :
int i,j,k,n;
public :
~T4Tutorials()
{
cout<<"Enter Number of rows : ";
cin>>n;
for(i=1 ; i<=n ; i++)
{
for(k=1 ;k<=n-i; k++)
{
cout<<" ";
}
for(j=1 ; j<=n ; j++)
{
cout<<"*";
}
cout<<endl;
}
}
};
int main()
{
T4Tutorials a;
}
How to print rhombus or parallelogram star pattern using constructor overloading in C++ programming.
#include<iostream>
using namespace std;
class construct
{
protected :
int i,j,k,n;
public :
construct(int n)
{
for(i=1 ; i<=n ; i++)
{
for(k=1 ;k<=n-i; k++)
{
cout<<" ";
}
for(j=1 ; j<=n ; j++)
{
cout<<"*";
}
cout<<endl;
}
}
construct(int two,int three)
{
cout<<"\n\n1st patern is \n\n";
for(i=1 ; i<=two ; i++)
{
for(k=1 ;k<=two-i; k++)
{
cout<<" ";
}
for(j=1 ; j<=two ; j++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"\n\n2nd patern is \n\n";
for(i=1 ; i<=three ; i++)
{
for(k=1 ;k<=three-i; k++)
{
cout<<" ";
}
for(j=1 ; j<=three ; j++)
{
cout<<"*";
}
cout<<endl;
}
}
};
int main()
{
cout<<"\t\t\tThis Program Demonstrate The Single and";
cout<<"multiple paramter Constructor\n\n\n";
int option;
cout<<"Enter 1 of Single parameter constructor \n";
cout<<"\nEnter 2 For Multiple Paramter constucor \n";
cout<<"\nEnter 1 or 2 : ";
cin>>option;
system("cls"); //this function is to clear the screen
if(option ==1)
{
cout<<"\t\t\t-------You Have Slected Single Paramater";
cout<<"Constructor-------\n\n";
int n;
cout<<"Enter Number of rows : ";
cin>>n;
construct a(n);
}
else if(option==2)
{
cout<<"\t\t\t-------You Have slected Multiple Paramater ";
cout<<"Constructor-------\n\n";
int two,three;
cout<<"\n\nEnter Number of rows for 1st patern : ";
cin>>two;
cout<<"\n\nEnter Number of rows for 2nd patern : ";
cin>>three;
construct a(two, three);
}
else
{
cout<<"Your Input in Wrong try Agin \n\n\n";
}
}
How to print rhombus or parallelogram star pattern using destructor in C++ programming.
The Logic to print rhombus or parallelogram star pattern series in C program.
