Advertisement
Heidel

Untitled

Jul 4th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Complex1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double re, im, mod, arg;
  10.            
  11.             Console.Write("Введите действительную часть комплексного числа re = ");
  12.             re = Convert.ToDouble(Console.ReadLine());
  13.             Console.Write("Введите мнимую часть комплексного числа im = ");
  14.             im = Convert.ToDouble(Console.ReadLine());
  15.             Complex z1 = Complex.Complex_FromCartesian(re, im);
  16.  
  17.             Console.Write("Введите модуль комплексного числа mod = ");
  18.             mod = Convert.ToDouble(Console.ReadLine());
  19.             Console.Write("Введите аргумент комплексного числа arg = ");
  20.             arg = Convert.ToDouble(Console.ReadLine());
  21.             Complex z2 = Complex.Complex_FromPolar(mod, arg);
  22.  
  23.             Console.WriteLine("Первое комплексное число z = {0} + {1}*i", z1.Re, z1.Im);
  24.             Console.WriteLine("Второе комплексное число z = {0} + {1}*i", z2.Re, z2.Im);
  25.         }
  26.     }
  27.  
  28.     public class Complex
  29.     {
  30.         public Complex() { }
  31.  
  32.         private Complex(double _re, double _im)
  33.         {
  34.             re = _re;
  35.             im = _im;
  36.         }
  37.  
  38.         public static Complex Complex_FromCartesian(double _re, double _im)
  39.         {
  40.             return new Complex(_re, _im);
  41.         }
  42.  
  43.         public static Complex Complex_FromPolar(double _mod, double _arg)
  44.         {
  45.             var _re = _mod * Math.Cos(_arg);
  46.             var _im = _mod * Math.Sin(_arg);
  47.             return new Complex(_re, _im);
  48.         }
  49.  
  50.         public static Complex operator +(Complex num1, Complex num2)
  51.         {
  52.             return new Complex(num1.re + num2.re, num1.im + num2.im);
  53.         }
  54.  
  55.         public static Complex operator -(Complex num1, Complex num2)
  56.         {
  57.             return new Complex(num1.re - num2.re, num1.im - num2.im);
  58.         }
  59.  
  60.         public double Re { get; set; }
  61.         public double Im { get; set; }
  62.  
  63.         private double re, im;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement