Showing posts with label Hollow. Show all posts
Showing posts with label Hollow. Show all posts

Tuesday 13 August 2013

Hollow Square

Hollow Square

In this post of shapes in c, you will find the code for constructing a hollow square in C++ using "*". 

Code:

Copy your code from below:
/*        Join us at
    http://shapesinc.blogspot.com 
      for more codes of shapes
*/
#include<iostream>
using namespace std;
int main()
{
cout << "Join http://shapesinc.blogspot.com for more codes of shapes\n\n";
 cout<<"CAUTION:   The input should not be other than numerical values \n\n\a";  
int length=0;
cout << "Enter the length of the hollow square\n";
cin>>length;
for(int i=0; i<length; i++)
{
for(int j=0; j<length; j++)
{
if(i==0 || i==length-1 || j==0 || j==length-1)
cout << "*";
else
cout << " ";
}
cout<<endl;
}
}

Output:


Hollow_Square_Shapes_In_c


Hollow rectangle

Hollow Rectangle:

In this post of shapes in c, you will find the code to draw hollow rectangle in C++ using "*".

Code:

Copy your code from below.
/*         Join us at 
 http://shapesinc.blogspot.com 
   for more codes of shapes */
#include<iostream>
using namespace std;
int main()
{
cout << "Join http://shapesinc.blogspot.com for more codes of shapes\n\n";
 cout<<"CAUTION:   The input should not be other than numerical values \n\n\a";  
int length=0, width=0;
cout << "Enter the length of the hollow rectangle\n";
cin>>length;
cout << "Enter the width of the hollow rectangle\n";
cin>>width;
for(int i=0; i<length; i++)
{
for(int j=0; j<width; j++)
{
if(i==0 || i==length-1 || j==0 || j==width-1)
cout << "*";
else
cout << " ";
}
cout<<endl;
}
}


Output:




Hollow_Rectangle_Shapes_In_C

Moving Fan

Moving Fan:

In this post of shapes in c you will be able to construct the code for a moving fan in C++ using "*".

Code:

#include<iostream>
#include<Windows.h>
using namespace std;
void fan1(const int size);
void fan2(const int size);
int main()
{
int size, time;
cout<< "Enter the size of fan" << endl;
cin>>size;
cout<< "For how many seconds you want to switch on the fan" << endl;
cin>>time;
system("cls");
for(int i=0 ; i<2*time ; i++)
{
fan1(size);
Sleep(500);
system("cls");
fan2(size);
Sleep(500);
system("cls");
}
return 0;
}
void fan1 (const int size)
{
for(int i=0 ; i<=size ; i++)
{
for(int j=0 ; j<=i ; j++)
{
if(i!=size)
{
if(j==0 || j==i)
cout<< "* ";
else
cout<<"  ";
}
else if (i==size )
cout<< "* ";
}
for(int spaces=i ; spaces<size ; spaces++)
cout<<"  ";
for(int j=i ; j<=size ; j++)
{
if(i==0)
cout<< "* ";
else 
if(j==i || j==size)
cout<<"* ";
else
cout<<"  ";
}
cout<<endl;
}
for(int m=0 ; m<=size ; m++)
{
for(int spaces1=m ; spaces1<size ; spaces1++)
cout<<"  ";
for(int n=0; n<=m ; n++)
{
if(m==size)
cout<<"* ";
else 
if(n==0 || n==m)
cout<<"* ";
else 
cout<<"  ";
}
for(int spaces1=0 ; spaces1<m ; spaces1++)
cout<<"  ";
for(int n=m; n<=size; n++)
{
if(m==0)
cout<<"* ";
else
if(n==m || n==size)
cout<<"* ";
else 
cout<<"  ";
}
cout<<endl;
}
}
void fan2 (const int size)
{
for(int i=0 ; i<=size ; i++)
{
for(int j=0 ; j<i ; j++)
cout<<"  ";
for(int spaces=i ; spaces<=size ; spaces++)
{
if(i==0)
cout<<"* ";
else
if(spaces==i || spaces==size)
cout<<"* ";
else 
cout<<"  ";
}
for(int j=i ; j<size ; j++)
cout<<"  ";
for(int j=0; j<=i ; j++)
{
if(i==size)
cout<<"* ";
else 
if(j==0 || j==i)
cout<<"* ";
else 
cout<<"  ";
}
cout<<endl;
}
for(int m=0 ; m<=size ; m++)
{
for(int spaces1=m ; spaces1<=size ; spaces1++)
{
if (m==0)
cout<<"* ";
else
if(spaces1==m || spaces1==size)
cout<<"* ";
else
cout<<"  ";
}
for(int n=0; n<m ; n++)
cout<<"  ";
for(int spaces1=0 ; spaces1<=m ; spaces1++)
{
if(m==0 || m==size)
cout<<"* ";
else
if(spaces1==0 || spaces1==m)
cout<<"* ";
else 
cout<<"  ";
}
cout<<endl;
}
}