Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04
- {
- class Zespolona
- {
- decimal Rzeczywista, Urojona;
- public Zespolona(decimal one, decimal two)
- {
- Rzeczywista = one;
- Urojona = two;
- }
- public static Zespolona operator +(Zespolona z1, Zespolona z2)
- {
- return new Zespolona(z1.Rzeczywista + z2.Rzeczywista, z1.Urojona + z2.Urojona);
- }
- public static Zespolona operator -(Zespolona z1, Zespolona z2)
- {
- return new Zespolona(z1.Rzeczywista - z2.Rzeczywista, z1.Urojona - z2.Urojona);
- }
- public static Zespolona operator *(Zespolona z1, Zespolona z2)
- {
- return new Zespolona((z1.Rzeczywista*z2.Rzeczywista-z1.Urojona*z2.Urojona),(z1.Urojona*z2.Rzeczywista+z1.Rzeczywista*z2.Urojona));
- }
- public static Zespolona operator /(Zespolona z1, Zespolona z2)
- {
- if(z2.Rzeczywista==0&&z2.Urojona==0)
- {
- throw new System.DivideByZeroException("Nie można dzielić przez 0.");
- }
- else
- return new Zespolona(z2.Rzeczywista*z2.Rzeczywista + z2.Urojona * z2.Urojona,(z1.Rzeczywista * z2.Rzeczywista - z1.Urojona * z2.Urojona) +(z1.Urojona * z2.Rzeczywista - z1.Rzeczywista * z2.Urojona));
- }
- public static bool operator !=(Zespolona z1, Zespolona z2)
- {
- bool stat = false;
- if(z1.Rzeczywista!=z2.Rzeczywista||z1.Urojona!=z2.Urojona)
- {
- stat = true;
- }
- return stat;
- }
- public static bool operator ==(Zespolona z1, Zespolona z2)
- {
- bool stat = false;
- if (z1.Rzeczywista == z2.Rzeczywista || z1.Urojona == z2.Urojona)
- {
- stat = true;
- }
- return stat;
- }
- public static bool operator >(Zespolona z1, Zespolona z2)
- {
- bool stat = false;
- if (z1.Rzeczywista > z2.Rzeczywista || z1.Urojona > z2.Urojona)
- {
- stat = true;
- }
- return stat;
- }
- public static bool operator <(Zespolona z1, Zespolona z2)
- {
- bool stat = false;
- if (z1.Rzeczywista < z2.Rzeczywista || z1.Urojona< z2.Urojona)
- {
- stat = true;
- }
- return stat;
- }
- public String getUro
- {
- get { return Convert.ToString(Urojona); }
- }
- public String getRze
- {
- get { return Convert.ToString(Rzeczywista); }
- }
- public static explicit operator decimal(Zespolona a)
- {
- return a.Rzeczywista;
- }
- public static implicit operator Zespolona(decimal a)
- {
- return new Zespolona(a,a);
- }
- public decimal this[int nr]
- {
- get {
- if (nr==0)
- {
- return Rzeczywista;
- }
- else if (nr==1)
- {
- return Urojona;
- }
- return 0;
- }
- }
- public decimal this[string a]
- {
- get
- {
- if(a.Equals("R"))
- {
- return Rzeczywista;
- }
- else if(a.Equals("I"))
- {
- return Urojona;
- }
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement