Last active
March 7, 2019 21:29
-
-
Save PlugFox/9cce7e63754661321ba2dcb993b42de0 to your computer and use it in GitHub Desktop.
Первый пример Сисярпа для Бори
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace BorisExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Создаю объект | |
TestCalculation test = new TestCalculation(); | |
test.x = 1; | |
test.y = 2; | |
test.PrintMultiply(); | |
test.PrintSumma(); | |
test.PrintDivision(); | |
Console.ReadLine(); // Ожидать ввода пользователя | |
} | |
} | |
class TestCalculation | |
{ | |
#region Блок переменных | |
private Product product = new Product(); | |
private Sum sum = new Sum(); | |
private Difference difference = new Difference(5, 6); | |
public decimal x | |
{ | |
set { product.SetX(value); } | |
//get { return product.GetX(); } | |
} | |
public decimal y | |
{ | |
set { product.SetY(value); } | |
//get { return product.GetY(); } | |
} | |
#endregion | |
// Конструктор | |
public TestCalculation() | |
{ | |
Console.WriteLine("Мы создали новый экземляр класса TestCalculation"); | |
} | |
#region Вывод данных на экран | |
// Вывод на экран перемножения методов объекта product | |
public void PrintMultiply() | |
{ | |
Console.WriteLine("{0} * {1} = {2}", product.GetX(), product.GetY(), product.Multiply()); // Форматная строка | |
} | |
// Вывод на экран суммы | |
public void PrintSumma() | |
{ | |
Console.WriteLine(sum.Summa()); | |
} | |
public void PrintDivision() => difference.PrintDivision(); | |
#endregion | |
} | |
class Product | |
{ | |
#region Переменные | |
private decimal x, y; | |
// Геттер перемножения x и y | |
private decimal z | |
{ | |
get { return x * y; } | |
} | |
#endregion | |
#region Установка и получение переменных через методы | |
public void SetX(decimal val) | |
{ | |
x = val; | |
} | |
public decimal GetX() | |
{ | |
return x; | |
} | |
public void SetY(decimal val) | |
{ | |
y = val; | |
} | |
public decimal GetY() | |
{ | |
return y; | |
} | |
#endregion | |
// Метод получения перемножения х и y | |
public decimal Multiply() | |
{ | |
return z; | |
} | |
} | |
class Sum | |
{ | |
private int a, b; | |
// конструктор | |
public Sum() | |
{ | |
a = 3; | |
b = 4; | |
} | |
public String Summa() | |
{ | |
int AplusB = a + b; | |
return "a=" + a + ", b=" + b + " результат:" + AplusB; // Конкатенация строк | |
} | |
} | |
class Difference | |
{ | |
private double c; | |
private double d; | |
// Конструктор с параметрами | |
public Difference(double C, double D) | |
{ | |
c = C; | |
d = D; | |
} | |
public void PrintDivision() | |
{ | |
Console.WriteLine("c = {0}, d = {1}, result = {2}", c, d, (c/d)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Мы создали новый экземляр класса TestCalculation
1 * 2 = 2
a=3, b=4 результат:7
c = 5, d = 6, result = 0,833333333333333