Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 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 ConsoleApp67
  8. {
  9. class Weigth
  10. {
  11. private double funt;
  12.  
  13. public double Funt
  14. {
  15. get { return funt; }
  16. set { funt = value; }
  17. }
  18.  
  19. public double Unc
  20. {
  21. get { return funt * 16; }
  22. set { funt = value / 16; }
  23. }
  24.  
  25. public double Gram
  26. {
  27. get { return funt * 453.59237; }
  28. set { funt = value / 453.59237; }
  29. }
  30.  
  31. private Weigth(double w)
  32. {
  33. funt = w;
  34. }
  35.  
  36. public static Weigth CreateFromFunt(double funt)
  37. {
  38. return new Weigth(funt);
  39. }
  40.  
  41. public static Weigth CreateFromGram(double funt)
  42. {
  43. return new Weigth(funt / 453.59237);
  44. }
  45.  
  46. public static Weigth CreateFromUnc(double funt)
  47. {
  48. return new Weigth(funt / 16);
  49. }
  50.  
  51. public override string ToString()
  52. {
  53. return $"Funt={Funt:f5} Unc={Unc:f5} Gram={Gram:f5}\n";
  54. }
  55.  
  56. public static Weigth operator +(Weigth t1, Weigth t2)
  57. {
  58. return new Weigth(t1.Funt + t2.Funt);
  59. }
  60.  
  61. public static Weigth operator -(Weigth t1, Weigth t2)
  62. {
  63. return new Weigth(t1.Funt - t2.Funt);
  64. }
  65.  
  66.  
  67. }
  68.  
  69. class Program
  70. {
  71. static void Main(string[] args)
  72. {
  73. Weigth w1, w2, w3;
  74. w1 = Weigth.CreateFromFunt(40);
  75. w2 = Weigth.CreateFromGram(10);
  76. w3 = Weigth.CreateFromUnc(20);
  77.  
  78. Console.WriteLine(w1);
  79. Console.WriteLine(w2);
  80. Console.WriteLine(w3);
  81. Console.WriteLine(w2 - w1);
  82. Console.WriteLine(w1 + w3);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement