#include <iostream> #include <cmath> using namespace std; typedef bool dot(int y,int x,int size); void draw(int yl,int yh,int xl,int xh,int size,dot *check) { for(int y=yl;y<=yh;++y,cout<<endl) for(int x=xl;x<=xh;++x) cout<<check(y,x,size)[" *"]; } struct { const char *name; dot *check; } tb[]= { {"diamond",[](int y,int x,int size) { return abs(y)+abs(x)<=size; } }, {"triangle A",[](int y,int x,int size) { return y+x<=0; } }, {"triangle B",[](int y,int x,int size) { return y+x>=0; } }, {"triangle C",[](int y,int x,int size) { return y-x<=0; } }, {"triangle D",[](int y,int x,int size) { return y-x>=0; } }, {"rectangle",[](int y,int x,int size) { return (abs(y)==size)||(abs(x)==size); } }, {"cross A",[](int y,int x,int size) { return abs(y)==abs(x); } }, {"cross B",[](int y,int x,int size) { return (!y)||(!x); } }, {"hourglass A",[](int y,int x,int size) { return (y<=0)&&(x<=y)||(y>=0)&&(x>=y); } }, {"hourglass B",[](int y,int x,int size) { return (x<=0)&&(x>=y)||(x>=0)&&(x<=y); } }, {"ellipse A",[](int y,int x,int size) { return round(sqrt(x*x+y*y))==size; } }, {"ellipse B",[](int y,int x,int size) { return round(sqrt(x*x+y*y))<=size; } }, {"ellipse C",[](int y,int x,int size) { return round(sqrt(x*x+y*y))>size; } }, }; int main() { for(int count;(cout<<"Podaj rozmiar: ")&&(cin>>count);) { for(auto shape:tb) { cout<<shape.name<<':'<<endl; draw(-count,count,-count,count,count,shape.check); cout<<endl<<endl; } } return 0; }
4 5 6 7
Podaj rozmiar: diamond:
*
***
*****
*******
*********
*******
*****
***
*
triangle A:
*********
********
*******
******
*****
****
***
**
*
triangle B:
*
**
***
****
*****
******
*******
********
*********
triangle C:
*********
********
*******
******
*****
****
***
**
*
triangle D:
*
**
***
****
*****
******
*******
********
*********
rectangle:
*********
* *
* *
* *
* *
* *
* *
* *
*********
cross A:
* *
* *
* *
* *
*
* *
* *
* *
* *
cross B:
*
*
*
*
*********
*
*
*
*
hourglass A:
*
**
***
****
*********
****
***
**
*
hourglass B:
*****
****
***
**
*
**
***
****
*****
ellipse A:
*****
** **
** **
* *
* *
* *
** **
** **
*****
ellipse B:
*****
*******
*********
*********
*********
*********
*********
*******
*****
ellipse C:
** **
* *
* *
** **
Podaj rozmiar: diamond:
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
triangle A:
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle B:
*
**
***
****
*****
******
*******
********
*********
**********
***********
triangle C:
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle D:
*
**
***
****
*****
******
*******
********
*********
**********
***********
rectangle:
***********
* *
* *
* *
* *
* *
* *
* *
* *
* *
***********
cross A:
* *
* *
* *
* *
* *
*
* *
* *
* *
* *
* *
cross B:
*
*
*
*
*
***********
*
*
*
*
*
hourglass A:
*
**
***
****
*****
***********
*****
****
***
**
*
hourglass B:
******
*****
****
***
**
*
**
***
****
*****
******
ellipse A:
*****
* *
* *
* *
* *
* *
* *
* *
* *
* *
*****
ellipse B:
*****
*******
*********
***********
***********
***********
***********
***********
*********
*******
*****
ellipse C:
*** ***
** **
* *
* *
** **
*** ***
Podaj rozmiar: diamond:
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*
triangle A:
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle B:
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
triangle C:
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle D:
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
rectangle:
*************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*************
cross A:
* *
* *
* *
* *
* *
* *
*
* *
* *
* *
* *
* *
* *
cross B:
*
*
*
*
*
*
*************
*
*
*
*
*
*
hourglass A:
*
**
***
****
*****
******
*************
******
*****
****
***
**
*
hourglass B:
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
ellipse A:
*****
** **
** **
* *
* *
* *
* *
* *
* *
* *
** **
** **
*****
ellipse B:
*****
*********
***********
***********
*************
*************
*************
*************
*************
***********
***********
*********
*****
ellipse C:
**** ****
** **
* *
* *
* *
* *
** **
**** ****
Podaj rozmiar: diamond:
*
***
*****
*******
*********
***********
*************
***************
*************
***********
*********
*******
*****
***
*
triangle A:
***************
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle B:
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
**************
***************
triangle C:
***************
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
triangle D:
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
**************
***************
rectangle:
***************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
***************
cross A:
* *
* *
* *
* *
* *
* *
* *
*
* *
* *
* *
* *
* *
* *
* *
cross B:
*
*
*
*
*
*
*
***************
*
*
*
*
*
*
*
hourglass A:
*
**
***
****
*****
******
*******
***************
*******
******
*****
****
***
**
*
hourglass B:
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
ellipse A:
*****
** **
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
** **
*****
ellipse B:
*****
*********
***********
*************
*************
***************
***************
***************
***************
***************
*************
*************
***********
*********
*****
ellipse C:
***** *****
*** ***
** **
* *
* *
* *
* *
** **
*** ***
***** *****
Podaj rozmiar: