Advertisement
gosuodin

MyPoint bai tap 5

Sep 13th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 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 abcd
  8. {
  9. class MyPoint
  10. {
  11. private
  12. int x, y;
  13. public
  14. MyPoint()
  15. {
  16. x = 0;
  17. y = 0;
  18. }
  19. MyPoint(int a, int b)
  20. {
  21. x = a;
  22. y = b;
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. int GetterX()
  31. {
  32. return x;
  33.  
  34. }
  35. int GetterY()
  36. {
  37. return y;
  38. }
  39.  
  40. void SetterX(int a)
  41. {
  42. x = a;
  43. }
  44. void SetterY(int b)
  45. {
  46. y = b;
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. string toString()
  55. {
  56. return string.Format("({0},{1})", x, y);
  57. }
  58. double distance(int a, int b)
  59. {
  60. return Math.Sqrt(Math.Pow((a-x),2)+Math.Pow((b-y),2));
  61. }
  62. double distance(MyPoint b){
  63. return Math.Sqrt(Math.Pow((b.x-x),2)+Math.Pow((b.y-y),2));
  64. }
  65. double distance(){
  66. return Math.Sqrt(Math.Pow(x,2)+Math.Pow(y,2));
  67. }
  68.  
  69.  
  70. static void Main(string[] args)
  71. {
  72. MyPoint a = new MyPoint(3,4);
  73. MyPoint b = new MyPoint(2,5);
  74. Console.WriteLine("toString :{0}", a.toString());
  75. double x=a.distance(b);
  76. Console.WriteLine("Khoang Cach {0}", x);
  77.  
  78. Console.ReadKey();
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement