Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. using System;
  2.  
  3. class Driver
  4. {
  5. static void Main()
  6. {
  7. Point pOne = new Point();
  8. Point pTwo = new Point(2, 1);
  9.  
  10. Console.Write("Point pOne: ");
  11. PrintPoint(pOne);
  12.  
  13. Console.Write("Point pthree: ");
  14. PrintPoint(pTwo);
  15.  
  16. Line lOne = new Line(pOne, pTwo);
  17.  
  18. Console.WriteLine("Line lOne: ");
  19. PrintLine(lOne);
  20.  
  21. //Rectangle rOne = new Rectangle();
  22. Rectangle rOne = new Rectangle(lOne);
  23.  
  24. Console.WriteLine("Rectangle rOne: ");
  25. PrintRectangle(rOne);
  26.  
  27. Console.ReadLine();
  28. }
  29.  
  30. // The PrintPoint method
  31. // purpose: display the coordinates of a Point
  32. // Parameters: a Point object
  33. // returns: none
  34. static void PrintPoint(Point p)
  35. {
  36. Console.Write("({0},{1})", p.GetXCoord(), p.GetYCoord());
  37. }
  38.  
  39. // the PrintLine method
  40. // purpose: display the endpoints of a line
  41. // Parameters: a Line object
  42. // returns: none
  43. static void PrintLine(Line aline)
  44. {
  45. // notice how we get the point objects from the line
  46. // and then print their coordinates
  47. Point p1 = aline.GetStartPoint();
  48. Point p2 = aline.GetEndPoint();
  49. Console.Write(" t");
  50. PrintPoint(p1);
  51. Console.Write(" - ");
  52. PrintPoint(p2);
  53. }
  54.  
  55. static void PrintRectangle(Rectangle aRec)
  56. {
  57. Line Left = aRec.getLeft();
  58. Line Top = aRec.gettop();
  59. Line Right = aRec.getRight();
  60. Line Bottem = aRec.getBottem();
  61.  
  62. Console.Write("t Left: ");
  63. PrintLine(Left);
  64. Console.Write("nt Top: ");
  65. PrintLine(Top);
  66. Console.Write("nt Right: ");
  67. PrintLine(Right);
  68. Console.Write("nt Bottem: ");
  69. PrintLine(Bottem);
  70.  
  71. }
  72. }
  73.  
  74. class Rectangle
  75. {
  76. private Line left;
  77. private Line top;
  78. private Line right;
  79. private Line bottem;
  80.  
  81.  
  82. public Rectangle()
  83. {
  84. Point zero = new Point();
  85.  
  86. left.setEndPoint(zero);
  87. left.SetStartPoint(zero);
  88.  
  89. top.setEndPoint(zero);
  90. top.SetStartPoint(zero);
  91.  
  92. right.setEndPoint(zero);
  93. right.SetStartPoint(zero);
  94.  
  95. bottem.setEndPoint(zero);
  96. bottem.SetStartPoint(zero);
  97.  
  98. }
  99.  
  100. public Rectangle(Line enter)
  101. {
  102. Point stDgl = new Point();
  103. Point endDgl = new Point();
  104.  
  105. stDgl = enter.GetStartPoint();
  106. endDgl = enter.GetEndPoint();
  107.  
  108. //stDgl
  109. int a = stDgl.GetXCoord();
  110. int b = stDgl.GetYCoord();
  111.  
  112. //endDgl
  113. int c = endDgl.GetXCoord();
  114. int d = endDgl.GetYCoord();
  115.  
  116. Point endright = new Point();
  117.  
  118. endright.SetXCoord(c);
  119. endright.SetYCoord(b);
  120.  
  121. Point endleft = new Point();
  122.  
  123. endleft.SetXCoord(a);
  124. endleft.SetYCoord(d);
  125.  
  126. //LEFT
  127. ********left.SetStartPoint(stDgl); - *NullReferenceException* -
  128. left.setEndPoint(endleft);
  129.  
  130. //TOP
  131. top.SetStartPoint(endleft);
  132. top.setEndPoint(endDgl);
  133.  
  134. //RIGHT
  135. right.SetStartPoint(endDgl);
  136. right.setEndPoint(endright);
  137.  
  138. //BOTTEM
  139. bottem.SetStartPoint(endright);
  140. bottem.setEndPoint(stDgl);
  141. }
  142.  
  143. public Line getLeft()
  144. {
  145. return left;
  146. }
  147.  
  148. public Line gettop()
  149. {
  150. return top;
  151. }
  152.  
  153. public Line getRight()
  154. {
  155. return right;
  156. }
  157.  
  158. public Line getBottem()
  159. {
  160. return bottem;
  161. }
  162.  
  163. }
  164.  
  165. // the Line class
  166. class Line
  167. {
  168. // data members - notice that they are Point objects
  169. private Point startPoint;
  170. private Point endPoint;
  171.  
  172. // default constructor
  173. // purpose: initialize data members to zero
  174. // Parameters: none
  175. // returns: none
  176. public Line()
  177. {
  178. // notice how we call methods in the Point class
  179. **startPoint.SetXCoord(0);** ***NullReferenceException***
  180. startPoint.SetYCoord(0);
  181. endPoint.SetXCoord(0);
  182. endPoint.SetYCoord(0);
  183. }
  184.  
  185. // parameterized constructor
  186. // purpose: initialize data members to p1 and p2
  187. // Parameters: Point objects p1 and p2
  188. // returns: none
  189. public Line(Point p1, Point p2)
  190. {
  191. startPoint = p1;
  192. endPoint = p2;
  193. }
  194.  
  195. /*
  196. //LEFT
  197. Point endleft = new Point();
  198.  
  199. endleft.SetXCoord(a);
  200. endleft.SetYCoord(d);
  201.  
  202. left.SetStartPoint(stDgl);
  203. left.setEndPoint(endleft);
  204. * */
  205.  
  206.  
  207. // the GetStartPoint method
  208. // purpose: return the value of the starting point
  209. // Parameters: none
  210. // returns: the value of the starting point as a Point object
  211. public Point GetStartPoint()
  212. {
  213. return startPoint;
  214. }
  215.  
  216. // the GetEndPoint method
  217. // purpose: return the value of the ending point
  218. // Parameters: none
  219. // returns: the value of the ending point as a Point object
  220. public Point GetEndPoint()
  221. {
  222. return endPoint;
  223. }
  224.  
  225. // the SetStartPoint method
  226. // purpose: store the value of the starting point
  227. // Parameters: the value of the starting point as a Point object
  228. // returns: none
  229. public void SetStartPoint(Point p1)
  230. {
  231. startPoint = p1;
  232. }
  233.  
  234. // the SetEndPoint method
  235. // purpose: store the value of the ending point
  236. // Parameters: the value of the ending point as a Point object
  237. // returns: none
  238. public void setEndPoint(Point p2)
  239. {
  240. endPoint = p2;
  241. }
  242. }
  243.  
  244. // The Point class
  245. class Point
  246. {
  247. // data members
  248. private int xCoord;
  249. private int yCoord;
  250.  
  251. // default constructor
  252. // purpose: initialize data members to zero
  253. // Parameters: none
  254. // returns: none
  255. public Point()
  256. {
  257. xCoord = 0;
  258. yCoord = 0;
  259. }
  260.  
  261. // parameterized constructor
  262. // purpose: initialize data members to x an y
  263. // Parameters: two integers x and y
  264. // returns: none
  265. public Point(int x, int y)
  266. {
  267. xCoord = x;
  268. yCoord = y;
  269. }
  270.  
  271. // the GetXCoord method
  272. // purpose: return the value of the x-coordinate
  273. // Parameters: none
  274. // returns: the value of the x-coordinate as an int
  275. public int GetXCoord()
  276. {
  277. return xCoord;
  278. }
  279.  
  280. // the GetYCoord method
  281. // purpose: return the value of the y-coordinate
  282. // Parameters: none
  283. // returns: the value of the y-coordinate as an int
  284. public int GetYCoord()
  285. {
  286. return yCoord;
  287. }
  288.  
  289. // the SetXCoord method
  290. // purpose: stores the value of the x-coordinate
  291. // Parameters: the value of the x-coordinate as an int
  292. // returns: none
  293. public void SetXCoord(int x)
  294. {
  295. xCoord = x;
  296. }
  297.  
  298. // the SetYCoord method
  299. // purpose: stores the value of the y-coordinate
  300. // Parameters: the value of the y-coordinate as an int
  301. // returns: none
  302. public void SetYCoord(int y)
  303. {
  304. yCoord = y;
  305. }
  306. }
  307.  
  308. class Line
  309. {
  310. private Point startPoint;
  311. private Point endPoint;
  312.  
  313. public Line()
  314. {
  315. startPoint.SetXCoord(0);
  316. ...
  317.  
  318. startPoint = new Point();
  319. startPoint.SetXCoord(0); // etc
  320.  
  321. public Rectangle(Line enter)
  322. {
  323. // ...
  324.  
  325. public Rectangle(Line enter) : this() // Call the default constructor as well
  326. {
  327. // ...
  328.  
  329. startPoint = new Point();
  330. endPoint = new Point();
Add Comment
Please, Sign In to add comment