Advertisement
Guest User

ClassWork

a guest
Apr 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp19
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             myComplex c1 = new myComplex(4, 3.3);
  14.             Console.WriteLine("Модуль исходного комплексного числа = " +
  15.             c1.Mod());
  16.             while (c1)
  17.             {
  18.                 Console.Write("c1 => "); display(c1);
  19.                 c1--;
  20.             }
  21.             Console.WriteLine("Модуль полученного числа = " +
  22.             c1.Mod());
  23.             Console.WriteLine("Число принадлежит кругу с радиусом 1.");
  24.             Console.ReadKey();
  25.         }
  26.  
  27.         static void display(myComplex cs)
  28.         {
  29.             Console.WriteLine("real=" + cs.re + ", image=" + cs.im);
  30.         }
  31.        
  32.     }
  33.     class myComplex
  34.     {
  35.         public double re, im;
  36.         public myComplex(double xre, double xim)
  37.         { re = xre; im = xim; }
  38.         public static myComplex operator --(myComplex mc)
  39.         { mc.re--; mc.im--; return mc; }
  40.         public static myComplex operator ++(myComplex mc)
  41.         { mc.re++; mc.im++; return mc; }
  42.  
  43.         public double Mod() { return Math.Abs(re * re + im * im); }
  44.         static public bool operator true(myComplex f)
  45.         {
  46.             if (f.Mod() > 1.0) return true;
  47.             else return false;
  48.         }
  49.         static public bool operator false(myComplex f)
  50.         {
  51.             if (f.Mod() <= 1.0) return true;
  52.             else return false;
  53.         }
  54.  
  55.         public static myComplex operator +(myComplex a, myComplex b)
  56.         {
  57.             return new myComplex(a.re + b.re, a.im + b.im);
  58.         }
  59.         public static myComplex operator -(myComplex a, myComplex b)
  60.         {
  61.             return new myComplex(a.re - b.re, a.im - b.im);
  62.         }
  63.         public static myComplex operator *(myComplex a, myComplex b)
  64.         {
  65.             return new myComplex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re);
  66.         }
  67.         public static myComplex operator /(myComplex a, myComplex b)
  68.         {
  69.             return new myComplex((a.re * b.re + a.im + b.im) / (b.re * b.re + b.im * b.im), (a.im * b.re - a.re * b.im) / (b.re * b.re + b.im * b.im));
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement