Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{

using System;
public class Деталь
{
public string Назва { get; set; }
public string Матеріал { get; set; }
public int Кількість { get; set; }

public string ОтриматиІнформацію()


{
return $"Назва: {Назва}\nМатеріал: {Матеріал}\nКількість: {Кількість}";
}
}

public class Механізм : Деталь


{
public string Тип { get; set; }
public string Виробник { get; set; }

public string Працювати()


{
return $"Механізм {Назва} ({Тип}) від {Виробник} почав роботу.";
}
}

public class Виріб : Деталь


{
public int Гарантія { get; set; }
public double Ціна { get; set; }

public string Купити()


{
return $"Виріб {Назва} успішно куплений. Гарантія: {Гарантія} років.
Ціна: {Ціна}.";
}
}

public class Вузол : Деталь


{
public string Розмір { get; set; }
public double Вага { get; set; }

public string Сполучити()


{
return $"Вузол {Назва} ({Розмір}) успішно з'єднаний. Вага: {Вага}.";
}
}
}

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
using System;

class ComplexNumber
{
// Властивості для частин комплексного числа
public double Real { get; set; }
public double Imaginary { get; set; }

// Конструктор класу
public ComplexNumber(double real, double imaginary)
{
Real = real;
Imaginary = imaginary;
}

// Метод для додавання комплексних чисел


public ComplexNumber Add(ComplexNumber other)
{
double newReal = Real + other.Real;
double newImaginary = Imaginary + other.Imaginary;
return new ComplexNumber(newReal, newImaginary);
}

// Метод для віднімання комплексних чисел


public ComplexNumber Subtract(ComplexNumber other)
{
double newReal = Real - other.Real;
double newImaginary = Imaginary - other.Imaginary;
return new ComplexNumber(newReal, newImaginary);
}

// Метод для множення комплексних чисел


public ComplexNumber Multiply(ComplexNumber other)
{
double newReal = Real * other.Real - Imaginary * other.Imaginary;
double newImaginary = Real * other.Imaginary + Imaginary * other.Real;
return new ComplexNumber(newReal, newImaginary);
}

// Перевизначення методу ToString для зручного виведення комплексного числа


public override string ToString()
{
return $"{Real} + {Imaginary}i";
}
}

class Program
{
static void Main(string[] args)
{
// Створюємо комплексні числа
ComplexNumber a = new ComplexNumber(2, 3);
ComplexNumber b = new ComplexNumber(1, 4);

// Виконуємо операції з комплексними числами


ComplexNumber sum = a.Add(b);
ComplexNumber difference = a.Subtract(b);
ComplexNumber product = a.Multiply(b);

// Виводимо результати
Console.WriteLine($"Сума: {sum}");
Console.WriteLine($"Різниця: {difference}");
Console.WriteLine($"Добуток: {product}");
}
}
}

You might also like