Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3D
  8. {
  9.  
  10. class Point3D
  11. {
  12. int x;
  13. public int X
  14. {
  15. get
  16. {
  17. return x;
  18. }
  19. set
  20. {
  21. try
  22. {
  23. if (value < 0)
  24. {
  25. throw new Exception("x не должен быть меньше нуля");
  26. }
  27. else { x = value; }
  28.  
  29. }
  30. catch (Exception e)
  31. {
  32. Console.WriteLine("Ошибка:" + e.Message);
  33. }
  34. }
  35. }
  36. int y;
  37. public int Y
  38. {
  39. get
  40. {
  41. return y;
  42. }
  43. set
  44. {
  45. try
  46. {
  47. if (value < 0)
  48. {
  49. throw new Exception("y не должен быть меньше нуля");
  50. }
  51. if (value > 100)
  52. {
  53. throw new Exception("y не должен быть больше 100");
  54. }
  55. y = value;
  56. }
  57. catch (Exception e)
  58. {
  59. if (value > 100)
  60. {
  61. y = 100;
  62. }
  63. Console.WriteLine("Ошибка:" + e.Message);
  64. }
  65. }
  66. }
  67.  
  68. int z;
  69. public int Z{
  70. get
  71. {
  72. return Z;
  73. }
  74. set
  75. {
  76. try
  77. {
  78. if (value > (x + y))
  79. {
  80. throw new Exception("z не должен быть больше чем сумма x и y");
  81. }
  82. else
  83. {
  84. z = value;
  85. }
  86. }
  87. catch (Exception e)
  88. {
  89. Console.WriteLine("Ошибка:" + e.Message);
  90. }
  91. }
  92. }
  93. public Point3D()
  94. {
  95.  
  96. }
  97. int Multiply
  98. {
  99. set
  100. {
  101. x *= value;
  102. y *= value;
  103. z *= value;
  104. }
  105. }
  106. public Point3D(int x, int y, int z)
  107. {
  108.  
  109.  
  110. try
  111. {
  112. if (x % 5 == 0 || y % 5 == 0 || z % 5 == 0)
  113. {
  114. this.z = z;
  115. this.x = x;
  116. this.y = y;
  117. }
  118. else throw new Exception("Ни ода из точек не делится на пять.");
  119. }
  120. catch(Exception e)
  121. {
  122.  
  123. Console.WriteLine("Ошибка:" + e.Message);
  124. //Point3D temp;
  125. do
  126. {
  127. Console.WriteLine("X, Y, Z:");
  128. this.x = int.Parse(Console.ReadLine());
  129.  
  130. this.y = int.Parse(Console.ReadLine());
  131.  
  132. this.z = int.Parse(Console.ReadLine());
  133. } while (this.x % 5 != 0 && this.y % 5 != 0 && this.z % 5 != 0);
  134.  
  135. //temp = new Point3D(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()));
  136.  
  137. //this.x = temp.X;
  138.  
  139. //this.y = temp.Y;
  140.  
  141. //this.z = temp.Z;
  142. }
  143.  
  144. }
  145. public void Move(char type, byte amount)
  146. {
  147. if (type == 'x')
  148. {
  149. x = amount;
  150. }
  151. else
  152. {
  153. if (type == 'y')
  154. {
  155. y = amount;
  156. }
  157. else
  158. {
  159. z = amount;
  160. }
  161. }
  162. }
  163.  
  164. public void CrdPrint()
  165. {
  166. Console.WriteLine("x:{0} y:{1} z:{2}", x, y, z);
  167. }
  168. public float RadiusVector()
  169. {
  170. return (float)Math.Sqrt(x * x + y * y + z * z);
  171. }
  172. public void Sum(Point3D ob)
  173. {
  174. this.z += ob.z;
  175. x += ob.x;
  176. y += ob.y;
  177. }
  178. public void Sum(int x,int y,int z)
  179. {
  180. this.z += z;
  181. this.x += x;
  182. this.y += y;
  183. }
  184. }
  185. class Paral
  186. {
  187. int x;
  188. int y;
  189. //int z;
  190. int height;
  191. int width;
  192. int length;
  193. public Paral()
  194. {
  195. x = 0;
  196. y = 0;
  197. //z = 0;
  198.  
  199. height = 5;
  200. length = 7;
  201. width = 6;
  202.  
  203.  
  204. }
  205. public Paral(int height, int width, int length, int x, int y)
  206. {
  207. this.height = height;
  208. this.width = width;
  209. this.length = length;
  210. this.x = x;
  211. this.y = y;
  212. //this.z = z;
  213. }
  214. public int getLength()
  215. {
  216. return length;
  217. }
  218. public int getWidth()
  219. {
  220. return width;
  221. }
  222. public int getHeight()
  223. {
  224. return height;
  225. }
  226. public int getArea()
  227. {
  228. return 2 * height * width + 2 * width * length + 2 * length * height;
  229. }
  230. public int getVolume()
  231. {
  232. return height * width * length;
  233. }
  234. public int getx()
  235. {
  236. return x;
  237. }
  238. public int gety()
  239. {
  240. return y;
  241. }
  242. public void showDimensions()
  243. {
  244. Console.WriteLine("Width:{0} Length:{1} Height{2}", width, length, height);
  245. }
  246. public bool IntersectionCheck(Paral ob)
  247. {
  248. if ((ob.getx() < (x + length) && ob.getx() > x) && (ob.gety() < (y + width) && ob.gety() > y))
  249. {
  250. return true;
  251. }
  252. if ((ob.getx() + ob.getLength() <= (x + length) && (ob.getx() + ob.getLength()) >= x) && (ob.gety() < (y + width) && ob.gety() >= y))
  253. return true;
  254. if ((ob.getx() + ob.getLength() <= (x + length) && (ob.getx() + ob.getLength()) >= x) && ob.gety() + ob.getWidth() >= y && ob.gety() + ob.getWidth() <= (y + width))
  255. return true;
  256. return false;
  257. }
  258. public void getUnionSize(Paral ob)
  259. {
  260. int width_union = 0;
  261. int length_union = 0;
  262. if (IntersectionCheck(ob))
  263. {
  264. if (ob.getx() < (x + length))
  265. {
  266. //if (ob.getx() >= x)
  267. //{
  268. if (ob.getx() + ob.getLength() > x + length)
  269. length_union = ob.getLength() - (ob.getx() + ob.getLength() - (x + length));
  270. else
  271. {
  272. if (ob.getx() < (x + length) && ob.getx() > x && ((ob.getx() + ob.length) < (x + length) && (ob.getx() + ob.length) > x))
  273. length_union = ob.getLength();
  274. else { length_union = ob.getx() + ob.getLength() - x; }
  275. //length_union = ob.getLength();
  276. }
  277. }
  278. else
  279. {
  280. length_union = ob.getx() + ob.length - x;
  281. }
  282.  
  283. //}
  284. if (ob.gety() < (y + width))
  285. {
  286. if (ob.gety() + ob.getWidth() > y + width)
  287. //width_union = (y + width) - ob.gety();
  288. width_union = ob.getWidth() - (ob.gety() + ob.getWidth() - (y + width));
  289. else
  290. {
  291. if (ob.gety() < (y + width) && ob.gety() > y && ((ob.gety() + ob.getWidth()) < (y + width) && (ob.gety() + ob.getWidth()) > y))
  292. width_union = ob.getLength();
  293. else { width_union = ob.gety() + ob.getWidth() - y; }
  294.  
  295. //width_union = ob.getWidth();
  296. }
  297. }
  298.  
  299. else
  300. {
  301. width_union = ob.gety() + ob.width - y;
  302. }
  303.  
  304.  
  305.  
  306. }
  307. Console.WriteLine(length_union + " " + width_union);
  308. }
  309. }
  310. class Program
  311. {
  312. static void Main(string[] args)
  313. {
  314. Point3D point = new Point3D(1, 2, 3);
  315. //Point3D point1 = new Point3D(0, 6, 30);
  316.  
  317. //point.CrdPrint();
  318. //point.Sum(point1);
  319. //point.CrdPrint();
  320. //Paral first = new Paral(90, 6, 7, 0, 0);
  321.  
  322. //while (true)
  323. //{
  324. // Console.WriteLine("Введите x и y:");
  325. // int x = int.Parse(Console.ReadLine());
  326. // int y = int.Parse(Console.ReadLine());
  327.  
  328. // Paral second = new Paral(80, 2, 2, x, y);
  329. // first.getUnionSize(second);
  330. //}
  331. //Console.Read();
  332. Console.WriteLine("Test");
  333. Console.ReadLine();
  334. while (true)
  335. {
  336.  
  337. point.X = int.Parse(Console.ReadLine());
  338. point.Y = int.Parse(Console.ReadLine());
  339. }
  340.  
  341. }
  342. }
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement