Constructor Example using For Loop ♥
#include<iostream.h>
#include<conio.h>
class mahi
{
int m,n,i,j,k;
public:
mahi(int,int);
void display()
{
for(i=m;i<=n;i++)
{
for(k=m;k<=n-i;k++)
{
cout<<" ";
}
for(j=m;j<=i;j++)
{
cout<<" "<<i;
}
cout<<"\n";
}
}
};
mahi::mahi(int x,int y)
{
m=x;
n=y;
}
void main()
{
clrscr();
mahi m1(1,3);
mahi m2(1,5);
cout<<"\n\n OBJECT1\n";
m1.display();
cout<<"\n\n OBJECT2\n";
m2.display();
getch();
}
Here is the Output :)
No comments:
Post a Comment