Написать программу на с# - Компьютерные вопросы
  • Чаты 4chT.com в телеграмм
    Наши группы в телеграмм

Вопрос Написать программу на с#

Регистрация
1 Окт 2013
Сообщения
77
Репутация
0
Спасибо
0
Монет
0
306134751_b69cdce528c0e582a581d905af7331be_800.png

 
Регистрация
15 Сен 2013
Сообщения
100
Репутация
-3
Спасибо
0
Монет
0
using System;
internal class Program {
private static void Main() {
var b = InputDouble("b: ");
var n = Math.Pow(Math.Pow(2.0 * b + 1.0, 3), 0.2) - 64.0 * b;
if (b < 0 || n < 0) {
Console.WriteLine("Недопустимый аргумент функции Math.Sqrt()");
} else {
var d = Math.Sqrt(5.0 * b) + 3.0 * Math.Sqrt(b) / 2.0;
if (b == 0 || d == 0) {
Console.WriteLine("Попытка деления на ноль");
} else {
var z = Math.Sqrt(n) / d;
Console.WriteLine($"z: {z}");
}
}
Console.ReadKey();
}
private static double InputDouble(string message) {
while (true) {
Console.Write(message);
if (double.TryParse(Console.ReadLine(), out double value)) {
return value;
}
}
}
} using System;
using System.Globalization;

internal class Program {
private static void Main() {
var distance = InputDouble("Введите длину отрезка в метрах: ");
var vershok = distance / MetricUnits.VERSHOK;
var arshin = distance / MetricUnits.ARSHIN;
var fathom = distance / MetricUnits.FATHOM;
var verst = distance / MetricUnits.VERST;
var fmtVershok = string.Format(CultureInfo.InvariantCulture, "{0:0.0}", vershok);
var fmtArshin = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", arshin);
var fmtFathom= string.Format(CultureInfo.InvariantCulture, "{0:0.000}", fathom);
var fmtVerst = string.Format(CultureInfo.InvariantCulture, "{0:0.0000}", verst);
Console.WriteLine("Вершков: " + fmtVershok);
Console.WriteLine("Аршинов: " + fmtArshin);
Console.WriteLine("Саженей: " + fmtFathom);
Console.WriteLine("Вёрст: " + fmtVerst);
Console.ReadKey();
}
private readonly struct MetricUnits {
public static readonly double VERSHOK = 0.04445;
public static readonly double ARSHIN = 16.0 * VERSHOK;
public static readonly double FATHOM = 3.0 * ARSHIN;
public static readonly double VERST = 500.0 * FATHOM;
}
private static double InputDouble(string message) {
while (true) {
Console.Write(message);
if (double.TryParse(Console.ReadLine(), out double value)) {
return value;
}
}
}
}
 
Регистрация
23 Авг 2013
Сообщения
82
Репутация
0
Спасибо
0
Монет
0
Такое себе решение с точки зрения ООП, но сегодня суббота, лень напрягать мозг:

namespace ConsoleApp2
{
class RussianMeasure: IEquatable
{
private string measureName;
private double valueMM;
public string MeasureName { get => measureName; }
public double ValueMM { get => valueMM; }

public RussianMeasure(string _MeasureName, double _ValueMM)
{
this.measureName = _MeasureName;
this.valueMM = _ValueMM;
}

public bool Equals(RussianMeasure? other)
{
return this.measureName == other.measureName;
}
}

class RussianMeasureSystem: List
{
public RussianMeasure this[string _MeasureName] { get
{
return Find(x => x.MeasureName == _MeasureName);
}
}

public RussianMeasureSystem()
{
Add(new RussianMeasure("Vershok", 44.55));
Add(new RussianMeasure("Arshin", this["Vershok"].ValueMM * 16));
Add(new RussianMeasure("Sazhen", this["Arshin"].ValueMM * 3));
Add(new RussianMeasure("Versta", this["Sazhen"].ValueMM * 500));
}

public string GetAsString(double _DistanceMM)
{
string Result = string.Empty;
for (int i= Count - 1; i >= 0; i--)
{
double CurrentMeasure = _DistanceMM / this.ValueMM;
Result += $"{(i == 0 ? CurrentMeasure: Math.Truncate(CurrentMeasure))} {this.MeasureName} ";
_DistanceMM -= this.ValueMM * Math.Truncate(CurrentMeasure);
}
return Result;
}

}

internal class Program
{
static void Main(string[] args)
{
double d = double.Parse(Console.ReadLine());
Console.WriteLine(new RussianMeasureSystem().GetAsString(d * 1000));
}
}
}
 
Сверху Снизу