Advertisement
BloodMoonYTC

KomplexOsztaly

Oct 19th, 2021
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace komplexosztaly
  4. {
  5.     class Komplex
  6.     {
  7.         double re, im;
  8.         public Komplex(double rr, double ii)
  9.         {
  10.             re = rr;
  11.             im = ii;
  12.         }
  13.         public double RE
  14.         {
  15.             get { return re; }
  16.             set { re = value; }
  17.         }
  18.         public double IM
  19.         {
  20.             get { return im; }
  21.             set { im = value; }
  22.         }
  23.         public void KiIr()
  24.         {
  25.             Console.WriteLine("{0} {1} {2}", re, (im < 0 ? '-' : '+'), Math.Abs(im));
  26.         }
  27.         public void KompOsszead(Komplex k1)
  28.         {
  29.             this.re = this.re + k1.re;
  30.             this.im = this.im + k1.im;
  31.         }
  32.         public void KompKivon(Komplex k1)
  33.         {
  34.             this.re = this.re - k1.re;
  35.             this.im = this.im - k1.im;
  36.         }
  37.         public void KompSzoroz(Komplex k1)
  38.         {
  39.             double re = this.re * k1.re - this.im * k1.im;
  40.             double im = this.re * k1.im + this.im * k1.re;
  41.             this.re = re;
  42.             this.im = im;
  43.         }
  44.         public void KompOszt(Komplex k1)
  45.         {
  46.             double d = Math.Pow(k1.re, 2.0) + Math.Pow(k1.im, 2.0);
  47.             double re = (this.re * k1.re + this.im * k1.im) / d;
  48.             double im = (this.im * k1.re - this.re * k1.im) / d;
  49.             this.re = re;
  50.             this.im = im;
  51.         }
  52.     }
  53.     class Program
  54.     {
  55.         static void Main(string[] args)
  56.         {
  57.             double rr1, ii1, rr2, ii2, rr3 = 0, ii3 = 0;
  58.             Komplex K3 = new Komplex(rr3, ii3);
  59.             while (true)
  60.             {
  61.                 Console.Write("Komplex1 - Realis Rész: ");
  62.                 rr1 = double.Parse(Console.ReadLine());
  63.                 Console.Write("Komplex1 - Imaginaris Rész: ");
  64.                 ii1 = double.Parse(Console.ReadLine());
  65.                 if (rr1 == 0 && ii1 == 0) break;
  66.                 Console.Write("Komplex2 - Realis Rész: ");
  67.                 rr2 = double.Parse(Console.ReadLine());
  68.                 Console.Write("Komplex2 - Imaginaris Rész: ");
  69.                 ii2 = double.Parse(Console.ReadLine());
  70.  
  71.                 Komplex K1 = new Komplex(rr1, ii1);
  72.                 Komplex K2 = new Komplex(rr2, ii2);
  73.  
  74.                 Console.Write("Z1= ");
  75.                 K1.KiIr();
  76.                 Console.Write("Z2= ");
  77.                 K2.KiIr();
  78.  
  79.                 K1.KompOsszead(K2);
  80.                 Console.Write("A komplex számok összege: ");
  81.                 K1.KiIr();
  82.  
  83.                 K1.RE = rr1;
  84.                 K1.IM = ii1;
  85.                 K1.KompKivon(K2);
  86.                 Console.Write("A komplex számok különbsége: ");
  87.                 K1.KiIr();
  88.  
  89.                 K1.RE = rr1;
  90.                 K1.IM = ii1;
  91.                 K1.KompSzoroz(K2);
  92.                 Console.Write("A komplex számok hányadosa: ");
  93.                 K1.KiIr();
  94.             }
  95.         }
  96.     }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement