c#类的定义和实例化
定义一个类cat实现对cat。cat类中成员字段又重量,身高。成员函数voidinput()实现数据输入,函数voidcatch实现获取信息。在主函数中创建cat类,调用...
定义一个类cat实现对cat。cat类中成员字段又重量,身高。成员函数void input()实现数据输入,函数void catch实现获取信息。在主函数中创建cat类,调用input方法输入数据,再用catch方法获取信息
展开
2个回答
展开全部
猫类吗···其实这个也很好写吧····如果没人写我就帮你写吧······
public class Cat
{
private double weight;
private double height;
public void Input()
{
Console.WriteLine("输入体重:");
try
{
weight = double.Parse(Console.ReadLine());
}
catch (FormatException fe)
{
Console.WriteLine(fe.Message);
Input();
return;
}
Console.WriteLine("输入身高:");
try
{
height = double.Parse(Console.ReadLine());
}
catch (FormatException fe)
{
Console.WriteLine(fe.Message);
Input();
return;
}
}
public void Catch()
{
Console.WriteLine("体重为:{0}",weight);
Console.WriteLine("身高为:{0}",height);
}
}
class program
{
static void Main(string[] args)
{
Cat cat = new Cat();
cat.Input();
cat.Catch();
}
}
public class Cat
{
private double weight;
private double height;
public void Input()
{
Console.WriteLine("输入体重:");
try
{
weight = double.Parse(Console.ReadLine());
}
catch (FormatException fe)
{
Console.WriteLine(fe.Message);
Input();
return;
}
Console.WriteLine("输入身高:");
try
{
height = double.Parse(Console.ReadLine());
}
catch (FormatException fe)
{
Console.WriteLine(fe.Message);
Input();
return;
}
}
public void Catch()
{
Console.WriteLine("体重为:{0}",weight);
Console.WriteLine("身高为:{0}",height);
}
}
class program
{
static void Main(string[] args)
{
Cat cat = new Cat();
cat.Input();
cat.Catch();
}
}
展开全部
public class Cat
{
private double stature;
private double weight;
//定义身高属性
public double Stature()
{
get{return stature};
set{stature=value};
}
//定义重量属性
public double Weight()
{
get {return weight};
set {weight =value};
}
}
//数据输入
public void Input()
{}
//数据抓取
public void Catch()
{}
}
public class Test
{
public static void Main()
{
Cat ca =new Cat();
ca.Input();
ca.Catch();
}
}
{
private double stature;
private double weight;
//定义身高属性
public double Stature()
{
get{return stature};
set{stature=value};
}
//定义重量属性
public double Weight()
{
get {return weight};
set {weight =value};
}
}
//数据输入
public void Input()
{}
//数据抓取
public void Catch()
{}
}
public class Test
{
public static void Main()
{
Cat ca =new Cat();
ca.Input();
ca.Catch();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询