Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace zad1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Pozycja p1 = new Pozycja("mleko",40);
- Pozycja p2 = new Pozycja("jajka", 10);
- Pozycja p3 = new Pozycja("mąka", 50);
- List<Pozycja> poz = new List<Pozycja>();
- poz.Add(p1);
- poz.Add(p2);
- poz.Add(p3);
- List<Pozycja> poz1 = new List<Pozycja>();
- poz1.Add(p1);
- poz1.Add(p2);
- Faktura f1 = new Faktura("jakas", 5344);
- f1.Pozycje = poz;
- Faktura f2 = new Faktura("jakas nowa", 53441);
- f2.Pozycje = poz;
- Console.WriteLine(f1>=f2);
- // Console.WriteLine(f1);
- Console.ReadKey();
- }
- }
- struct Pozycja
- {
- string nazwa;
- int cena;
- public int Cena
- {
- get { return cena; }
- }
- public Pozycja(string nazwa, int cena)
- {
- this.nazwa = nazwa;
- this.cena = cena;
- }
- public override string ToString()
- {
- return nazwa + " cena: " + cena;
- }
- }
- class Faktura : IComparable
- {
- protected string nazwa;
- protected int numer;
- protected List<Pozycja> pozycje = new List<Pozycja>();
- public Faktura(string name, int id)
- {
- nazwa = name;
- numer = id;
- }
- public List<Pozycja> Pozycje
- {
- // get { return pozycje; }
- set { pozycje = value; }
- }
- public int CompareTo(object obj)
- {
- return 0;
- }
- public static bool operator >(Faktura a,Faktura b)
- {
- int sum_a = Suma_wartosci_pozycji(a);
- int sum_b = Suma_wartosci_pozycji(b);
- if (sum_a > sum_b) return true;
- else return false;
- }
- public static bool operator <(Faktura a, Faktura b)
- {
- if (a > b) return false;
- else return true;
- }
- public static bool operator >=(Faktura a, Faktura b)
- {
- int sum_a = Suma_wartosci_pozycji(a);
- int sum_b = Suma_wartosci_pozycji(b);
- if (sum_a >= sum_b) return true;
- else return false;
- }
- public static bool operator <=(Faktura a, Faktura b)
- {
- int sum_a = Suma_wartosci_pozycji(a);
- int sum_b = Suma_wartosci_pozycji(b);
- if (sum_a <= sum_b) return true;
- else return false;
- }
- public static int operator +(Faktura a)
- {
- return Suma_wartosci_pozycji(a);
- }
- public static Faktura operator +(Faktura a,Faktura b)
- {
- int y= Suma_wartosci_pozycji(a)+Suma_wartosci_pozycji(b);
- Faktura nowa = new Faktura("nowa", 11111);
- Pozycja nq = new Pozycja("cos", y);
- nowa.pozycje.Add(nq);
- return nowa;
- }
- public static bool operator ==(Faktura a,Faktura b)
- {
- if (a.nazwa == b.nazwa && a.numer == b.numer)
- return true;
- else return false;
- }
- public static bool operator !=(Faktura a, Faktura b)
- {
- return !(a == b);
- }
- static int Suma_wartosci_pozycji(Faktura a)
- {
- int suma_a = 0;
- for (int i = 0; i < a.pozycje.Count; i++)
- {
- suma_a += a.pozycje[i].Cena;
- }
- return suma_a;
- }
- public override string ToString()
- {
- String s = nazwa + ":" + numer;
- foreach (Pozycja p in pozycje) s += "\n" + p;
- return s + "\n\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement