关于c#编程问题

[复制链接]
查看11 | 回复1 | 2009-10-16 22:45:00 | 显示全部楼层 |阅读模式
using System;using System.Collections.Generic;using System.Text;//using System.namespace ConsoleApplication29{
class OneTest
{
static void Main(string[] args)
{
Console.WriteLine("请输入圆的半径:");
double r = Convert .ToDouble(Console.ReadLine());
Circle circle = new Circle(r);
Console.WriteLine(circle.Girth());
Console.WriteLine(circle.Area());
Console.WriteLine("请输入长:");
double a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入宽:");
double b = Convert.ToDouble(Console.ReadLine());
Rect rect = new Rect(a, b);
Shape s = new Shape();
Console.WriteLine(rect.Girth());
Console.WriteLine(rect.Area());
}
publicclass Shape
{
publicdouble pi = Math.PI;
public void Girth()
{
}
public void Area()
{
}
}
public class Circle:Shape
{
double area,r,girth;
public Circle(double r)
{
this.r = r;
}
new public double Area()
{
area = pi * r * r;
return area;
}
new public double Girth()
{
girth = 2 * pi * r;
return girth;
}
}
public class Rect : Shape
{
double length ,width,area,girth;
public Rect(double a, double b)
{
this.length = a;
this.width = b;
}
new public double Area()
{
area = length * width;
return area;
}
new public double Girth()
{
girth = 2 * length + 2 * width;
return girth;
}
}
}}
回复

使用道具 举报

千问 | 2009-10-16 22:45:00 | 显示全部楼层
..不就是做几个类..写几个方法..不难啊...自己敲...别人的代码总是别人的...自己敲的才是你自己的..你看是可能看懂了..自己不做过是不行的..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行