Advertisement
erfanul007

determine the shape

Dec 2nd, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. struct node{
  5. double x;
  6. double y;
  7. };
  8.  
  9. double distace(double x1, double y1, double x2, double y2)
  10. {
  11. double d;
  12. d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  13. return d;
  14. }
  15.  
  16. double slop(double x1, double y1, double x2, double y2)
  17. {
  18. double m;
  19. if(x1==x2)
  20. m=10009;
  21. else
  22. m=(y2-y1)/(x2-x1);
  23. return m;
  24. }
  25.  
  26. int main()
  27. {
  28. int n,i;
  29. double ab,bc,cd,da;
  30. double abm,bcm,cdm,dam;
  31. struct node a,b,c,d;
  32. freopen("input.txt","r",stdin);
  33. scanf("%d",&n);
  34. for(i=1;i<=n;i++){
  35. scanf("%lf %lf",&a.x,&a.y);
  36. scanf("%lf %lf",&b.x,&b.y);
  37. scanf("%lf %lf",&c.x,&c.y);
  38. scanf("%lf %lf",&d.x,&d.y);
  39.  
  40. printf("Case %d: ",i);
  41.  
  42. ab = distace(a.x, a.y, b.x, b.y);
  43. bc = distace(b.x, b.y, c.x, c.y);
  44. cd = distace(d.x, d.y, c.x, c.y);
  45. da = distace(a.x, a.y, d.x, d.y);
  46.  
  47. abm = slop(a.x, a.y, b.x, b.y);
  48. bcm = slop(b.x, b.y, c.x, c.y);
  49. cdm = slop(d.x, d.y, c.x, c.y);
  50. dam = slop(a.x, a.y, d.x, d.y);
  51.  
  52. if(ab==cd && bc==da){
  53. if(ab==bc){
  54. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  55. printf("Square\n");
  56. else if((bcm!=10009 && abm!=10009) && abm==-(1/bcm))
  57. printf("Square\n");
  58. else if(abm==cdm && bcm==dam)
  59. printf("Rhombus\n");
  60. }
  61. else{
  62. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  63. printf("Rectangle\n");
  64. else if((bcm!=10009 && abm!=10009) && ((abm==-(1/bcm))||(bcm==-(1/abm))))
  65. printf("Rectangle\n");
  66. else if(abm==cdm && bcm==dam)
  67. printf("Parallelogram\n");
  68. }
  69. }
  70. else{
  71. if(abm==cdm || bcm==dam)
  72. printf("Trapezium\n");
  73. else{
  74. ab = distace(a.x, a.y, b.x, b.y);
  75. bc = distace(b.x, b.y, d.x, d.y);
  76. cd = distace(c.x, c.y, d.x, d.y);
  77. da = distace(a.x, a.y, c.x, c.y);
  78.  
  79. abm = slop(a.x, a.y, b.x, b.y);
  80. bcm = slop(b.x, b.y, d.x, d.y);
  81. cdm = slop(c.x, c.y, d.x, d.y);
  82. dam = slop(a.x, a.y, c.x, c.y);
  83.  
  84. if(ab==cd && bc==da){
  85. if(ab==bc){
  86. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  87. printf("Square\n");
  88. else if((bcm!=10009 && abm!=10009) && abm==-(1/bcm))
  89. printf("Square\n");
  90. else if(abm==cdm && bcm==dam)
  91. printf("Rhombus\n");
  92. }
  93. else{
  94. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  95. printf("Rectangle\n");
  96. else if((bcm!=10009 && abm!=10009) && ((abm==-(1/bcm))||(bcm==-(1/abm))))
  97. printf("Rectangle\n");
  98. else if(abm==cdm && bcm==dam)
  99. printf("Parallelogram\n");
  100. }
  101. }
  102. else{
  103. if(abm==cdm || bcm==dam)
  104. printf("Trapezium\n");
  105. else{
  106. ab = distace(a.x, a.y, c.x, c.y);
  107. bc = distace(c.x, c.y, b.x, b.y);
  108. cd = distace(d.x, d.y, b.x, b.y);
  109. da = distace(a.x, a.y, d.x, d.y);
  110.  
  111. abm = slop(a.x, a.y, c.x, c.y);
  112. bcm = slop(c.x, c.y, b.x, b.y);
  113. cdm = slop(d.x, d.y, b.x, b.y);
  114. dam = slop(a.x, a.y, d.x, d.y);
  115.  
  116. if(ab==cd && bc==da){
  117. if(ab==bc){
  118. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  119. printf("Square\n");
  120. else if((bcm!=10009 && abm!=10009) && abm==-(1/bcm))
  121. printf("Square\n");
  122. else if(abm==cdm && bcm==dam)
  123. printf("Rhombus\n");
  124. }
  125. else{
  126. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  127. printf("Rectangle\n");
  128. else if((bcm!=10009 && abm!=10009) && ((abm==-(1/bcm))||(bcm==-(1/abm))))
  129. printf("Rectangle\n");
  130. else if(abm==cdm && bcm==dam)
  131. printf("Parallelogram\n");
  132. }
  133. }
  134. else{
  135. if(abm==cdm || bcm==dam)
  136. printf("Trapezium\n");
  137. else{
  138. ab = distace(a.x, a.y, c.x, c.y);
  139. bc = distace(c.x, c.y, d.x, d.y);
  140. cd = distace(b.x, b.y, d.x, d.y);
  141. da = distace(a.x, a.y, b.x, b.y);
  142.  
  143. abm = slop(a.x, a.y, c.x, c.y);
  144. bcm = slop(c.x, c.y, d.x, d.y);
  145. cdm = slop(b.x, b.y, d.x, d.y);
  146. dam = slop(a.x, a.y, b.x, b.y);
  147.  
  148. if(ab==cd && bc==da){
  149. if(ab==bc){
  150. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  151. printf("Square\n");
  152. else if((bcm!=10009 && abm!=10009) && abm==-(1/bcm))
  153. printf("Square\n");
  154. else if(abm==cdm && bcm==dam)
  155. printf("Rhombus\n");
  156. }
  157. else{
  158. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  159. printf("Rectangle\n");
  160. else if((bcm!=10009 && abm!=10009) && ((abm==-(1/bcm))||(bcm==-(1/abm))))
  161. printf("Rectangle\n");
  162. else if(abm==cdm && bcm==dam)
  163. printf("Parallelogram\n");
  164. }
  165. }
  166. else{
  167. if(abm==cdm || bcm==dam)
  168. printf("Trapezium\n");
  169. else{
  170. ab = distace(a.x, a.y, d.x, d.y);
  171. bc = distace(d.x, d.y, b.x, b.y);
  172. cd = distace(c.x, c.y, b.x, b.y);
  173. da = distace(a.x, a.y, c.x, c.y);
  174.  
  175. abm = slop(a.x, a.y, d.x, d.y);
  176. bcm = slop(d.x, d.y, b.x, b.y);
  177. cdm = slop(c.x, c.y, b.x, b.y);
  178. dam = slop(a.x, a.y, c.x, c.y);
  179.  
  180. if(ab==cd && bc==da){
  181. if(ab==bc){
  182. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  183. printf("Square\n");
  184. else if((bcm!=10009 && abm!=10009) && abm==-(1/bcm))
  185. printf("Square\n");
  186. else if(abm==cdm && bcm==dam)
  187. printf("Rhombus\n");
  188. }
  189. else{
  190. if((abm==10009 && bcm==0)||(abm==0 && bcm==10009))
  191. printf("Rectangle\n");
  192. else if((bcm!=10009 && abm!=10009) && ((abm==-(1/bcm))||(bcm==-(1/abm))))
  193. printf("Rectangle\n");
  194. else if(abm==cdm && bcm==dam)
  195. printf("Parallelogram\n");
  196. }
  197. }
  198. else{
  199. if(abm==cdm || bcm==dam)
  200. printf("Trapezium\n");
  201. else
  202. printf("Ordinary Quadrilateral\n");
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. return 0;
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement