|
Elabnody
Web Master

Egypt
59 Posts |
Posted - 04/21/2009 : 06:11:23
|
// SQARES.cpp : Defines the entry point for the console application. // Mohamed Reda
#include "stdafx.h" #include <iostream> using namespace std;
int main() { //Declaring Neede Variables int width,hight; int sqs,maxsqs; //The number of squares inside the shape
do{ cout<<"Enter the WIDTH of the sahpe (Gteater than 1): ";cin>>width;} while(width<2); cout<<endl;// To insure that the width is Greater than 1
do{ cout<<"Enter the HIGHT of the sahpe (Greater than 1): ";cin>>hight;} while(hight<2); cout<<endl;// To inusre that the hight is Greater than 1 //Now we will define the max squares which is the most important variable in the code if(width<hight)maxsqs=(width/4)+ (width%4>1 ? 1 : 0);else maxsqs=(hight/4)+ (hight%4>1 ? 1 : 0); do{ cout<<"Number of Squares Needed inside the shape, " <<"The Max number of sqaure is "<<maxsqs <<"\nEnter the number of squares (Between 1 and "<<maxsqs<<"): ";cin>>sqs;} while(sqs<1 || sqs>maxsqs); // To inusre that the sqaure Between 1 and max cout<<endl;
//Drawing the above shape //*****************************************************************************
//Part one for(int r=0;r<2*sqs-1;r++) { for(int left=0;left<r;left++)if(left%2==0)cout<<"* ";else cout<<" "; for(int mid=0;mid<width-2*r;mid++)if(r%2==0)cout<<"* ";else cout<<" "; for(int right=0; right<r;right++) if(r%2==0) if(right%2==0)cout<<" ";else cout<<"* "; else if(right%2==0)cout<<"* ";else cout<<" "; cout<<endl; }
//Part tow for(int r=0;r<hight-(4*sqs-2);r++) { for(int left=0;left<2*sqs-1;left++)if(left%2==0)cout<<"* ";else cout<<" "; for(int mid=0;mid<width-(4*sqs-2);mid++)cout<<" "; for(int right=0;right<2*sqs-1;right++)if(right%2==0)cout<<"* ";else cout<<" "; cout<<endl; }
//Part three for(int r=2*sqs-2;r>=0;r--) { for(int left=0;left<r;left++)if(left%2==0)cout<<"* ";else cout<<" "; for(int mid=0;mid<width-2*r;mid++)if(r%2==0)cout<<"* ";else cout<<" "; for(int right=0;right<r;right++) if(r%2==0) if(right%2==0)cout<<" ";else cout<<"* "; else if(right%2==0)cout<<"* ";else cout<<" "; cout<<endl; } //*****************************************************************************
cout<<endl<<"Creater by MOHAMED REDA ZAKI (Hope Your Doaa)"<<endl; return 0; }
|
|