- 1
vvvvvvv
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
vvvvvvv
Я не пойму, почему же "PHP" всегда в кавычках?
Комментарии (2)0
using System;
namespace GovnoLiEto
{
class SobsnaSamKod
{
public static void Main(string[] args)
{
ComplexNumber x = new ComplexNumber(3, 4);
ComplexNumber y = new ComplexNumber(7, 5);
ComplexNumber z = new ComplexNumber();
z = x + y;
Console.WriteLine("Addition: " + z.real + " + " + z.imaginary + "i");
z = x - y;
Console.WriteLine("Subtraction: " + z.real + " + " + z.imaginary + "i");
z = x * y;
Console.WriteLine("Multiplication: " + z.real + " + " + z.imaginary + "i");
z = x / y;
Console.WriteLine("Division: " + z.real + " + " + z.imaginary + "i");
}
class ComplexNumber
{
public double real, imaginary;
public ComplexNumber(double r = 0, double i = 0)
{
real = r;
imaginary = i;
}
public static ComplexNumber operator+(ComplexNumber a, ComplexNumber b)
{
return new ComplexNumber(a.real + b.real, a.imaginary + b.imaginary);
}
public static ComplexNumber operator-(ComplexNumber a, ComplexNumber b)
{
return new ComplexNumber(a.real - b.real, a.imaginary - b.imaginary);
}
public static ComplexNumber operator*(ComplexNumber a, ComplexNumber b)
{
return new ComplexNumber((a.real * b.real) - (a.imaginary * b.imaginary), (a.real * b.imaginary) + (b.real * a.imaginary));
}
public static ComplexNumber operator/(ComplexNumber a, ComplexNumber b)
{
return new ComplexNumber(((a.real * b.real) + (a.imaginary * b.imaginary)) / (b.real * b.real + b.imaginary * b.imaginary), ((a.imaginary * b.real) - (a.real * b.imaginary)) / (b.real * b.real + b.imaginary * b.imaginary));
}
public static bool operator<(ComplexNumber a, ComplexNumber b)
{
return (a.real < b.real) && (a.imaginary < b.imaginary);
}
public static bool operator>(ComplexNumber a, ComplexNumber b)
{
return (a.real > b.real) && (a.imaginary > b.imaginary);
}
/*public static bool operator!>(ComplexNumber a, ComplexNumber b)
{
return (a.real <= b.real) || (a.imaginary <= b.imaginary);
}
public static bool operator!<(ComplexNumber a, ComplexNumber b)
{
return (a.real >= b.real) || (a.imaginary >= b.imaginary);
}*/
public static bool operator<=(ComplexNumber a, ComplexNumber b)
{
return (a.real <= b.real) && (a.imaginary <= b.imaginary);
}
public static bool operator>=(ComplexNumber a, ComplexNumber b)
{
return (a.real >= b.real) && (a.imaginary >= b.imaginary);
}
/*public static bool operator!>=(ComplexNumber a, ComplexNumber b)
{
return (a.real < b.real) || (a.imaginary < b.imaginary);
}
public static bool operator!<=(ComplexNumber a, ComplexNumber b)
{
return (a.real > b.real) || (a.imaginary > b.imaginary);
}*/
public static ComplexNumber operator++(ComplexNumber a)
{
return new ComplexNumber(a.real + 1, a.imaginary + 1);
}
public static ComplexNumber operator--(ComplexNumber a)
{
return new ComplexNumber(a.real - 1, a.imaginary - 1);
}
}
}
}
Комплексные числа. Говно? Судя по всему, да. Дохуя оверлоадов.
Комментарии (1)0
11-гет
Комментарии (0)
0
10-гет на ксюзе
Ууу
Комментарии (0)0
Личный тест говнокода.xyz.
Переведи на "PHP".
Комментарии (0)