theme changed

This commit is contained in:
nik
2025-09-30 08:21:09 +03:00
parent 4c261f7def
commit 8bd93df2ae
917 changed files with 15023 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
using System;
public class Operation
{
public static double TriangleArea(double a, double b, double c)
{
double p = (a + b + c) / 2;
bool exists = CheckTriangle(a, b, c);
if (!exists)
return -1;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
public static double TriangleArea(double a)
{
return TriangleArea(a, a, a);
}
public static bool CheckTriangle(double a, double b, double c)
{
if (a <= 0 || b <= 0 || c <= 0) return false;
double maxSide = Math.Max(Math.Max(a, b), Math.Max(b, c));
if (maxSide >= a + b + c - maxSide) return false;
return true;
}
public static int SolveQuadratic(int a, int b, int c, out double x1, out double x2)
{
double d = b * b - 4 * a * c;
if (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
return 1;
}
else if (d == 0)
{
x1 = x2 = -b / (2 * a);
return 0;
}
else
{
x1 = x2 = -1;
return -1;
}
}
}

View File

@@ -0,0 +1,86 @@
using System;
public class Program
{
static void Main(string[] args)
{
int x, y;
Console.WriteLine("Введите первое число: ");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Введите второе число: ");
y = int.Parse(Console.ReadLine());
int greater = Utils.Greater(x, y);
Console.WriteLine("Большим из чисел {0} и {1} является {2} ", x, y, greater);
Console.WriteLine("До swap: \t" + x + " " + y);
Utils.Swap(ref x, ref y);
Console.WriteLine("После swap: \t" + x + " " + y);
int f;
bool ok;
Console.WriteLine("Number for factorial:");
x = int.Parse(Console.ReadLine());
ok = Utils.Factorial(x, out f);
if (ok)
Console.WriteLine("Factorial(" + x + ") = " + f);
else
Console.WriteLine("Cannot compute this factorial");
Console.WriteLine("choose the type of the triangle. type 1 for equilateral else 2: ");
int triangleType = int.Parse(Console.ReadLine());
switch (triangleType)
{
case 1:
Console.WriteLine("input side length: ");
double a = double.Parse(Console.ReadLine());
Console.WriteLine("area = {0}", Operation.TriangleArea(a));
break;
case 2:
Console.WriteLine("input first side length: ");
double sideA = double.Parse(Console.ReadLine());
Console.WriteLine("input second side length: ");
double sideB = double.Parse(Console.ReadLine());
Console.WriteLine("input third side length: ");
double sideC = double.Parse(Console.ReadLine());
Console.WriteLine("area = {0}", Operation.TriangleArea(sideA, sideB, sideC));
break;
default:
Console.WriteLine("invalid triangle type");
break;
}
Console.WriteLine("input coefficient a: ");
int coef_a = int.Parse(Console.ReadLine());
Console.WriteLine("input coefficient b: ");
int coef_b = int.Parse(Console.ReadLine());
Console.WriteLine("input coefficient c: ");
int coef_c = int.Parse(Console.ReadLine());
double x1, x2;
int res = Operation.SolveQuadratic(coef_a, coef_b, coef_c, out x1, out x2);
if (res == 1)
{
Console.WriteLine("Корни уравнения с коэффициентами a = {0}, b = {1}, c = {2} равны x1 = {3}, x2 = {4}.", coef_a, coef_b, coef_c, x1, x2);
}
else if (res == 0)
{
Console.WriteLine("Корень уравнения с коэффициентами a = {0}, b = {1}, c = {2} равны один x1 = x2 = {0}", coef_a, coef_b, coef_c, x1);
}
else
{
Console.WriteLine("Корней уравнения с коэффициентами a = {0}, b = {1}, c = {2} нет.", coef_a, coef_b, coef_c);
}
}
}

44
labs/lab4/Utils/Utils.cs Normal file
View File

@@ -0,0 +1,44 @@
class Utils
{
public static int Greater(int a, int b)
{
if (a > b)
return a;
else
return b;
}
public static void Swap(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
public static bool Factorial(int n, out int answer)
{
int k;
int f = 1;
bool ok = true;
try
{
checked
{
for (k = 2; k <= n; ++k)
{
f = f * k;
}
}
}
catch (Exception)
{
f = 0;
ok = false;
}
answer = f;
return ok;
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

Binary file not shown.

View File

@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"Utils/1.0.0": {
"runtime": {
"Utils.dll": {}
}
}
}
},
"libraries": {
"Utils/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Utils")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3a99124ecb2908fafc9602658ef92948c0982366")]
[assembly: System.Reflection.AssemblyProductAttribute("Utils")]
[assembly: System.Reflection.AssemblyTitleAttribute("Utils")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -0,0 +1 @@
d9a0f86e152d85ac94c64d207d25d9e28a1d26a5f639b47c191b315b50d0343b

View File

@@ -0,0 +1,15 @@
is_global = true
build_property.TargetFramework = net9.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Utils
build_property.ProjectDir = /home/nik/oop/labs/lab4/Utils/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@@ -0,0 +1 @@
6085c8efa71b7fcbc87826f6ffc190d4c6caed39809ad47b380e6cbe090d21f2

View File

@@ -0,0 +1,14 @@
/home/nik/oop/labs/lab4/Utils/bin/Debug/net9.0/Utils
/home/nik/oop/labs/lab4/Utils/bin/Debug/net9.0/Utils.deps.json
/home/nik/oop/labs/lab4/Utils/bin/Debug/net9.0/Utils.runtimeconfig.json
/home/nik/oop/labs/lab4/Utils/bin/Debug/net9.0/Utils.dll
/home/nik/oop/labs/lab4/Utils/bin/Debug/net9.0/Utils.pdb
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.GeneratedMSBuildEditorConfig.editorconfig
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.AssemblyInfoInputs.cache
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.AssemblyInfo.cs
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.csproj.CoreCompileInputs.cache
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.dll
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/refint/Utils.dll
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.pdb
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/Utils.genruntimeconfig.cache
/home/nik/oop/labs/lab4/Utils/obj/Debug/net9.0/ref/Utils.dll

Binary file not shown.

View File

@@ -0,0 +1 @@
f03924812c89729fd31a52bd93ecb6618a58cbe375ba94dee7d99a52e7f3cade

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,73 @@
{
"format": 1,
"restore": {
"/home/nik/oop/labs/lab4/Utils/Utils.csproj": {}
},
"projects": {
"/home/nik/oop/labs/lab4/Utils/Utils.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/nik/oop/labs/lab4/Utils/Utils.csproj",
"projectName": "Utils",
"projectPath": "/home/nik/oop/labs/lab4/Utils/Utils.csproj",
"packagesPath": "/home/nik/.nuget/packages/",
"outputPath": "/home/nik/oop/labs/lab4/Utils/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/nik/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net9.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0": {
"targetAlias": "net9.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.100"
},
"frameworks": {
"net9.0": {
"targetAlias": "net9.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[9.0.9, 9.0.9]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/9.0.110/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/nik/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/nik/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.4</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/nik/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -0,0 +1,78 @@
{
"version": 3,
"targets": {
"net9.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net9.0": []
},
"packageFolders": {
"/home/nik/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/nik/oop/labs/lab4/Utils/Utils.csproj",
"projectName": "Utils",
"projectPath": "/home/nik/oop/labs/lab4/Utils/Utils.csproj",
"packagesPath": "/home/nik/.nuget/packages/",
"outputPath": "/home/nik/oop/labs/lab4/Utils/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/nik/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net9.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0": {
"targetAlias": "net9.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.100"
},
"frameworks": {
"net9.0": {
"targetAlias": "net9.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[9.0.9, 9.0.9]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/9.0.110/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"version": 2,
"dgSpecHash": "322eHXCW/NQ=",
"success": true,
"projectFilePath": "/home/nik/oop/labs/lab4/Utils/Utils.csproj",
"expectedPackageFiles": [
"/home/nik/.nuget/packages/microsoft.aspnetcore.app.ref/9.0.9/microsoft.aspnetcore.app.ref.9.0.9.nupkg.sha512"
],
"logs": []
}

BIN
labs/lab4/assets/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
labs/lab4/assets/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
labs/lab4/assets/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
labs/lab4/assets/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
labs/lab4/assets/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

BIN
labs/lab4/assets/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
labs/lab4/assets/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

BIN
labs/lab4/report.pdf Normal file

Binary file not shown.

373
labs/lab4/report.typ Normal file
View File

@@ -0,0 +1,373 @@
#set text(size: 1.3em)
#show raw.where(block: false): box.with(
fill: luma(240),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
#show raw.where(block: true): block.with(
fill: luma(240),
inset: 10pt,
radius: 4pt,
)
// title
#align(center)[Санкт-Петербургский национальный исследовательский университет информационных технологий, механики и оптики]
\
\
\
#align(center)[Факультет инфокоммуникационных технологий]
#align(center)[Направление подготовки 11.03.02]
\
\
#align(center)[Лабораторная работа №4]
#align(center)[Создание и использование методов]
\
\
\ //#align(center)[Вариант 19]
\
\
\
\
\
\
\
#align(right)[Выполнил:]
#align(right)[Дощенников Никита Андреевич]
#align(right)[Группа: К3221]
#align(right)[Проверил:]
#align(right)[Иванов Сергей Евгеньевич]
\
\
#align(center)[Санкт-Петербург]
#align(center)[2025]
#pagebreak()
=== Цель работы:
Изучить и приобрести навыки работы с методами класса.
=== Упражнение 1. Использование параметров в методах, возвращающих значения.
Я создал класс `Utils` и определил в нем метод `Greater`, который принимает 2 целочисленных параметра и возвращает больший из них.
Тело метода:
```cs
public static int Greater(int a, int b)
{
if (a > b)
return a;
else
return b;
}
```
Тест:
```cs
static void Main(string[] args)
{
int x, y;
Console.WriteLine("Введите первое число: ");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Введите второе число: ");
y = int.Parse(Console.ReadLine());
int greater = Utils.Greater(x, y);
Console.WriteLine("Большим из чисел {0} и {1} является {2} ", x, y, greater);
}
```
Пример:
#align(center)[#image("assets/1.png")]
=== Упражнение 2. Использование в методах параметров, передаваемых по ссылке
Я создал метод `Swap`, который меняет местами значения параметров. При этом использовались параметры, передаваемые по ссылке:
```cs
public static void Swap(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
```
Тест:
```cs
Console.WriteLine("До swap: \t" + x + " " + y);
Utils.Swap(ref x, ref y);
Console.WriteLine("После swap: \t" + x + " " + y);
```
Пример:
#align(center)[#image("assets/2.png")]
=== Упражнение 3. Использование возвращаемых параметров в методах.
В этом упражнении я создал метод `Factorial`, принимающий целочисленную переменную и рассчитывающий ее факториал по итерационному алгоритму.
```cs
public static bool Factorial(int n, out int answer)
{
int k;
int f = 1;
bool ok = true;
try
{
checked
{
for (k = 2; k <= n; ++k)
{
f = f * k;
}
}
}
catch (Exception)
{
f = 0;
ok = false;
}
answer = f;
return ok;
}
```
Тест:
```cs
int f;
bool ok;
Console.WriteLine("Number for factorial:");
x = int.Parse(Console.ReadLine());
ok = Utils.Factorial(x, out f);
if (ok)
Console.WriteLine("Factorial(" + x + ") = " + f);
else
Console.WriteLine("Cannot compute this factorial");
```
Пример:
#align(center)[#image("assets/3.png")]
=== Упражнение 4. Расчет площади треугольника с помощью метода.
В этом упражнении я создал класс `Operation` который умеет считать площадь треугольника, проверять треугольник на существование и считать площадь для равностороннего треугольника.
```cs
using System;
public class Operation
{
public static double TriangleArea(double a, double b, double c)
{
double p = (a + b + c) / 2;
bool exists = CheckTriangle(a, b, c);
if (!exists)
return -1;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
public static double TriangleArea(double a)
{
return TriangleArea(a, a, a);
}
public static bool CheckTriangle(double a, double b, double c)
{
if (a <= 0 || b <= 0 || c <= 0) return false;
double maxSide = Math.Max(Math.Max(a, b), Math.Max(b, c));
if (maxSide >= a + b + c - maxSide) return false;
return true;
}
public static int SolveQuadratic(int a, int b, int c, out double x1, out double x2)
{
double d = b * b - 4 * a * c;
if (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
return 1;
}
else if (d == 0)
{
x1 = x2 = -b / (2 * a);
return 0;
}
else
{
x1 = x2 = -1;
return -1;
}
}
}
```
Тесты:
```cs
Console.WriteLine("choose the type of the triangle. type 1 for equilateral else 2: ");
int triangleType = int.Parse(Console.ReadLine());
switch (triangleType)
{
case 1:
Console.WriteLine("input side length: ");
double a = double.Parse(Console.ReadLine());
Console.WriteLine("area = {0}", Operation.TriangleArea(a));
break;
case 2:
Console.WriteLine("input first side length: ");
double sideA = double.Parse(Console.ReadLine());
Console.WriteLine("input second side length: ");
double sideB = double.Parse(Console.ReadLine());
Console.WriteLine("input third side length: ");
double sideC = double.Parse(Console.ReadLine());
Console.WriteLine("area = {0}", Operation.TriangleArea(sideA, sideB, sideC));
break;
default:
Console.WriteLine("invalid triangle type");
break;
}
```
Пример:
#align(center)[#image("assets/4.png")]
=== Упражнение 5. Вычисление корней квадратного уравнения.
В этом упражнении я реализовал метод вычисления квадратного уравнения.
```cs
public static int SolveQuadratic(int a, int b, int c, out double x1, out double x2)
{
double d = b * b - 4 * a * c;
if (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
return 1;
}
else if (d == 0)
{
x1 = x2 = -b / (2 * a);
return 0;
}
else
{
x1 = x2 = -1;
return -1;
}
}
```
Тесты:
```cs
Console.WriteLine("input coefficient a: ");
int coef_a = int.Parse(Console.ReadLine());
Console.WriteLine("input coefficient b: ");
int coef_b = int.Parse(Console.ReadLine());
Console.WriteLine("input coefficient c: ");
int coef_c = int.Parse(Console.ReadLine());
double x1, x2;
int res = Operation.SolveQuadratic(coef_a, coef_b, coef_c, out x1, out x2);
if (res == 1)
{
Console.WriteLine("Корни уравнения с коэффициентами a = результат, b = результат, c = результат равны x1 = {0}, x2 = {1}.", x1, x2);
}
else if (res == 0)
{
Console.WriteLine("Корень уравнения с коэффициентами a = результат, b = результат, c = результат равны один x1 = x2 = {0}", x1);
}
else
{
Console.WriteLine("Корней уравнения с коэффициентами a = результат, b = результат, c = результат нет.");
}
```
Пример:
#align(center)[#image("assets/5.png")]
#align(center)[#image("assets/6.png")]
#align(center)[#image("assets/7.png")]
=== Вывод.
В ходе проделанной работы, я изучил и приобрел навыки работы с методами класса.
=== Code review. (by #link("https://zzzcode.ai")[zzzcode.ai])
*Резюме*
Данный код реализует несколько математических операций, включая вычисление площади треугольника, решение квадратного уравнения и вычисление факториала. Код написан на C\# и включает в себя классы `Operation`, `Program` и `Utils`. В целом, код выполняет свои функции, но требует улучшений в области обработки ошибок, читаемости и структуры.
*Ошибка*
В методе `TriangleArea` возвращается -1 в случае, если треугольник не существует. Это может вызвать путаницу, так как -1 может быть интерпретировано как валидное значение площади. Рекомендуется использовать исключения для обработки ошибок.
*Стиль кода*
Код в целом следует стандартам C\#, однако есть некоторые моменты, которые можно улучшить:
Использование var для переменных, где тип очевиден.
Избегание магических чисел, таких как -1, для обозначения ошибок.
*Структура кода*
Классы и методы организованы логически, однако стоит рассмотреть возможность разделения функциональности на более мелкие классы или модули для улучшения поддержки и тестирования.
*Читаемость*
Код читаем, но можно улучшить его с помощью:
Добавления комментариев для сложных участков кода.
Использования более описательных имен переменных и методов.
*Производительность*
Код работает эффективно для небольших входных данных. Однако, для больших значений, особенно в методе `Factorial`, стоит рассмотреть использование более эффективных алгоритмов или библиотек.
*Масштабируемость*
Код может быть масштабирован, но для этого потребуется рефакторинг. Например, можно использовать интерфейсы и абстракции для улучшения гибкости.
*Безопасность*
Код не содержит явных уязвимостей, но стоит добавить проверки на вводимые данные, чтобы избежать исключений при некорректном вводе.
*Обработка ошибок*
Обработка ошибок в коде минимальна. Рекомендуется использовать исключения для более четкой обработки ошибок, а также добавлять проверки на вводимые данные.
*Заключение*
Код выполняет свои функции, но требует улучшений в области обработки ошибок, читаемости и структуры. Рекомендуется провести рефакторинг для повышения качества кода и его поддержки в будущем.