一道C#题目,急求答案!
用c#设计一个圆球的类,具有求体积和面积的方法,并前main创建一个半径为5的实例,输出体积面积...
用c#设计一个圆球的类,具有求体积和面积的方法,并前main创建一个半径为5的实例,输出体积面积
展开
展开全部
public class Ball
{
double _radius;
public Ball(double radius)
{
_radius=radius ;
}
public double GetCover() //面积
{
return 4 * Math.PI * _radius * _radius;
}
public double GetBulk() //体积
{
return 4 * Math.PI * _radius * _radius*_radius / 3;
}
}
static Main() //main 方法
{
Ball ball = new Ball(5);
Console.WriteLine(ball.GetCover().ToString());
}
{
double _radius;
public Ball(double radius)
{
_radius=radius ;
}
public double GetCover() //面积
{
return 4 * Math.PI * _radius * _radius;
}
public double GetBulk() //体积
{
return 4 * Math.PI * _radius * _radius*_radius / 3;
}
}
static Main() //main 方法
{
Ball ball = new Ball(5);
Console.WriteLine(ball.GetCover().ToString());
}
展开全部
class Program
{
static void Main(string[] args)
{
Ball ball = new Ball(5);
Console.WriteLine(ball.getArea());
Console.WriteLine(ball.getVolume());
}
}
public class Ball
{
private double _radius;
public Ball(double R)
{
this._radius = R;
}
public double getArea()
{
return 4.0 * Math.PI * Math.Pow(_radius, 2);
}
public double getVolume()
{
return 4.0 / 3.0 * Math.PI * Math.Pow(_radius, 3);
}
}
{
static void Main(string[] args)
{
Ball ball = new Ball(5);
Console.WriteLine(ball.getArea());
Console.WriteLine(ball.getVolume());
}
}
public class Ball
{
private double _radius;
public Ball(double R)
{
this._radius = R;
}
public double getArea()
{
return 4.0 * Math.PI * Math.Pow(_radius, 2);
}
public double getVolume()
{
return 4.0 / 3.0 * Math.PI * Math.Pow(_radius, 3);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class Ball
{
protected double r;
public double Radius
{
get
{
return r;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
r = value;
}
}
public Ball()
{
this.r = 10;
}
public Ball(double r)
{
this.Radius = r;
}
public double area()
{
return 4 * Math.PI * Radius * Radius;
}
public double volume()
{
return 4 * Math.PI * Radius * Radius * Radius / 3;
}
}
class Program
{
static void Main(string[] args)
{
Ball instance = new Ball(5);
Console.WriteLine("Area:{0}", instance.area());
Console.WriteLine("volume:{0}", instance.volume());
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class Ball
{
protected double r;
public double Radius
{
get
{
return r;
}
set
{
if (value < 0)
throw new Exception("Out of range!");
r = value;
}
}
public Ball()
{
this.r = 10;
}
public Ball(double r)
{
this.Radius = r;
}
public double area()
{
return 4 * Math.PI * Radius * Radius;
}
public double volume()
{
return 4 * Math.PI * Radius * Radius * Radius / 3;
}
}
class Program
{
static void Main(string[] args)
{
Ball instance = new Ball(5);
Console.WriteLine("Area:{0}", instance.area());
Console.WriteLine("volume:{0}", instance.volume());
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询