程序填空题:
(1)设计一个圆类(Circle),计算周长( perimeter)和计算面积( area)的方法。
(2)设计一个圆柱体类(Cylinder),圆柱体类继承自圆类,能计算圆柱体的表面积(area)和计算体积(volumn)。
(3)创建半径为5的圆对象,显示其面积。创建半径为3,高为7的圆柱体对象,显示其表面积。
(圆柱体的表面积=2 * Math.PI * R * R + 2 * Math.PI *R * heigth)
(圆柱体的体积=Math.PI *R * R * height)
class Circle
{
protected double r;
public double R
{
get { return r; }
set
{
if ( 【1】 )
{
r = value;
}
else
{
throw new Exception("半径不能小于等于0");
}
}
}
public Circle()
{
}
public Circle( 【2】 )
{
R = r;
}
public double Perimeter()
{
return 2 * Math.PI * r;
}
public double Area()
{
return Math.PI * r * r;
}
}
class Cylinder 【3】
{
private double heigth;
public double Heigth
{
get { return heigth; }
set
{
if ( 【4】 )
{
heigth = value;
}
else
{
throw new Exception("高不能小于等于0");
}
}
}
public Cylinder()
{ }
public Cylinder(double r,double height) 【5】
{
【6】 = height;
}
public new double Area()
{
return 2 * 【7】 + 【8】 * heigth; //要求调用父类的方法
}
public double CylinderVolumn()
{
return 【9】 * heigth; //要求调用父类的方法
}
}
class Program
{
static void Main(string[] args)
{
try
{
Circle c1 = new Circle();
【10】 = 5; //设置圆的半径为5
Console.WriteLine("半径为{0}的圆面积是:{1}", 【11】 );
Cylinder c2 = new 12】 ; //创建半径为3,高为7的圆柱体对象
Console.WriteLine("半径为{0}高为{1}的圆柱表面积是:{2}", 【13】 );
}
catch (Exception e)
{
Console.WriteLine( 【14】 );
}
Console.Read();
}
(1)设计一个圆类(Circle),计算周长( perimeter)和计算面积( area)的方法。
(2)设计一个圆柱体类(Cylinder),圆柱体类继承自圆类,能计算圆柱体的表面积(area)和计算体积(volumn)。
(3)创建半径为5的圆对象,显示其面积。创建半径为3,高为7的圆柱体对象,显示其表面积。
(圆柱体的表面积=2 * Math.PI * R * R + 2 * Math.PI *R * heigth)
(圆柱体的体积=Math.PI *R * R * height)
class Circle
{
protected double r;
public double R
{
get { return r; }
set
{
if ( 【1】 )
{
r = value;
}
else
{
throw new Exception("半径不能小于等于0");
}
}
}
public Circle()
{
}
public Circle( 【2】 )
{
R = r;
}
public double Perimeter()
{
return 2 * Math.PI * r;
}
public double Area()
{
return Math.PI * r * r;
}
}
class Cylinder 【3】
{
private double heigth;
public double Heigth
{
get { return heigth; }
set
{
if ( 【4】 )
{
heigth = value;
}
else
{
throw new Exception("高不能小于等于0");
}
}
}
public Cylinder()
{ }
public Cylinder(double r,double height) 【5】
{
【6】 = height;
}
public new double Area()
{
return 2 * 【7】 + 【8】 * heigth; //要求调用父类的方法
}
public double CylinderVolumn()
{
return 【9】 * heigth; //要求调用父类的方法
}
}
class Program
{
static void Main(string[] args)
{
try
{
Circle c1 = new Circle();
【10】 = 5; //设置圆的半径为5
Console.WriteLine("半径为{0}的圆面积是:{1}", 【11】 );
Cylinder c2 = new 12】 ; //创建半径为3,高为7的圆柱体对象
Console.WriteLine("半径为{0}高为{1}的圆柱表面积是:{2}", 【13】 );
}
catch (Exception e)
{
Console.WriteLine( 【14】 );
}
Console.Read();
}