Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Complex1
- {
- class Program
- {
- static void Main(string[] args)
- {
- double re, im, mod, arg;
- Console.Write("Введите действительную часть комплексного числа re = ");
- re = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите мнимую часть комплексного числа im = ");
- im = Convert.ToDouble(Console.ReadLine());
- Complex z1 = Complex.Complex_FromCartesian(re, im);
- Console.Write("Введите модуль комплексного числа mod = ");
- mod = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите аргумент комплексного числа arg = ");
- arg = Convert.ToDouble(Console.ReadLine());
- Complex z2 = Complex.Complex_FromPolar(mod, arg);
- Console.WriteLine("Первое комплексное число z = {0} + {1}*i", z1.Re, z1.Im);
- Console.WriteLine("Второе комплексное число z = {0} + {1}*i", z2.Re, z2.Im);
- }
- }
- public class Complex
- {
- public Complex() { }
- private Complex(double _re, double _im)
- {
- re = _re;
- im = _im;
- }
- public static Complex Complex_FromCartesian(double _re, double _im)
- {
- return new Complex(_re, _im);
- }
- public static Complex Complex_FromPolar(double _mod, double _arg)
- {
- var _re = _mod * Math.Cos(_arg);
- var _im = _mod * Math.Sin(_arg);
- return new Complex(_re, _im);
- }
- public static Complex operator +(Complex num1, Complex num2)
- {
- return new Complex(num1.re + num2.re, num1.im + num2.im);
- }
- public static Complex operator -(Complex num1, Complex num2)
- {
- return new Complex(num1.re - num2.re, num1.im - num2.im);
- }
- public double Re { get; set; }
- public double Im { get; set; }
- private double re, im;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement