using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AreaDemo
{
class Program
{
const double PI = 3.1415926;
static void Main(string[] args)
{
//求三角形面积例子,另外两个求法类同
Console.WriteLine("请输入三角形的相应数据:");
Console.Write("底边长:");
string bases = Console.ReadLine();
Console.Write("高:");
string height = Console.ReadLine();
Area method = new Area();
double area = method.GetTriangleArea(Convert.ToDouble(bases), Convert.ToDouble(height));
Console.WriteLine("三角形面积为:" + area.ToString());
Console.Read();
}
class Area
{
/// <summary>
/// 求三角形面积
/// </summary>
/// <param name="bases">底边</param>
/// <param name="height">高</param>
/// <returns>面积</returns>
public double GetTriangleArea(double bases, double height)
{
return bases * height / 2;
}
/// <summary>
/// 求正方形面积
/// </summary>
/// <param name="side">边长</param>
/// <returns>面积</returns>
public double GetSquareArea(double side)
{
return side * side;
}
/// <summary>
/// 求圆面积
/// </summary>
/// <param name="radius"></param>
/// <returns></returns>
public double GetCircleArea(double radius)
{
return PI * radius * radius;
}
}
}
}
温馨提示:答案为网友推荐,仅供参考