обязательно
This commit is contained in:
parent
b314ff775d
commit
9a71276639
@ -23,32 +23,32 @@ namespace ProjectBoat_bae
|
||||
private readonly int _BoatHeight = 60;
|
||||
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool body, bool wing, bool sportLine, int width, int height)
|
||||
additionalColor, bool body,
|
||||
int width, int height)
|
||||
{
|
||||
if (width >= _BoatWidth || height >= _BoatHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
Boat = new ProjectBoat_bae();
|
||||
Boat.Init(speed, weight, bodyColor, additionalColor,
|
||||
body, wing, sportLine);
|
||||
Boat.Init(speed,weight, bodyColor, additionalColor,body );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Установка позиции(запоминаем значение)
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (_pictureWidth <= _BoatWidth || _pictureHeight <= _BoatHeight)
|
||||
if (x < 0 || x + _BoatWidth > _pictureWidth)
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y + _BoatHeight > _pictureHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
// Изменение направления перемещения
|
||||
|
@ -55,12 +55,12 @@ namespace ProjectBoat_bae
|
||||
{
|
||||
Random random = new();
|
||||
_drawningBoat = new Drawing();
|
||||
_drawningBoat.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
_drawningBoat.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningBoat.SetPosition(random.Next(10, 10), random.Next(10, 10), pictureBox1.Width, pictureBox1.Height);
|
||||
//Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
@ -21,33 +21,17 @@ namespace ProjectBoat_bae
|
||||
|
||||
public bool body { get; private set; }
|
||||
|
||||
public bool Wing { get; private set; }
|
||||
|
||||
public bool SportLine { get; private set; }
|
||||
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса
|
||||
/// </summary>
|
||||
/// <param name="speed"
|
||||
/// <param name="weight"
|
||||
/// <param name="bodyColor"
|
||||
/// <param name="additionalColor"
|
||||
/// <param name="bodyKit"
|
||||
/// <param name="wing"
|
||||
/// <param name="sportLine"
|
||||
|
||||
//объект
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool bodyKit)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
body = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
evm_4laba/evm_4laba.sln
Normal file
25
evm_4laba/evm_4laba.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34031.279
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "evm_4laba", "evm_4laba\evm_4laba.csproj", "{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7CFA474E-08C2-459C-AC2B-35D9B2179EA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CDA146C8-F7AF-41AE-A3DD-591AFE057184}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
54
evm_4laba/evm_4laba/Program.cs
Normal file
54
evm_4laba/evm_4laba/Program.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace BinaryCalculator
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Ввод пользователем данных
|
||||
Console.WriteLine("Введите исходную систему счисления (2-16):");
|
||||
int baseNumber = Convert.ToInt32(Console.ReadLine());
|
||||
|
||||
Console.WriteLine("Введите первое число:");
|
||||
string binaryNumber1 = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Введите второе число:");
|
||||
string binaryNumber2 = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Введите операцию (+, -, *, /):");
|
||||
char operation = Convert.ToChar(Console.ReadLine());
|
||||
|
||||
|
||||
// Преобразование чисел в двоичную систему счисления
|
||||
int decimalNumber1 = Convert.ToInt32(binaryNumber1, baseNumber);
|
||||
int decimalNumber2 = Convert.ToInt32(binaryNumber2, baseNumber);
|
||||
|
||||
// Выполнение арифметической операции
|
||||
int result = 0;
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
case '+':
|
||||
result = decimalNumber1 + decimalNumber2;
|
||||
break;
|
||||
case '-':
|
||||
result = decimalNumber1 - decimalNumber2;
|
||||
break;
|
||||
case '*':
|
||||
result = decimalNumber1 * decimalNumber2;
|
||||
break;
|
||||
case '/':
|
||||
result = decimalNumber1 / decimalNumber2;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Неправильно указана операция.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Вывод результата в двоичной системе счисления
|
||||
string binaryResult = Convert.ToString(result, 2);
|
||||
Console.WriteLine("Результат: " + binaryResult);
|
||||
}
|
||||
}
|
||||
}
|
10
evm_4laba/evm_4laba/evm_4laba.csproj
Normal file
10
evm_4laba/evm_4laba/evm_4laba.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
25
evm_laba3/evm_laba3.sln
Normal file
25
evm_laba3/evm_laba3.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34031.279
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "evm_laba3", "evm_laba3\evm_laba3.csproj", "{BE1E2078-C452-4E42-BBBB-3AC3141E9744}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE1E2078-C452-4E42-BBBB-3AC3141E9744}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5A26F9BF-589C-4D50-995E-D6FA981231E6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
296
evm_laba3/evm_laba3/Program.cs
Normal file
296
evm_laba3/evm_laba3/Program.cs
Normal file
@ -0,0 +1,296 @@
|
||||
//using System;
|
||||
|
||||
//namespace NumberConverter
|
||||
//{
|
||||
// class Program
|
||||
// {
|
||||
// static void Main(string[] args)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Console.WriteLine("Введите исходную систему счисления (2-16):");
|
||||
// int sourceBase = int.Parse(Console.ReadLine());
|
||||
|
||||
// Console.WriteLine("Введите конечную систему счисления (2-16):");
|
||||
// int targetBase = int.Parse(Console.ReadLine());
|
||||
|
||||
// Console.WriteLine("Введите число в исходной системе счисления:");
|
||||
// string number = Console.ReadLine();
|
||||
|
||||
// int decimalNumber = ConvertToDecimal(number, sourceBase);
|
||||
|
||||
// string targetNumber = ConvertFromDecimal(decimalNumber, targetBase);
|
||||
|
||||
// Console.WriteLine("Результат: " + targetNumber);
|
||||
|
||||
// //string result = Convert.ToString(decimalNumber, targetBase);
|
||||
|
||||
// //result = result.PadLeft(8, '0'); // дополняем до 8 символов
|
||||
// // //Console.WriteLine("Результат ПК: " + result);
|
||||
// //Console.WriteLine("Результат ПК: " + result);
|
||||
|
||||
// }
|
||||
// catch (FormatException)
|
||||
// {
|
||||
// Console.WriteLine("Ошибка: введенное значение имеет неверный формат.");
|
||||
// }
|
||||
// catch (ArgumentOutOfRangeException)
|
||||
// {
|
||||
// Console.WriteLine("Ошибка: значение системы счисления должно быть от 2 до 16.");
|
||||
// }
|
||||
// }
|
||||
|
||||
// //в 10
|
||||
// static int ConvertToDecimal(string number, int sourceBase) //число в 10
|
||||
// {
|
||||
// bool isNegative = false;
|
||||
// if (number.StartsWith("-"))
|
||||
// {
|
||||
// isNegative = true;
|
||||
// number = number.Substring(1);//извлекает подстроку
|
||||
// }
|
||||
|
||||
// //с конца числа каждая цифра умножается на на степень систем, а потом суммируются значения
|
||||
// int decimalNumber = 0;
|
||||
// int power = 0;
|
||||
// for (int i = number.Length - 1; i >= 0; i--)
|
||||
// {
|
||||
// int digitValue;
|
||||
// if (char.IsDigit(number[i]))
|
||||
// {
|
||||
// digitValue = number[i] - '0';
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitValue = number[i] - 'A' + 10;
|
||||
// }
|
||||
|
||||
// //Math.Pow - в степень
|
||||
// decimalNumber += digitValue * (int)Math.Pow(sourceBase, power);
|
||||
// power++;
|
||||
// }
|
||||
|
||||
// //конвертирует в пк
|
||||
// static string ConvertTwosComplement(int num)
|
||||
// {
|
||||
// string binary = Convert.ToString(num, 2);
|
||||
// char[] binaryArr = binary.PadLeft(8, '0').ToCharArray();
|
||||
// for (int i = 0; i < binaryArr.Length; i++)
|
||||
// {
|
||||
// binaryArr[i] = binaryArr[i] == '0' ? '1' : '0';
|
||||
// }
|
||||
|
||||
// int twosComplement = Convert.ToInt32(new string(binaryArr), 2) + 1;
|
||||
// return Convert.ToString(twosComplement, 2).PadLeft(8, '0');
|
||||
// }
|
||||
|
||||
// return isNegative ? -decimalNumber : decimalNumber;
|
||||
// }
|
||||
|
||||
// //из 10
|
||||
// static string ConvertFromDecimal(int decimalNumber, int targetBase)//10 d lheue.
|
||||
// {
|
||||
// bool isNegative = false;
|
||||
// if (decimalNumber < 0)
|
||||
// {
|
||||
// isNegative = true;
|
||||
// decimalNumber = -decimalNumber;
|
||||
// }
|
||||
|
||||
// //остаток от деления записывается как цифра
|
||||
// string targetNumber = "";
|
||||
// while (decimalNumber != 0)
|
||||
// {
|
||||
// int remainder = decimalNumber % targetBase;
|
||||
// char digit;
|
||||
// if (remainder < 10)
|
||||
// {
|
||||
// digit = (char)(remainder + '0');
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digit = (char)(remainder - 10 + 'A');
|
||||
// }
|
||||
// targetNumber = digit + targetNumber;
|
||||
// decimalNumber /= targetBase;
|
||||
// }
|
||||
|
||||
// if (isNegative)
|
||||
// {
|
||||
// return "-" + targetNumber;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return targetNumber;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//using System;
|
||||
|
||||
//public class NumberConverter
|
||||
//{
|
||||
// public static void Main(string[] args)
|
||||
// {
|
||||
// Console.Write("Введите число: ");
|
||||
// string number = Console.ReadLine();
|
||||
|
||||
// Console.Write("Введите первоначальную систему: (2 - 16): ");
|
||||
// int origBase = Int32.Parse(Console.ReadLine());
|
||||
|
||||
// Console.Write("Введите конечную систему: (2 - 16): ");
|
||||
// int finalBase = Int32.Parse(Console.ReadLine());
|
||||
|
||||
// bool isNegative = number.StartsWith('-');//убирает минус чтобы конвертировать
|
||||
// if (isNegative) number = number.Substring(1);
|
||||
|
||||
// //преоразование в 10
|
||||
// int decimalNum = Convert.ToInt32(number, origBase);
|
||||
|
||||
// if (isNegative && finalBase == 2)
|
||||
// {
|
||||
// Console.WriteLine("С минусом -" + Convert.ToString(decimalNum, finalBase));
|
||||
// Console.WriteLine("ПК: " + ConvertTwosComplement(decimalNum));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// string finalNum = Convert.ToString(decimalNum, finalBase);
|
||||
// if (isNegative) finalNum = "-" + finalNum;
|
||||
// Console.WriteLine($"{finalBase}-число: {finalNum.ToUpper()}");
|
||||
// }
|
||||
// }
|
||||
|
||||
// //конвертирует в пк
|
||||
// private static string ConvertTwosComplement(int num)
|
||||
// {
|
||||
// string binary = Convert.ToString(num, 2);
|
||||
// char[] binaryArr = binary.PadLeft(8, '0').ToCharArray();
|
||||
// for (int i = 0; i < binaryArr.Length; i++)
|
||||
// {
|
||||
// binaryArr[i] = binaryArr[i] == '0' ? '1' : '0';
|
||||
// }
|
||||
|
||||
// int twosComplement = Convert.ToInt32(new string(binaryArr), 2) + 1;
|
||||
// return Convert.ToString(twosComplement, 2).PadLeft(8, '0');
|
||||
// }
|
||||
//}
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace AVM_3_laba
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.Write("Введите исходную систему счисления (2-16): ");
|
||||
int input = Convert.ToInt32(Console.ReadLine());
|
||||
|
||||
if ((input > 16) || (input < 2))
|
||||
{
|
||||
Console.WriteLine("Введите сс от 2 до 16!");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.Write("Введите конечную систему счисления (2-16): ");
|
||||
int output = Convert.ToInt32(Console.ReadLine());
|
||||
|
||||
if ((output > 16) || (output < 2))
|
||||
{
|
||||
Console.WriteLine("Введите сс от 2 до 16!");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.Write("Введите число в исходной системе счисления: ");
|
||||
string number = Console.ReadLine();
|
||||
|
||||
bool minus = false;
|
||||
if (number[0] == '-')
|
||||
{
|
||||
number = number.Substring(1);
|
||||
minus = true;
|
||||
}
|
||||
|
||||
int decimalNumber = ConvertToDecimal(number, input);
|
||||
int result = ConvertToOutput(decimalNumber, output);
|
||||
|
||||
if (minus) { result = -result; };
|
||||
|
||||
Console.WriteLine(result);
|
||||
|
||||
if (minus && output == 2)
|
||||
{
|
||||
Console.WriteLine(directСode(result * -1));
|
||||
}
|
||||
}
|
||||
|
||||
static int ConvertToDecimal(string number, int input)
|
||||
{
|
||||
string numberString = number.ToString();
|
||||
int decimalNumber = 0;
|
||||
int power = 0; // степень числа
|
||||
string digits = "0123456789ABCDEF";
|
||||
|
||||
for (int i = numberString.Length - 1; i >= 0; i--)
|
||||
{
|
||||
char digit = numberString[i]; // берем текущую цифру
|
||||
|
||||
// Проверка на недопустимые символы
|
||||
if (!digits.Contains(digit))
|
||||
{
|
||||
Console.WriteLine("Неверный формат числа!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
int value = digits.IndexOf(digit);
|
||||
|
||||
// Проверка на недопустимую цифру для выбранной системы счисления
|
||||
if (value >= input)
|
||||
{
|
||||
Console.WriteLine("Неверный формат числа!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
decimalNumber += value * (int)Math.Pow(input, power++);
|
||||
}
|
||||
return decimalNumber;
|
||||
}
|
||||
|
||||
static int ConvertToOutput(int number, int output)
|
||||
{
|
||||
string digits = "0123456789ABCDEF";
|
||||
string result = "";
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
int remainder = number % output;
|
||||
result = digits[remainder] + result;
|
||||
number /= output;
|
||||
}
|
||||
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
|
||||
static string directСode(int result)
|
||||
{
|
||||
string resultString = result.ToString();
|
||||
int discharge = 8;
|
||||
int countNumber = resultString.Length;
|
||||
|
||||
while (countNumber >= discharge)
|
||||
{
|
||||
discharge *= 2;
|
||||
}
|
||||
|
||||
int numberOfZeros = discharge - countNumber - 1;
|
||||
|
||||
string finalResultString = "1" + string.Concat(Enumerable.Repeat("0", numberOfZeros)) + resultString;
|
||||
|
||||
return finalResultString;
|
||||
}
|
||||
}
|
||||
}
|
10
evm_laba3/evm_laba3/evm_laba3.csproj
Normal file
10
evm_laba3/evm_laba3/evm_laba3.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user