using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
PhysicalObject ph = new PhysicalObject();
Console.WriteLine("请输入物体的质量:");
ph.Weight = double.Parse(Console.ReadLine());
Console.WriteLine("请输入物体的体积:");
ph.Veloum = double.Parse(Console.ReadLine());
ph.ifdrop();
MovingObject mv = new MovingObject();
mv.Weight = ph.Weight;
mv.Veloum = ph.Veloum;
Console.WriteLine("请输入物体的速度:");
mv.Sudu = double.Parse(Console.ReadLine());
mv.get1();
mv.get2();
Console.ReadKey();
}
}
class PhysicalObject
{
private double weight;
private double veloum;
public double Weight
{
get { return weight; }
set { weight = value; }
}
public double Veloum
{
get { return veloum; }
set { veloum = value; }
}
public double midu
{
get { return weight / veloum; }
}
public void ifdrop()
{
if (weight / veloum == 1)
{
Console.WriteLine("此物体会漂浮!");
}
else if (weight / veloum >= 1)
{
Console.WriteLine("此物体会下沉!");
}
else
{
Console.WriteLine("此物体会下沉!");
}
}
}
class MovingObject:PhysicalObject
{
double sudu;
public double Sudu
{
get { return sudu;}
set { sudu=value;}
}
public void get1()
{
Console.WriteLine("此物体的动能为:" + Weight * sudu);
}
public void get2()
{
Console.WriteLine("此物体的动能为:" + Weight * sudu*sudu/2);
}
}
}
c#实验5.3:物体类的扩展
最新推荐文章于 2016-04-22 16:32:55 发布