Advertisement
Guest User

dsadsad

a guest
May 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5. namespace zad1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Pozycja p1 = new Pozycja("mleko",40);
  12. Pozycja p2 = new Pozycja("jajka", 10);
  13. Pozycja p3 = new Pozycja("mąka", 50);
  14. List<Pozycja> poz = new List<Pozycja>();
  15. poz.Add(p1);
  16. poz.Add(p2);
  17. poz.Add(p3);
  18. List<Pozycja> poz1 = new List<Pozycja>();
  19. poz1.Add(p1);
  20. poz1.Add(p2);
  21. Faktura f1 = new Faktura("jakas", 5344);
  22. f1.Pozycje = poz;
  23. Faktura f2 = new Faktura("jakas nowa", 53441);
  24. f2.Pozycje = poz;
  25. Console.WriteLine(f1>=f2);
  26. // Console.WriteLine(f1);
  27.  
  28. Console.ReadKey();
  29.  
  30. }
  31. }
  32.  
  33. struct Pozycja
  34. {
  35. string nazwa;
  36. int cena;
  37.  
  38. public int Cena
  39. {
  40. get { return cena; }
  41. }
  42.  
  43. public Pozycja(string nazwa, int cena)
  44. {
  45. this.nazwa = nazwa;
  46. this.cena = cena;
  47. }
  48.  
  49. public override string ToString()
  50. {
  51. return nazwa + " cena: " + cena;
  52. }
  53. }
  54.  
  55. class Faktura : IComparable
  56. {
  57. protected string nazwa;
  58. protected int numer;
  59. protected List<Pozycja> pozycje = new List<Pozycja>();
  60.  
  61. public Faktura(string name, int id)
  62. {
  63. nazwa = name;
  64. numer = id;
  65. }
  66. public List<Pozycja> Pozycje
  67. {
  68. // get { return pozycje; }
  69. set { pozycje = value; }
  70.  
  71. }
  72. public int CompareTo(object obj)
  73. {
  74. return 0;
  75. }
  76. public static bool operator >(Faktura a,Faktura b)
  77. {
  78. int sum_a = Suma_wartosci_pozycji(a);
  79. int sum_b = Suma_wartosci_pozycji(b);
  80.  
  81. if (sum_a > sum_b) return true;
  82. else return false;
  83. }
  84. public static bool operator <(Faktura a, Faktura b)
  85. {
  86. if (a > b) return false;
  87. else return true;
  88. }
  89. public static bool operator >=(Faktura a, Faktura b)
  90. {
  91. int sum_a = Suma_wartosci_pozycji(a);
  92. int sum_b = Suma_wartosci_pozycji(b);
  93.  
  94. if (sum_a >= sum_b) return true;
  95. else return false;
  96. }
  97. public static bool operator <=(Faktura a, Faktura b)
  98. {
  99. int sum_a = Suma_wartosci_pozycji(a);
  100. int sum_b = Suma_wartosci_pozycji(b);
  101.  
  102. if (sum_a <= sum_b) return true;
  103. else return false;
  104. }
  105. public static int operator +(Faktura a)
  106. {
  107. return Suma_wartosci_pozycji(a);
  108. }
  109. public static Faktura operator +(Faktura a,Faktura b)
  110. {
  111. int y= Suma_wartosci_pozycji(a)+Suma_wartosci_pozycji(b);
  112. Faktura nowa = new Faktura("nowa", 11111);
  113. Pozycja nq = new Pozycja("cos", y);
  114. nowa.pozycje.Add(nq);
  115. return nowa;
  116. }
  117. public static bool operator ==(Faktura a,Faktura b)
  118. {
  119. if (a.nazwa == b.nazwa && a.numer == b.numer)
  120. return true;
  121. else return false;
  122. }
  123. public static bool operator !=(Faktura a, Faktura b)
  124. {
  125. return !(a == b);
  126. }
  127. static int Suma_wartosci_pozycji(Faktura a)
  128. {
  129. int suma_a = 0;
  130. for (int i = 0; i < a.pozycje.Count; i++)
  131. {
  132. suma_a += a.pozycje[i].Cena;
  133. }
  134. return suma_a;
  135. }
  136.  
  137. public override string ToString()
  138. {
  139. String s = nazwa + ":" + numer;
  140. foreach (Pozycja p in pozycje) s += "\n" + p;
  141. return s + "\n\n";
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement