跪求那位大虾用C#编写一个圆柱形类Column,如果答案满意必定重谢...
发布网友
发布时间:2024-04-10 23:54
我来回答
共2个回答
热心网友
时间:2024-04-11 02:51
主程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class Column
{
protected double r;
protected double h;
public double Radius
{
get
{
return r;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
r = value;
}
}
public double Height
{
get
{
return h;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
h = value;
}
}
public Column()
{
this.r = 10;
this.h = 10;
}
public Column(double r, double h)
{
this.Radius = r;
this.Height = h;
}
public double area()
{
return 2 * Math.PI * Radius * Radius + 2 * Math.PI * Radius * Height;
}
public double volume()
{
return Math.PI * Radius * Radius * Height;
}
}
class Program
{
static void Main(string[] args)
{
Column instance = new Column(10, 20);
Console.WriteLine("Area:{0}", instance.area());
Console.WriteLine("volume:{0}", instance.volume());
}
}
}
热心网友
时间:2024-04-11 02:52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class Column
{
protected double r;
protected double h;
public double Radius
{
get
{
return r;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
r = value;
}
}
public double Height
{
get
{
return h;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
h = value;
}
}
public Column()
{
this.r = 10;
this.h = 10;
}
public Column(double r, double h)
{
this.Radius = r;
this.Height = h;
}
public double area()
{
return 2 * Math.PI * Radius * Radius + 2 * Math.PI * Radius * Height;
}
public double volume()
{
return Math.PI * Radius * Radius * Height;
}
}
class Program
{
static void Main(string[] args)
{
Column instance = new Column(10, 20);
Console.WriteLine("Area:{0}", instance.area());
Console.WriteLine("volume:{0}", instance.volume());
}
}
}