Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace komplexosztaly
- {
- class Komplex
- {
- double re, im;
- public Komplex(double rr, double ii)
- {
- re = rr;
- im = ii;
- }
- public double RE
- {
- get { return re; }
- set { re = value; }
- }
- public double IM
- {
- get { return im; }
- set { im = value; }
- }
- public void KiIr()
- {
- Console.WriteLine("{0} {1} {2}", re, (im < 0 ? '-' : '+'), Math.Abs(im));
- }
- public void KompOsszead(Komplex k1)
- {
- this.re = this.re + k1.re;
- this.im = this.im + k1.im;
- }
- public void KompKivon(Komplex k1)
- {
- this.re = this.re - k1.re;
- this.im = this.im - k1.im;
- }
- public void KompSzoroz(Komplex k1)
- {
- double re = this.re * k1.re - this.im * k1.im;
- double im = this.re * k1.im + this.im * k1.re;
- this.re = re;
- this.im = im;
- }
- public void KompOszt(Komplex k1)
- {
- double d = Math.Pow(k1.re, 2.0) + Math.Pow(k1.im, 2.0);
- double re = (this.re * k1.re + this.im * k1.im) / d;
- double im = (this.im * k1.re - this.re * k1.im) / d;
- this.re = re;
- this.im = im;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- double rr1, ii1, rr2, ii2, rr3 = 0, ii3 = 0;
- Komplex K3 = new Komplex(rr3, ii3);
- while (true)
- {
- Console.Write("Komplex1 - Realis Rész: ");
- rr1 = double.Parse(Console.ReadLine());
- Console.Write("Komplex1 - Imaginaris Rész: ");
- ii1 = double.Parse(Console.ReadLine());
- if (rr1 == 0 && ii1 == 0) break;
- Console.Write("Komplex2 - Realis Rész: ");
- rr2 = double.Parse(Console.ReadLine());
- Console.Write("Komplex2 - Imaginaris Rész: ");
- ii2 = double.Parse(Console.ReadLine());
- Komplex K1 = new Komplex(rr1, ii1);
- Komplex K2 = new Komplex(rr2, ii2);
- Console.Write("Z1= ");
- K1.KiIr();
- Console.Write("Z2= ");
- K2.KiIr();
- K1.KompOsszead(K2);
- Console.Write("A komplex számok összege: ");
- K1.KiIr();
- K1.RE = rr1;
- K1.IM = ii1;
- K1.KompKivon(K2);
- Console.Write("A komplex számok különbsége: ");
- K1.KiIr();
- K1.RE = rr1;
- K1.IM = ii1;
- K1.KompSzoroz(K2);
- Console.Write("A komplex számok hányadosa: ");
- K1.KiIr();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement