C#源代码—三角形面积、圆的面积
2016-01-14 11:20
471 查看
三角形面积、圆的面积
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _2 { public abstract class shape { private string mc; public shape(string s) { Mc = s; } public string Mc { get { return mc; } set { mc = value; } } public double Area() { return 1; } public abstract double area { get; } public override string ToString() { return Mc + "面积为:" + string.Format("{0:F2}", area); } } public class triangle : shape { private int a,b,c; public triangle(int a,int b,int c, string id) : base(id) { this.a = a; this.b = b; this.c = c; } public double Area() { double p,s; p = (a + b + c) / 2; s = Math.Sqrt(p*(p-a)*(p-b)*(p-c)); return s; } public override double area { get { return Math.Sqrt(((a + b + c) / 2) * (((a + b + c) / 2) - a) * (((a + b + c) / 2) - b) * (((a + b + c) / 2) - c)); } } } public class circles : shape { public double r; public circles(double r, string id) : base(id) { this.r = r; } public double Area() { double s; s = 2 * 3.14 * r; return s; } public override double area { get { return 2 * 3.14 * r; } } } class Program { static void Main(string[] args) { triangle s1 = new triangle(3,4,5,"三角形"); circles c1 = new circles(4,"圆"); string result1, result2; result1 = s1.ToString(); result2 = c1.ToString(); Console.WriteLine("{0}\n{1}",result1,result2); Console.WriteLine("第二种实现方法:"); Console.WriteLine("三角形面积为:{0}\n圆的面积为:{1}", s1.Area(), c1.Area()); } } }
相关文章推荐
- C#源代码—姓名 请输入老师的编号、姓名、职称和部门
- C# string字符串转换为字节数组和转换为16进制的字符串形式
- C# 冒泡排序
- C#邮件发送类 简单实用 可自定义发件人名称
- C# 简单的泛型单例
- C#引用dll库失败
- c#范型List的Sort方法详解
- 输出字符串中最长的单词 C# 算法
- C# Excel写入
- C# WebBrowser控件 模拟登录 抓取数据
- 运用VC#编程通过OPC方式实现PC机与西门子PLC通讯《异步篇》
- 运用VC#编程通过OPC方式实现PC机与西门子PLC通讯《异步篇》
- 用 C# 实现带键值的优先队列
- C# partial 说明
- C#图片验证码,旋转文字主要代码
- 利用C#开发web应用程序时,对注册表进行操作提示没有权限的解决办法
- C# 发送邮件
- C# event线程安全
- 【NCRE】——C#查看PowerPoint属性
- C# Graphics 放大和旋转