C#
Помогите решить задачу на с#
Создать класс для описания цилиндра. Свойства: радиус, высота. Метод: вычисление объема цилиндра. V=пr^2h
Как то так...


using System;
namespace Answer {
class Program {
static void Main() {
Console.Write("Введите радиус цилиндра: ");
var radius = double.Parse(Console.ReadLine());
Console.Write("Введите высоту цилиндра: ");
var height = double.Parse(Console.ReadLine());
var cylinder = new Cylinder(radius, height);
var volume = cylinder.Volume();
Console.WriteLine($"Объём цилиндра: {volume:F3}");
Console.ReadKey();
}
}
class Cylinder {
private readonly double radius;
private readonly double height;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double Volume() {
return Math.PI * Math.Pow(radius, 2) * height;
}
}
}
namespace Answer {
class Program {
static void Main() {
Console.Write("Введите радиус цилиндра: ");
var radius = double.Parse(Console.ReadLine());
Console.Write("Введите высоту цилиндра: ");
var height = double.Parse(Console.ReadLine());
var cylinder = new Cylinder(radius, height);
var volume = cylinder.Volume();
Console.WriteLine($"Объём цилиндра: {volume:F3}");
Console.ReadKey();
}
}
class Cylinder {
private readonly double radius;
private readonly double height;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double Volume() {
return Math.PI * Math.Pow(radius, 2) * height;
}
}
}
using System;
namespace ConsoleApplication1
{
class Cylinder
{
private double h;
private double v;
private double r;
private double s;
public Cylinder(double H, double R)
{
h = H;
r = R;
}
public Cylinder(double V)
{
v = V;
}
public double V()
{
v = Math.PI * r * r * h;
return v;
}
public void S()
{
s = 2 * Math.PI * r * h;
Console.WriteLine("Площадь поверхности цилиндра: {0}",s);
}
public static bool operator ==(Cylinder obj1, Cylinder obj2)
{
if (obj1.v == obj2.v)
return true;
return false;
}
public static bool operator !=(Cylinder obj1, Cylinder obj2)
{
if (obj1.v != obj2.v )
return true;
return false;
}
public static bool operator >(Cylinder obj1, Cylinder obj2)
{
if (obj1.v > obj2.v)
return true;
return false;
}
public static bool operator <(Cylinder obj1, Cylinder obj2)
{
if (obj1.v < obj2.v)
return true;
return false;
}
public override int GetHashCode()
{
return 0;
}
public override bool Equals(object o)
{
return true;
}
}
class Program
{
static void Main()
{
Console.WriteLine("Введите высоту первого цилиндра");
double H = double.Parse(Console.ReadLine());
Console.WriteLine("Введите радиус первого цилиндра");
double R = double.Parse(Console.ReadLine());
Cylinder a = new Cylinder(H,R);
Console.WriteLine("Введите высоту второго цилиндра");
double h = double.Parse(Console.ReadLine());
Console.WriteLine("Введите радиус второго цилиндра");
double r = double.Parse(Console.ReadLine());
Cylinder b = new Cylinder(h,r);
double v = a.V();
double v1 = b.V();
Console.WriteLine("Объем первого цилиндра равен: {0}",v);
a.S();
Console.WriteLine("Объем второго цилиндра равен: {0}", v1);
b.S();
Cylinder z = new Cylinder(v);
Cylinder z1 = new Cylinder(v1);
if (z == z1)
{
Console.WriteLine("Равны");
}
if (z != z1)
{
Console.WriteLine("Не равны");
}
if (z > z1)
{
Console.WriteLine("Объем первого цилиндра больше второго");
}
if (z < z1)
{
Console.WriteLine("Объем второго цилиндра больше первого");
}
Console.ReadKey();
}
}
}
Источник: https://www.google.com/search?q=с#+Создать+класс+для+описания+цилиндра
namespace ConsoleApplication1
{
class Cylinder
{
private double h;
private double v;
private double r;
private double s;
public Cylinder(double H, double R)
{
h = H;
r = R;
}
public Cylinder(double V)
{
v = V;
}
public double V()
{
v = Math.PI * r * r * h;
return v;
}
public void S()
{
s = 2 * Math.PI * r * h;
Console.WriteLine("Площадь поверхности цилиндра: {0}",s);
}
public static bool operator ==(Cylinder obj1, Cylinder obj2)
{
if (obj1.v == obj2.v)
return true;
return false;
}
public static bool operator !=(Cylinder obj1, Cylinder obj2)
{
if (obj1.v != obj2.v )
return true;
return false;
}
public static bool operator >(Cylinder obj1, Cylinder obj2)
{
if (obj1.v > obj2.v)
return true;
return false;
}
public static bool operator <(Cylinder obj1, Cylinder obj2)
{
if (obj1.v < obj2.v)
return true;
return false;
}
public override int GetHashCode()
{
return 0;
}
public override bool Equals(object o)
{
return true;
}
}
class Program
{
static void Main()
{
Console.WriteLine("Введите высоту первого цилиндра");
double H = double.Parse(Console.ReadLine());
Console.WriteLine("Введите радиус первого цилиндра");
double R = double.Parse(Console.ReadLine());
Cylinder a = new Cylinder(H,R);
Console.WriteLine("Введите высоту второго цилиндра");
double h = double.Parse(Console.ReadLine());
Console.WriteLine("Введите радиус второго цилиндра");
double r = double.Parse(Console.ReadLine());
Cylinder b = new Cylinder(h,r);
double v = a.V();
double v1 = b.V();
Console.WriteLine("Объем первого цилиндра равен: {0}",v);
a.S();
Console.WriteLine("Объем второго цилиндра равен: {0}", v1);
b.S();
Cylinder z = new Cylinder(v);
Cylinder z1 = new Cylinder(v1);
if (z == z1)
{
Console.WriteLine("Равны");
}
if (z != z1)
{
Console.WriteLine("Не равны");
}
if (z > z1)
{
Console.WriteLine("Объем первого цилиндра больше второго");
}
if (z < z1)
{
Console.WriteLine("Объем второго цилиндра больше первого");
}
Console.ReadKey();
}
}
}
Источник: https://www.google.com/search?q=с#+Создать+класс+для+описания+цилиндра
Похожие вопросы
- Помогите решить задачу на С#
- Помогите решить задачу C#! С помощью switch case.
- C# Помогите решить задачу! Нужен полный код!
- Помогите решить задачу на c#
- Помогите решить простую задачу на c#
- Решить задачи C#
- С#. Решить задачу по программированию С#.
- Решить задачу через C#
- Помогите написать задачу на C#
- Помогите с задачей по c#