C# 圆柱体类:计算体积和表面积
下面是 C# 代码:
using System;
class Cylinder
{
double radius;
double height;
public Cylinder(double r, double h)
{
radius = r;
height = h;
}
public double Volume()
{
return Math.PI * radius * radius * height;
}
public double Area()
{
return 2 * Math.PI * radius * height + 2 * Math.PI * radius * radius;
}
}
class Test
{
static void Main(string[] args)
{
Cylinder c = new Cylinder(5.0, 10.0);
Console.WriteLine('Volume: ' + c.Volume());
Console.WriteLine('Area: ' + c.Area());
}
}
原文地址: https://www.cveoy.top/t/topic/nomc 著作权归作者所有。请勿转载和采集!